mirror of
https://github.com/Ylianst/MeshAgent
synced 2025-12-15 15:53:55 +00:00
Updated timing logic for remote keyboard input
This commit is contained in:
@@ -4703,6 +4703,57 @@ struct ILibXMLNode *ILibParseXML(char *buffer, size_t offset, size_t length)
|
||||
return RetVal;
|
||||
}
|
||||
|
||||
typedef struct ILibCircularQueue_Record
|
||||
{
|
||||
void *next;
|
||||
char data[];
|
||||
}ILibCircularQueue_Record;
|
||||
ILibQueue ILibCircularQueue_Create(size_t entrySize, size_t totalEntries)
|
||||
{
|
||||
totalEntries++;
|
||||
size_t index;
|
||||
void *ret = ILibMemory_SmartAllocateEx(2 * sizeof(void*), (sizeof(ILibCircularQueue_Record) + entrySize)*totalEntries);
|
||||
((void**)ret)[0] = ((void**)ret)[1] = ILibMemory_Extra(ret);
|
||||
|
||||
char *data = (char*)ILibMemory_Extra(ret);
|
||||
for (index = 0; index < totalEntries; ++index)
|
||||
{
|
||||
((ILibCircularQueue_Record*)data)->next = (index == totalEntries - 1) ? ILibMemory_Extra(ret) : (data + sizeof(ILibCircularQueue_Record) + entrySize);
|
||||
data = ((ILibCircularQueue_Record*)data)->next;
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
void* ILibCircularQueue_EnQueue(ILibQueue circularQueue)
|
||||
{
|
||||
ILibCircularQueue_Record *head = (ILibCircularQueue_Record*)((void**)circularQueue)[0];
|
||||
ILibCircularQueue_Record *tail = (ILibCircularQueue_Record*)((void**)circularQueue)[1];
|
||||
ILibCircularQueue_Record *next = (ILibCircularQueue_Record*)tail->next;
|
||||
|
||||
if (next == head) { return(NULL); } // No Space
|
||||
((void**)circularQueue)[1] = next;
|
||||
return(tail->data);
|
||||
}
|
||||
void* ILibCircularQueue_DeQueue(ILibQueue circularQueue)
|
||||
{
|
||||
ILibCircularQueue_Record *head = (ILibCircularQueue_Record*)((void**)circularQueue)[0];
|
||||
ILibCircularQueue_Record *tail = (ILibCircularQueue_Record*)((void**)circularQueue)[1];
|
||||
if (head == tail) { return(NULL); } // Empty
|
||||
|
||||
((void**)circularQueue)[0] = head->next;
|
||||
return(head->data);
|
||||
}
|
||||
void* ILibCircularQueue_Peek(ILibQueue circularQueue)
|
||||
{
|
||||
ILibCircularQueue_Record *head = (ILibCircularQueue_Record*)((void**)circularQueue)[0];
|
||||
ILibCircularQueue_Record *tail = (ILibCircularQueue_Record*)((void**)circularQueue)[1];
|
||||
if (head == tail) { return(NULL); } // Empty
|
||||
return(head->data);
|
||||
}
|
||||
int ILibCircularQueue_IsEmpty(ILibQueue circularQueue)
|
||||
{
|
||||
return(((void**)circularQueue)[0] == ((void**)circularQueue)[1]);
|
||||
}
|
||||
|
||||
/*! \fn ILibQueue_Create()
|
||||
\brief Create an empty Queue
|
||||
\return An empty queue
|
||||
|
||||
@@ -515,6 +515,7 @@ int ILibIsRunningOnChainThread(void* chain);
|
||||
time_t ILibTime_Parse(char *timeString);
|
||||
char* ILibTime_Serialize(time_t timeVal);
|
||||
long long ILibGetUptime();
|
||||
#define ILibTime_timespec_subtract(bigger, smaller) ((uint64_t)(((bigger)->tv_sec - (smaller)->tv_sec) * 1000000000) + (uint64_t)((bigger)->tv_nsec - (smaller)->tv_nsec))
|
||||
|
||||
uint64_t ILibHTONLL(uint64_t v);
|
||||
uint64_t ILibNTOHLL(uint64_t v);
|
||||
@@ -904,6 +905,13 @@ int ILibIsRunningOnChainThread(void* chain);
|
||||
\{
|
||||
*/
|
||||
typedef void* ILibQueue;
|
||||
ILibQueue ILibCircularQueue_Create(size_t entrySize, size_t totalEntries);
|
||||
void* ILibCircularQueue_EnQueue(ILibQueue circularQueue);
|
||||
void* ILibCircularQueue_DeQueue(ILibQueue circularQueue);
|
||||
void* ILibCircularQueue_Peek(ILibQueue circularQueue);
|
||||
int ILibCircularQueue_IsEmpty(ILibQueue circularQueue);
|
||||
#define ILibCircularQueue_Destroy(circularQueue) ILibMemory_Free(circularQueue)
|
||||
|
||||
ILibQueue ILibQueue_Create();
|
||||
void ILibQueue_Destroy(ILibQueue q);
|
||||
int ILibQueue_IsEmpty(ILibQueue q);
|
||||
|
||||
Reference in New Issue
Block a user