mirror of
https://github.com/morgan9e/FreeRDP
synced 2026-04-15 00:44:19 +09:00
libwinpr-utils: implement asynchronous mode for ListDictionary
This commit is contained in:
@@ -134,6 +134,14 @@ enum SURFCMD_FRAMEACTION
|
||||
SURFACECMD_FRAMEACTION_END = 0x0001
|
||||
};
|
||||
|
||||
struct _SURFACE_FRAME
|
||||
{
|
||||
UINT32 frameId;
|
||||
UINT32 commandCount;
|
||||
SURFACE_BITS_COMMAND* commands;
|
||||
};
|
||||
typedef struct _SURFACE_FRAME SURFACE_FRAME;
|
||||
|
||||
/* defined inside libfreerdp-core */
|
||||
typedef struct rdp_update_proxy rdpUpdateProxy;
|
||||
|
||||
|
||||
@@ -43,17 +43,23 @@ int ListDictionary_Count(wListDictionary* listDictionary)
|
||||
int count = 0;
|
||||
wListDictionaryItem* item;
|
||||
|
||||
if (!listDictionary->head)
|
||||
return 0;
|
||||
if (listDictionary->synchronized)
|
||||
EnterCriticalSection(&listDictionary->lock);
|
||||
|
||||
item = listDictionary->head;
|
||||
|
||||
while (item)
|
||||
if (listDictionary->head)
|
||||
{
|
||||
count++;
|
||||
item = item->next;
|
||||
item = listDictionary->head;
|
||||
|
||||
while (item)
|
||||
{
|
||||
count++;
|
||||
item = item->next;
|
||||
}
|
||||
}
|
||||
|
||||
if (listDictionary->synchronized)
|
||||
LeaveCriticalSection(&listDictionary->lock);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
@@ -97,6 +103,9 @@ void ListDictionary_Add(wListDictionary* listDictionary, void* key, void* value)
|
||||
wListDictionaryItem* item;
|
||||
wListDictionaryItem* lastItem;
|
||||
|
||||
if (listDictionary->synchronized)
|
||||
EnterCriticalSection(&listDictionary->lock);
|
||||
|
||||
item = (wListDictionaryItem*) malloc(sizeof(wListDictionaryItem));
|
||||
|
||||
item->key = key;
|
||||
@@ -107,15 +116,19 @@ void ListDictionary_Add(wListDictionary* listDictionary, void* key, void* value)
|
||||
if (!listDictionary->head)
|
||||
{
|
||||
listDictionary->head = item;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
lastItem = listDictionary->head;
|
||||
|
||||
while (lastItem->next)
|
||||
lastItem = lastItem->next;
|
||||
|
||||
lastItem->next = item;
|
||||
}
|
||||
|
||||
lastItem = listDictionary->head;
|
||||
|
||||
while (lastItem->next)
|
||||
lastItem = lastItem->next;
|
||||
|
||||
lastItem->next = item;
|
||||
if (listDictionary->synchronized)
|
||||
LeaveCriticalSection(&listDictionary->lock);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -127,19 +140,25 @@ void ListDictionary_Clear(wListDictionary* listDictionary)
|
||||
wListDictionaryItem* item;
|
||||
wListDictionaryItem* nextItem;
|
||||
|
||||
if (!listDictionary->head)
|
||||
return;
|
||||
if (listDictionary->synchronized)
|
||||
EnterCriticalSection(&listDictionary->lock);
|
||||
|
||||
item = listDictionary->head;
|
||||
|
||||
while (item)
|
||||
if (listDictionary->head)
|
||||
{
|
||||
nextItem = item->next;
|
||||
free(item);
|
||||
item = nextItem;
|
||||
item = listDictionary->head;
|
||||
|
||||
while (item)
|
||||
{
|
||||
nextItem = item->next;
|
||||
free(item);
|
||||
item = nextItem;
|
||||
}
|
||||
|
||||
listDictionary->head = NULL;
|
||||
}
|
||||
|
||||
listDictionary->head = NULL;
|
||||
if (listDictionary->synchronized)
|
||||
LeaveCriticalSection(&listDictionary->lock);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -148,22 +167,31 @@ void ListDictionary_Clear(wListDictionary* listDictionary)
|
||||
|
||||
BOOL ListDictionary_Contains(wListDictionary* listDictionary, void* key)
|
||||
{
|
||||
BOOL status = FALSE;
|
||||
wListDictionaryItem* item;
|
||||
|
||||
if (!listDictionary->head)
|
||||
return FALSE;
|
||||
if (listDictionary->synchronized)
|
||||
EnterCriticalSection(&listDictionary->lock);
|
||||
|
||||
item = listDictionary->head;
|
||||
|
||||
while (item)
|
||||
if (listDictionary->head)
|
||||
{
|
||||
if (item->key == key)
|
||||
break;
|
||||
item = listDictionary->head;
|
||||
|
||||
item = item->next;
|
||||
while (item)
|
||||
{
|
||||
if (item->key == key)
|
||||
break;
|
||||
|
||||
item = item->next;
|
||||
}
|
||||
|
||||
status = (item) ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
return (item) ? TRUE : FALSE;
|
||||
if (listDictionary->synchronized)
|
||||
LeaveCriticalSection(&listDictionary->lock);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -175,35 +203,42 @@ void ListDictionary_Remove(wListDictionary* listDictionary, void* key)
|
||||
wListDictionaryItem* item;
|
||||
wListDictionaryItem* prevItem;
|
||||
|
||||
if (!listDictionary->head)
|
||||
return;
|
||||
if (listDictionary->synchronized)
|
||||
EnterCriticalSection(&listDictionary->lock);
|
||||
|
||||
item = listDictionary->head;
|
||||
|
||||
if (listDictionary->head->key == key)
|
||||
if (listDictionary->head)
|
||||
{
|
||||
listDictionary->head = listDictionary->head->next;
|
||||
free(item);
|
||||
return;
|
||||
}
|
||||
item = listDictionary->head;
|
||||
|
||||
if (!item->next)
|
||||
return;
|
||||
|
||||
prevItem = item;
|
||||
item = item->next;
|
||||
|
||||
while (item)
|
||||
{
|
||||
if (item->key == key)
|
||||
if (listDictionary->head->key == key)
|
||||
{
|
||||
prevItem->next = item->next;
|
||||
listDictionary->head = listDictionary->head->next;
|
||||
free(item);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (item->next)
|
||||
{
|
||||
prevItem = item;
|
||||
item = item->next;
|
||||
|
||||
item = item->next;
|
||||
while (item)
|
||||
{
|
||||
if (item->key == key)
|
||||
{
|
||||
prevItem->next = item->next;
|
||||
free(item);
|
||||
break;
|
||||
}
|
||||
|
||||
item = item->next;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (listDictionary->synchronized)
|
||||
LeaveCriticalSection(&listDictionary->lock);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -212,22 +247,31 @@ void ListDictionary_Remove(wListDictionary* listDictionary, void* key)
|
||||
|
||||
void* ListDictionary_GetItemValue(wListDictionary* listDictionary, void* key)
|
||||
{
|
||||
void* value = NULL;
|
||||
wListDictionaryItem* item;
|
||||
|
||||
if (!listDictionary->head)
|
||||
return NULL;
|
||||
if (listDictionary->synchronized)
|
||||
EnterCriticalSection(&listDictionary->lock);
|
||||
|
||||
item = listDictionary->head;
|
||||
|
||||
while (item)
|
||||
if (listDictionary->head)
|
||||
{
|
||||
if (item->key == key)
|
||||
break;
|
||||
item = listDictionary->head;
|
||||
|
||||
item = item->next;
|
||||
while (item)
|
||||
{
|
||||
if (item->key == key)
|
||||
break;
|
||||
|
||||
item = item->next;
|
||||
}
|
||||
}
|
||||
|
||||
return (item) ? item->value : NULL;
|
||||
value = (item) ? item->value : NULL;
|
||||
|
||||
if (listDictionary->synchronized)
|
||||
LeaveCriticalSection(&listDictionary->lock);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -236,25 +280,34 @@ void* ListDictionary_GetItemValue(wListDictionary* listDictionary, void* key)
|
||||
|
||||
BOOL ListDictionary_SetItemValue(wListDictionary* listDictionary, void* key, void* value)
|
||||
{
|
||||
BOOL status = FALSE;
|
||||
wListDictionaryItem* item;
|
||||
|
||||
if (!listDictionary->head)
|
||||
return FALSE;
|
||||
if (listDictionary->synchronized)
|
||||
EnterCriticalSection(&listDictionary->lock);
|
||||
|
||||
item = listDictionary->head;
|
||||
|
||||
while (item)
|
||||
if (listDictionary->head)
|
||||
{
|
||||
if (item->key == key)
|
||||
break;
|
||||
item = listDictionary->head;
|
||||
|
||||
item = item->next;
|
||||
while (item)
|
||||
{
|
||||
if (item->key == key)
|
||||
break;
|
||||
|
||||
item = item->next;
|
||||
}
|
||||
|
||||
if (item)
|
||||
item->value = value;
|
||||
|
||||
status = (item) ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
if (item)
|
||||
item->value = value;
|
||||
if (listDictionary->synchronized)
|
||||
LeaveCriticalSection(&listDictionary->lock);
|
||||
|
||||
return (item) ? TRUE : FALSE;
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -272,6 +325,8 @@ wListDictionary* ListDictionary_New(BOOL synchronized)
|
||||
listDictionary->synchronized = synchronized;
|
||||
|
||||
listDictionary->head = NULL;
|
||||
|
||||
InitializeCriticalSectionAndSpinCount(&listDictionary->lock, 4000);
|
||||
}
|
||||
|
||||
return listDictionary;
|
||||
@@ -282,6 +337,7 @@ void ListDictionary_Free(wListDictionary* listDictionary)
|
||||
if (listDictionary)
|
||||
{
|
||||
ListDictionary_Clear(listDictionary);
|
||||
DeleteCriticalSection(&listDictionary->lock);
|
||||
free(listDictionary);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ int TestListDictionary(int argc, char* argv[])
|
||||
char* value;
|
||||
wListDictionary* list;
|
||||
|
||||
list = ListDictionary_New(FALSE);
|
||||
list = ListDictionary_New(TRUE);
|
||||
|
||||
ListDictionary_Add(list, key1, val1);
|
||||
ListDictionary_Add(list, key2, val2);
|
||||
|
||||
Reference in New Issue
Block a user