libfreerdp-core: change interlocked singly-linked list to synchronized Queue
This commit is contained in:
parent
a3080bcd3a
commit
875c556d13
@ -1298,6 +1298,20 @@ int freerdp_client_parse_command_line_arguments(int argc, char** argv, rdpSettin
|
||||
if (settings->DisableThemes)
|
||||
settings->PerformanceFlags |= PERF_DISABLE_THEMING;
|
||||
|
||||
arg = CommandLineFindArgumentA(args, "p");
|
||||
|
||||
if (arg->Flags & COMMAND_LINE_ARGUMENT_PRESENT)
|
||||
{
|
||||
FillMemory(arg->Value, strlen(arg->Value), '*');
|
||||
}
|
||||
|
||||
arg = CommandLineFindArgumentA(args, "gp");
|
||||
|
||||
if (arg->Flags & COMMAND_LINE_ARGUMENT_PRESENT)
|
||||
{
|
||||
FillMemory(arg->Value, strlen(arg->Value), '*');
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -718,13 +718,10 @@ rdpRpc* rpc_new(rdpTransport* transport)
|
||||
rpc->max_xmit_frag = 0x0FF8;
|
||||
rpc->max_recv_frag = 0x0FF8;
|
||||
|
||||
rpc->pdu = (RPC_PDU*) _aligned_malloc(sizeof(RPC_PDU), MEMORY_ALLOCATION_ALIGNMENT);
|
||||
rpc->pdu = (RPC_PDU*) malloc(sizeof(RPC_PDU));
|
||||
|
||||
rpc->SendQueue = (PSLIST_HEADER) _aligned_malloc(sizeof(SLIST_HEADER), MEMORY_ALLOCATION_ALIGNMENT);
|
||||
InitializeSListHead(rpc->SendQueue);
|
||||
|
||||
rpc->ReceiveQueue = (PSLIST_HEADER) _aligned_malloc(sizeof(SLIST_HEADER), MEMORY_ALLOCATION_ALIGNMENT);
|
||||
InitializeSListHead(rpc->ReceiveQueue);
|
||||
rpc->SendQueue = Queue_New(TRUE, -1, -1);
|
||||
rpc->ReceiveQueue = Queue_New(TRUE, -1, -1);
|
||||
|
||||
rpc->ReceiveWindow = 0x00010000;
|
||||
|
||||
@ -753,20 +750,16 @@ void rpc_free(rdpRpc* rpc)
|
||||
{
|
||||
if (rpc != NULL)
|
||||
{
|
||||
RPC_PDU* PduEntry;
|
||||
|
||||
ntlm_http_free(rpc->NtlmHttpIn);
|
||||
ntlm_http_free(rpc->NtlmHttpOut);
|
||||
|
||||
_aligned_free(rpc->pdu);
|
||||
free(rpc->pdu);
|
||||
|
||||
while ((PduEntry = (RPC_PDU*) InterlockedPopEntrySList(rpc->SendQueue)) != NULL)
|
||||
_aligned_free(PduEntry);
|
||||
_aligned_free(rpc->SendQueue);
|
||||
Queue_Clear(rpc->SendQueue);
|
||||
Queue_Free(rpc->SendQueue);
|
||||
|
||||
while ((PduEntry = (RPC_PDU*) InterlockedPopEntrySList(rpc->ReceiveQueue)) != NULL)
|
||||
_aligned_free(PduEntry);
|
||||
_aligned_free(rpc->ReceiveQueue);
|
||||
Queue_Clear(rpc->ReceiveQueue);
|
||||
Queue_Free(rpc->ReceiveQueue);
|
||||
|
||||
rpc_client_virtual_connection_free(rpc->VirtualConnection);
|
||||
rpc_virtual_connection_cookie_table_free(rpc->VirtualConnectionCookieTable);
|
||||
|
@ -23,6 +23,7 @@
|
||||
#define FREERDP_CORE_RPC_H
|
||||
|
||||
#include <winpr/wtypes.h>
|
||||
#include <winpr/collections.h>
|
||||
#include <winpr/interlocked.h>
|
||||
|
||||
typedef struct rdp_rpc rdpRpc;
|
||||
@ -763,8 +764,8 @@ struct rdp_rpc
|
||||
UINT16 max_xmit_frag;
|
||||
UINT16 max_recv_frag;
|
||||
|
||||
PSLIST_HEADER SendQueue;
|
||||
PSLIST_HEADER ReceiveQueue;
|
||||
wQueue* SendQueue;
|
||||
wQueue* ReceiveQueue;
|
||||
|
||||
UINT32 ReceiveWindow;
|
||||
|
||||
|
@ -35,11 +35,11 @@ int rpc_send_enqueue_pdu(rdpRpc* rpc, BYTE* buffer, UINT32 length)
|
||||
{
|
||||
RPC_PDU* pdu;
|
||||
|
||||
pdu = (RPC_PDU*) _aligned_malloc(sizeof(RPC_PDU), MEMORY_ALLOCATION_ALIGNMENT);
|
||||
pdu = (RPC_PDU*) malloc(sizeof(RPC_PDU));
|
||||
pdu->Buffer = buffer;
|
||||
pdu->Length = length;
|
||||
|
||||
InterlockedPushEntrySList(rpc->SendQueue, &(pdu->ItemEntry));
|
||||
Queue_Enqueue(rpc->SendQueue, pdu);
|
||||
ReleaseSemaphore(rpc->client->SendSemaphore, 1, NULL);
|
||||
|
||||
if (rpc->client->SynchronousSend)
|
||||
@ -56,7 +56,7 @@ int rpc_send_dequeue_pdu(rdpRpc* rpc)
|
||||
int status;
|
||||
RPC_PDU* pdu;
|
||||
|
||||
pdu = (RPC_PDU*) InterlockedPopEntrySList(rpc->SendQueue);
|
||||
pdu = (RPC_PDU*) Queue_Dequeue(rpc->SendQueue);
|
||||
|
||||
if (!pdu)
|
||||
return 0;
|
||||
@ -77,7 +77,7 @@ int rpc_send_dequeue_pdu(rdpRpc* rpc)
|
||||
rpc->VirtualConnection->DefaultInChannel->SenderAvailableWindow -= status;
|
||||
|
||||
free(pdu->Buffer);
|
||||
_aligned_free(pdu);
|
||||
free(pdu);
|
||||
|
||||
if (rpc->client->SynchronousSend)
|
||||
SetEvent(rpc->client->PduSentEvent);
|
||||
@ -97,7 +97,7 @@ int rpc_recv_enqueue_pdu(rdpRpc* rpc)
|
||||
return -1;
|
||||
}
|
||||
|
||||
rpc->pdu = (RPC_PDU*) _aligned_malloc(sizeof(RPC_PDU), MEMORY_ALLOCATION_ALIGNMENT);
|
||||
rpc->pdu = (RPC_PDU*) malloc(sizeof(RPC_PDU));
|
||||
|
||||
if (pdu->Flags & RPC_PDU_FLAG_STUB)
|
||||
{
|
||||
@ -110,7 +110,7 @@ int rpc_recv_enqueue_pdu(rdpRpc* rpc)
|
||||
rpc->FragBuffer = (BYTE*) malloc(rpc->FragBufferSize);
|
||||
}
|
||||
|
||||
InterlockedPushEntrySList(rpc->ReceiveQueue, &(pdu->ItemEntry));
|
||||
Queue_Enqueue(rpc->ReceiveQueue, pdu);
|
||||
ReleaseSemaphore(rpc->client->ReceiveSemaphore, 1, NULL);
|
||||
|
||||
return 0;
|
||||
@ -129,7 +129,7 @@ RPC_PDU* rpc_recv_dequeue_pdu(rdpRpc* rpc)
|
||||
|
||||
if (WaitForSingleObject(rpc->client->ReceiveSemaphore, dwMilliseconds) == WAIT_OBJECT_0)
|
||||
{
|
||||
pdu = (RPC_PDU*) InterlockedPopEntrySList(rpc->ReceiveQueue);
|
||||
pdu = (RPC_PDU*) Queue_Dequeue(rpc->ReceiveQueue);
|
||||
return pdu;
|
||||
}
|
||||
|
||||
|
@ -47,6 +47,7 @@ typedef struct _wQueue wQueue;
|
||||
|
||||
WINPR_API int Queue_Count(wQueue* queue);
|
||||
WINPR_API BOOL Queue_IsSynchronized(wQueue* queue);
|
||||
WINPR_API HANDLE Queue_SyncRoot(wQueue* queue);
|
||||
|
||||
WINPR_API void Queue_Clear(wQueue* queue);
|
||||
WINPR_API BOOL Queue_Contains(wQueue* queue, void* obj);
|
||||
|
@ -52,6 +52,15 @@ BOOL Queue_IsSynchronized(wQueue* queue)
|
||||
return queue->synchronized;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an object that can be used to synchronize access to the Queue.
|
||||
*/
|
||||
|
||||
HANDLE Queue_SyncRoot(wQueue* queue)
|
||||
{
|
||||
return queue->mutex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Methods
|
||||
*/
|
||||
@ -144,7 +153,7 @@ void* Queue_Dequeue(wQueue* queue)
|
||||
{
|
||||
obj = queue->array[queue->head];
|
||||
queue->array[queue->head] = NULL;
|
||||
queue->head = (queue->head + 1) % queue->size;
|
||||
queue->head = (queue->head + 1) % queue->capacity;
|
||||
queue->size--;
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@ set(MODULE_PREFIX "TEST_WINPR_UTILS")
|
||||
set(${MODULE_PREFIX}_DRIVER ${MODULE_NAME}.c)
|
||||
|
||||
set(${MODULE_PREFIX}_TESTS
|
||||
TestQueue.c
|
||||
TestCmdLine.c)
|
||||
|
||||
create_test_sourcelist(${MODULE_PREFIX}_SRCS
|
||||
|
36
winpr/libwinpr/utils/test/TestQueue.c
Normal file
36
winpr/libwinpr/utils/test/TestQueue.c
Normal file
@ -0,0 +1,36 @@
|
||||
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/tchar.h>
|
||||
#include <winpr/collections.h>
|
||||
|
||||
int TestQueue(int argc, char* argv[])
|
||||
{
|
||||
int item;
|
||||
int index;
|
||||
int count;
|
||||
wQueue* queue;
|
||||
|
||||
queue = Queue_New(TRUE, -1, -1);
|
||||
|
||||
for (index = 1; index <= 10; index++)
|
||||
{
|
||||
Queue_Enqueue(queue, (void*) (size_t) index);
|
||||
}
|
||||
|
||||
count = Queue_Count(queue);
|
||||
|
||||
printf("queue count: %d\n", count);
|
||||
|
||||
for (index = 1; index <= 10; index++)
|
||||
{
|
||||
item = (int) (size_t) Queue_Dequeue(queue);
|
||||
|
||||
if (item != index)
|
||||
return -1;
|
||||
}
|
||||
|
||||
Queue_Clear(queue);
|
||||
Queue_Free(queue);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user