diff --git a/meshcore/KVM/Windows/input.c b/meshcore/KVM/Windows/input.c index 9579c3b..a73e966 100644 --- a/meshcore/KVM/Windows/input.c +++ b/meshcore/KVM/Windows/input.c @@ -239,7 +239,8 @@ void KVM_StopMessagePump() if (CUR_HWND != NULL) { PostMessageA(CUR_HWND, WM_QUIT, 0, 0); - WaitForSingleObject(CUR_WORKTHREAD, 5000); + if (WaitForSingleObject(CUR_WORKTHREAD, 5000) == 0) { CloseHandle(CUR_WORKTHREAD); CUR_WORKTHREAD = NULL; } + if (CUR_APCTHREAD != NULL) { CloseHandle(CUR_APCTHREAD); CUR_APCTHREAD = NULL; } } } diff --git a/meshcore/KVM/Windows/kvm.c b/meshcore/KVM/Windows/kvm.c index b1c3ed3..f707a95 100644 --- a/meshcore/KVM/Windows/kvm.c +++ b/meshcore/KVM/Windows/kvm.c @@ -559,23 +559,7 @@ typedef struct kvm_data_handler char buffer[]; }kvm_data_handler; -//void __stdcall kvm_relay_feeddata_ex_APC(ULONG_PTR data) -//{ -// kvm_data_handler *k = (kvm_data_handler*)data; -// -// k->handler(k->buffer, k->len, k->reserved); -// free((void*)data); -//} -//ILibTransport_DoneState kvm_relay_feeddata_ex(char *buf, int len, void *reserved) -//{ -// kvm_data_handler *data = (kvm_data_handler*)ILibMemory_Allocate(sizeof(kvm_data_handler) + len, 0, NULL, NULL); -// data->handler = (ILibKVM_WriteHandler)((void**)reserved)[0]; -// data->reserved = ((void**)reserved)[1]; -// data->len = len; -// memcpy_s(data->buffer, len, buf, len); -// -// QueueUserAPC((PAPCFUNC)kvm_relay_feeddata_ex_APC, kvmthread, (ULONG_PTR)data); -//} + // Feed network data into the KVM. Return the number of bytes consumed. // This method consumes as many input commands as it can. @@ -798,6 +782,7 @@ DWORD WINAPI kvm_server_mainloop_ex(LPVOID parm) { g_shutdown = 0; kvmthread = CreateThread(NULL, 0, kvm_mainloopinput, parm, 0, 0); + CloseHandle(kvmthread); } #endif @@ -979,7 +964,6 @@ DWORD WINAPI kvm_server_mainloop_ex(LPVOID parm) KVMDEBUG("kvm_server_mainloop / end3", (int)GetCurrentThreadId()); KVMDEBUG("kvm_server_mainloop / end2", (int)GetCurrentThreadId()); - // if (kvmthread != NULL) { CloseHandle(kvmthread); kvmthread = NULL; } if (tileInfo != NULL) { for (row = 0; row < TILE_HEIGHT_COUNT; row++) free(tileInfo[row]); free(tileInfo); @@ -1187,6 +1171,7 @@ int kvm_relay_setup(char *exePath, void *processPipeMgr, ILibKVM_WriteHandler wr if (ThreadRunning == 1 && g_shutdown == 0) { KVMDEBUG("kvm_relay_setup() session already exists", 0); free(parms); return 0; } kvmthread = CreateThread(NULL, 0, kvm_server_mainloop, (void*)parms, 0, 0); + CloseHandle(kvmthread); return 1; } } diff --git a/microstack/ILibAsyncSocket.c b/microstack/ILibAsyncSocket.c index b3cdfbd..2f4c9b6 100644 --- a/microstack/ILibAsyncSocket.c +++ b/microstack/ILibAsyncSocket.c @@ -413,7 +413,6 @@ void ILibAsyncSocket_Destroy(void *socketModule) #ifndef MICROSTACK_NOTLS module->SSLConnect = 0; #endif - sem_destroy(&(module->SendLock)); } /*! \fn ILibAsyncSocket_SetReAllocateNotificationCallback(ILibAsyncSocket_SocketModule AsyncSocketToken, ILibAsyncSocket_OnBufferReAllocated Callback) \brief Set the callback handler for when the internal data buffer has been resized @@ -476,7 +475,7 @@ ILibAsyncSocket_SocketModule ILibCreateAsyncSocketModuleWithMemory(void *Chain, RetVal->MallocSize = initialBufferSize; RetVal->LifeTime = ILibGetBaseTimer(Chain); //ILibCreateLifeTime(Chain); - sem_init(&(RetVal->SendLock), 0, 1); + ILibSpinLock_Init(&(RetVal->SendLock)); ILibAddToChain(Chain, RetVal); @@ -513,17 +512,15 @@ void ILibAsyncSocket_SendError(ILibAsyncSocket_SocketModule socketModule) module->PAUSE = 1; ILibAsyncSocket_ClearPendingSend(module); // This causes a segfault - SEM_TRACK(AsyncSocket_TrackUnLock("ILibAsyncSocket_SendError", 1, module);) - sem_post(&(module->SendLock)); + ILibSpinLock_UnLock(&(module->SendLock)); // Ensure Calling On_Disconnect with MicroStackThread ILibLifeTime_Add(module->LifeTime, socketModule, 0, &ILibAsyncSocket_Disconnect, NULL); - SEM_TRACK(AsyncSocket_TrackLock("ILibAsyncSocket_SendError", 1, module);) - sem_wait(&(module->SendLock)); + ILibSpinLock_Lock(&(module->SendLock)); } -sem_t *ILibAsyncSocket_GetSendLock(ILibAsyncSocket_SocketModule socketModule) +ILibSpinLock *ILibAsyncSocket_GetSpinLock(ILibAsyncSocket_SocketModule socketModule) { return(&((struct ILibAsyncSocketModule*)socketModule)->SendLock); } @@ -558,7 +555,7 @@ ILibAsyncSocket_SendStatus ILibAsyncSocket_SendTo_MultiWrite(ILibAsyncSocket_Soc #ifndef MICROSTACK_NOTLS if (module->ssl != NULL) { - if (lockOverride == 0) { sem_wait(&(module->SendLock)); } + if (lockOverride == 0) { ILibSpinLock_Lock(&(module->SendLock)); } for (vi = 0; vi < count; ++vi) { @@ -657,14 +654,14 @@ ILibAsyncSocket_SendStatus ILibAsyncSocket_SendTo_MultiWrite(ILibAsyncSocket_Soc ILibAsyncSocket_SendError(module); } - if (lockOverride == 0) { sem_post(&(module->SendLock)); } + if (lockOverride == 0) { ILibSpinLock_UnLock(&(module->SendLock)); } if (retVal != ILibAsyncSocket_ALL_DATA_SENT && !ILibIsRunningOnChainThread(module->Transport.ChainLink.ParentChain)) ILibForceUnBlockChain(module->Transport.ChainLink.ParentChain); return retVal; } #endif // If we got here, we aren't doing TLS - if (lockOverride == 0) { sem_wait(&(module->SendLock)); } + if (lockOverride == 0) { ILibSpinLock_Lock(&(module->SendLock)); } if (module->internalSocket == ~0) { // Too Bad, the socket closed @@ -675,7 +672,7 @@ ILibAsyncSocket_SendStatus ILibAsyncSocket_SendTo_MultiWrite(ILibAsyncSocket_Soc UserFree = va_arg(vlist, ILibAsyncSocket_MemoryOwnership); if (UserFree == ILibAsyncSocket_MemoryOwnership_CHAIN) { free(buffer); } } - if (lockOverride == 0) { sem_post(&(module->SendLock)); } + if (lockOverride == 0) { ILibSpinLock_UnLock(&(module->SendLock)); } va_end(vlist); return ILibAsyncSocket_SEND_ON_CLOSED_SOCKET_ERROR; } @@ -781,7 +778,7 @@ ILibAsyncSocket_SendStatus ILibAsyncSocket_SendTo_MultiWrite(ILibAsyncSocket_Soc } va_end(vlist); - if (lockOverride == 0) { sem_post(&(module->SendLock)); } + if (lockOverride == 0) { ILibSpinLock_UnLock(&(module->SendLock)); } if (notok != 0) { retVal = ILibAsyncSocket_BUFFER_TOO_LARGE; @@ -812,8 +809,7 @@ void ILibAsyncSocket_Disconnect(ILibAsyncSocket_SocketModule socketModule) ILibRemoteLogging_printf(ILibChainGetLogger(module->Transport.ChainLink.ParentChain), ILibRemoteLogging_Modules_Microstack_AsyncSocket, ILibRemoteLogging_Flags_VerbosityLevel_1, "AsyncSocket[%p] << DISCONNECT", (void*)module); - SEM_TRACK(AsyncSocket_TrackLock("ILibAsyncSocket_Disconnect", 1, module);) - sem_wait(&(module->SendLock)); + ILibSpinLock_Lock(&(module->SendLock)); module->timeout_handler = NULL; module->timeout_milliSeconds = 0; @@ -823,9 +819,9 @@ void ILibAsyncSocket_Disconnect(ILibAsyncSocket_SocketModule socketModule) { SSL_TRACE1("ILibAsyncSocket_Disconnect()"); SSL_shutdown(module->ssl); - sem_post(&(module->SendLock)); + ILibSpinLock_UnLock(&(module->SendLock)); SSL_free(module->ssl); // Frees SSL session and both BIO buffers at the same time - sem_wait(&(module->SendLock)); + ILibSpinLock_Lock(&(module->SendLock)); module->ssl = NULL; SSL_TRACE2("ILibAsyncSocket_Disconnect()"); } @@ -852,8 +848,7 @@ void ILibAsyncSocket_Disconnect(ILibAsyncSocket_SocketModule socketModule) // Since the socket is closing, we need to clear the data that is pending to be sent ILibAsyncSocket_ClearPendingSend(socketModule); - SEM_TRACK(AsyncSocket_TrackUnLock("ILibAsyncSocket_Disconnect", 2, module);) - sem_post(&(module->SendLock)); + ILibSpinLock_UnLock(&(module->SendLock)); #ifndef MICROSTACK_NOTLS if (wasssl == NULL) @@ -879,8 +874,7 @@ void ILibAsyncSocket_Disconnect(ILibAsyncSocket_SocketModule socketModule) } else { - SEM_TRACK(AsyncSocket_TrackUnLock("ILibAsyncSocket_Disconnect", 3, module);) - sem_post(&(module->SendLock)); + ILibSpinLock_UnLock(&(module->SendLock)); } } @@ -1089,7 +1083,7 @@ ILibAsyncSocket_SendStatus ILibAsyncSocket_ProcessEncryptedBuffer(ILibAsyncSocke ILibAsyncSocket_SendData *data; ILibAsyncSocket_SendStatus retVal = ILibAsyncSocket_SEND_ON_CLOSED_SOCKET_ERROR; - sem_wait(&(Reader->SendLock)); + ILibSpinLock_Lock(&(Reader->SendLock)); if (Reader->writeBioBuffer->length > 0) { if (Reader->PendingSend_Tail == NULL) @@ -1136,7 +1130,7 @@ ILibAsyncSocket_SendStatus ILibAsyncSocket_ProcessEncryptedBuffer(ILibAsyncSocke // Don't need to do anything, becuase it'll get picked up in the PostSelect } } - sem_post(&(Reader->SendLock)); + ILibSpinLock_UnLock(&(Reader->SendLock)); return retVal; } #endif @@ -1388,9 +1382,9 @@ void ILibProcessAsyncSocket(struct ILibAsyncSocketModule *Reader, int pendingRea if (Reader->ssl != NULL) { SSL_free(Reader->ssl); // Frees SSL session and BIO buffer at the same time - sem_wait(&(Reader->SendLock)); + ILibSpinLock_Lock(&(Reader->SendLock)); Reader->ssl = NULL; - sem_post(&(Reader->SendLock)); + ILibSpinLock_UnLock(&(Reader->SendLock)); } #endif @@ -1532,8 +1526,7 @@ void ILibAsyncSocket_PreSelect(void* socketModule,fd_set *readset, fd_set *write ILibRemoteLogging_printf(ILibChainGetLogger(module->Transport.ChainLink.ParentChain), ILibRemoteLogging_Modules_Microstack_AsyncSocket, ILibRemoteLogging_Flags_VerbosityLevel_5, "AsyncSocket[%p] entered PreSelect", (void*)module); - SEM_TRACK(AsyncSocket_TrackLock("ILibAsyncSocket_PreSelect", 1, module);) - sem_wait(&(module->SendLock)); + ILibSpinLock_Lock(&(module->SendLock)); if (module->internalSocket != -1) { @@ -1556,9 +1549,9 @@ void ILibAsyncSocket_PreSelect(void* socketModule,fd_set *readset, fd_set *write module->timeout_handler = NULL; if (h != NULL) { - sem_post(&(module->SendLock)); + ILibSpinLock_UnLock(&(module->SendLock)); h(module, module->user); - sem_wait(&(module->SendLock)); + ILibSpinLock_Lock(&(module->SendLock)); if (module->timeout_milliSeconds != 0) { *blocktime = module->timeout_milliSeconds; @@ -1616,8 +1609,7 @@ void ILibAsyncSocket_PreSelect(void* socketModule,fd_set *readset, fd_set *write } } - SEM_TRACK(AsyncSocket_TrackUnLock("ILibAsyncSocket_PreSelect", 2, module);) - sem_post(&(module->SendLock)); + ILibSpinLock_UnLock(&(module->SendLock)); ILibRemoteLogging_printf(ILibChainGetLogger(module->Transport.ChainLink.ParentChain), ILibRemoteLogging_Modules_Microstack_AsyncSocket, ILibRemoteLogging_Flags_VerbosityLevel_5, "...AsyncSocket[%p] exited PreSelect", (void*)module); } @@ -1706,8 +1698,7 @@ void ILibAsyncSocket_PostSelect(void* socketModule, int slct, fd_set *readset, f UNREFERENCED_PARAMETER( slct ); - SEM_TRACK(AsyncSocket_TrackLock("ILibAsyncSocket_PostSelect", 1, module);) - sem_wait(&(module->SendLock)); // Lock! + ILibSpinLock_Lock(&(module->SendLock)); // Lock! //if (fd_error != 0) printf("ILibAsyncSocket_PostSelect-ERROR\r\n"); //if (fd_read != 0) printf("ILibAsyncSocket_PostSelect-READ\r\n"); @@ -1760,8 +1751,7 @@ void ILibAsyncSocket_PostSelect(void* socketModule, int slct, fd_set *readset, f if (serr != 0) { // Unlock before fireing the event - SEM_TRACK(AsyncSocket_TrackUnLock("ILibAsyncSocket_PostSelect", 4, module);) - sem_post(&(module->SendLock)); + ILibSpinLock_UnLock(&(module->SendLock)); ILibAsyncSocket_PrivateShutdown(module); } else @@ -1820,8 +1810,7 @@ void ILibAsyncSocket_PostSelect(void* socketModule, int slct, fd_set *readset, f // TODO: Set timeout. If the proxy does not respond, we need to close this connection. // On the other hand... This is not generally a problem, proxies will disconnect after a timeout anyway. - SEM_TRACK(AsyncSocket_TrackUnLock("ILibAsyncSocket_PostSelect", 4, module);) - sem_post(&(module->SendLock)); + ILibSpinLock_UnLock(&(module->SendLock)); return; } if (module->ProxyState == 2) module->ProxyState = 3; @@ -1832,8 +1821,7 @@ void ILibAsyncSocket_PostSelect(void* socketModule, int slct, fd_set *readset, f } // Unlock before fireing the event - SEM_TRACK(AsyncSocket_TrackUnLock("ILibAsyncSocket_PostSelect", 4, module);) - sem_post(&(module->SendLock)); + ILibSpinLock_UnLock(&(module->SendLock)); // If we did connect, we got more things to do if (triggerWriteSet != 0) @@ -1871,17 +1859,14 @@ void ILibAsyncSocket_PostSelect(void* socketModule, int slct, fd_set *readset, f } // Unlock before fireing the event - SEM_TRACK(AsyncSocket_TrackUnLock("ILibAsyncSocket_PostSelect", 4, module);) - sem_post(&(module->SendLock)); + ILibSpinLock_UnLock(&(module->SendLock)); if (triggerReadSet != 0 || triggerResume != 0) ILibProcessAsyncSocket(module, triggerReadSet); } } - SEM_TRACK(AsyncSocket_TrackUnLock("ILibAsyncSocket_PostSelect", 4, module);) - SEM_TRACK(AsyncSocket_TrackLock("ILibAsyncSocket_PostSelect", 1, module);) - sem_wait(&(module->SendLock)); + ILibSpinLock_Lock(&(module->SendLock)); // Write Handling if (module->FinConnect > 0 && module->internalSocket != ~0 && fd_write != 0 && module->PendingSend_Head != NULL && (module->ProxyState != 1)) { @@ -2087,8 +2072,7 @@ void ILibAsyncSocket_PostSelect(void* socketModule, int slct, fd_set *readset, f // This triggers OnSendOK, if all the pending data has been sent. if (module->PendingSend_Head == NULL && bytesSent != -1) { TriggerSendOK = 1; } - SEM_TRACK(AsyncSocket_TrackUnLock("ILibAsyncSocket_PostSelect", 2, module);) - sem_post(&(module->SendLock)); + ILibSpinLock_UnLock(&(module->SendLock)); #ifndef MICROSTACK_NOTLS if (TriggerSendOK != 0 && (module->ssl == NULL || module->SSLConnect != 0)) #else @@ -2106,8 +2090,7 @@ void ILibAsyncSocket_PostSelect(void* socketModule, int slct, fd_set *readset, f } else { - SEM_TRACK(AsyncSocket_TrackUnLock("ILibAsyncSocket_PostSelect", 2, module);) - sem_post(&(module->SendLock)); + ILibSpinLock_UnLock(&(module->SendLock)); } ILibRemoteLogging_printf(ILibChainGetLogger(module->Transport.ChainLink.ParentChain), ILibRemoteLogging_Modules_Microstack_AsyncSocket, ILibRemoteLogging_Flags_VerbosityLevel_5, "...AsyncSocket[%p] exited PostSelect", (void*)module); diff --git a/microstack/ILibParsers.c b/microstack/ILibParsers.c index 7c9b9a4..b7a51c6 100644 --- a/microstack/ILibParsers.c +++ b/microstack/ILibParsers.c @@ -230,7 +230,7 @@ typedef struct ILibSparseArray_Root ILibSparseArray_Node* bucket; int bucketSize; ILibSparseArray_Bucketizer bucketizer; - sem_t LOCK; + ILibSpinLock LOCK; int userMemorySize; }ILibSparseArray_Root; const int ILibMemory_SparseArray_CONTAINERSIZE = sizeof(ILibSparseArray_Root); @@ -268,14 +268,14 @@ struct ILibQueueNode { struct ILibStackNode *Head; struct ILibStackNode *Tail; - sem_t LOCK; + ILibSpinLock LOCK; }; struct HashNode_Root { struct HashNode *Root; int CaseInSensitive; void *Reserved; - sem_t LOCK; + ILibSpinLock LOCK; }; struct HashNode { @@ -300,7 +300,7 @@ typedef struct ILibLinkedListNode }ILibLinkedListNode; typedef struct ILibLinkedListNode_Root { - sem_t LOCK; + ILibSpinLock LOCK; long count; void* Tag; struct ILibLinkedListNode *Head; @@ -4943,7 +4943,7 @@ void ILibClearStack(void **TheStack) void ILibHashTree_Lock(void *hashtree) { struct HashNode_Root *r = (struct HashNode_Root*)hashtree; - sem_wait(&(r->LOCK)); + ILibSpinLock_Lock(&(r->LOCK)); } /*! \fn ILibHashTree_UnLock(void *hashtree) @@ -4953,7 +4953,7 @@ void ILibHashTree_Lock(void *hashtree) void ILibHashTree_UnLock(void *hashtree) { struct HashNode_Root *r = (struct HashNode_Root*)hashtree; - sem_post(&(r->LOCK)); + ILibSpinLock_UnLock(&(r->LOCK)); } /*! \fn ILibDestroyHashTree(void *tree) @@ -4966,7 +4966,6 @@ void ILibDestroyHashTree(void *tree) struct HashNode *c = r->Root; struct HashNode *n; - sem_destroy(&(r->LOCK)); while (c != NULL) { // @@ -5110,7 +5109,7 @@ void* ILibInitHashTreeEx(void *ReservedMemory) } Root->Root = RetVal; - if (ReservedMemory == NULL) { sem_init(&(Root->LOCK), 0, 1); } + if (ReservedMemory == NULL) { ILibSpinLock_Init(&(Root->LOCK)); } return(Root); } /*! \fn void* ILibInitHashTree_CaseInSensitive() @@ -7671,8 +7670,7 @@ void* ILibLinkedList_CreateEx(int userMemorySize) ILibMemory_Allocate(sizeof(ILibLinkedListNode_Root), userMemorySize, (void**)&root, &mem); root->ExtraMemory = mem; - - sem_init(&(root->LOCK), 0, 1); + ILibSpinLock_Init(&(root->LOCK)); return root; } @@ -8003,7 +8001,7 @@ void* ILibLinkedList_Node_ResizeAdditional(void *node, size_t additionalSize) void ILibLinkedList_Lock(void *LinkedList) { struct ILibLinkedListNode_Root *r = (struct ILibLinkedListNode_Root*)LinkedList; - sem_wait(&(r->LOCK)); + ILibSpinLock_Lock(&(r->LOCK)); } /*! \fn void ILibLinkedList_UnLock(void *LinkedList) @@ -8013,7 +8011,7 @@ void ILibLinkedList_Lock(void *LinkedList) void ILibLinkedList_UnLock(void *LinkedList) { struct ILibLinkedListNode_Root *r = (struct ILibLinkedListNode_Root*)LinkedList; - sem_post(&(r->LOCK)); + ILibSpinLock_UnLock(&(r->LOCK)); } @@ -8027,7 +8025,6 @@ void ILibLinkedList_Destroy(void *LinkedList) { struct ILibLinkedListNode_Root *r = (struct ILibLinkedListNode_Root*)LinkedList; while (r->Head != NULL) ILibLinkedList_Remove(ILibLinkedList_GetNode_Head(LinkedList)); - sem_destroy(&(r->LOCK)); free(r); } @@ -8417,7 +8414,7 @@ ILibSparseArray ILibSparseArray_CreateWithUserMemory(int numberOfBuckets, ILibSp { ILibSparseArray_Root *retVal = (ILibSparseArray_Root*)ILibMemory_Allocate(sizeof(ILibSparseArray_Root), userMemorySize, NULL, NULL); - sem_init(&(retVal->LOCK), 0, 1); + ILibSpinLock_Init(&(retVal->LOCK)); retVal->bucketSize = numberOfBuckets; retVal->bucketizer = bucketizer; retVal->bucket = (ILibSparseArray_Node*)malloc(numberOfBuckets * sizeof(ILibSparseArray_Node)); @@ -8638,7 +8635,6 @@ void ILibSparseArray_ClearEx2(ILibSparseArray sarray, ILibSparseArray_OnValue on void ILibSparseArray_DestroyEx(ILibSparseArray sarray, ILibSparseArray_OnValue onDestroy, void *user) { ILibSparseArray_ClearEx(sarray, onDestroy, user); - sem_destroy(&((ILibSparseArray_Root*)sarray)->LOCK); free(((ILibSparseArray_Root*)sarray)->bucket); free(sarray); } @@ -8656,7 +8652,7 @@ void ILibSparseArray_Destroy(ILibSparseArray sarray) */ void ILibSparseArray_Lock(ILibSparseArray sarray) { - sem_wait(&(((ILibSparseArray_Root*)sarray)->LOCK)); + ILibSpinLock_Lock(&(((ILibSparseArray_Root*)sarray))); } //! Use the Sparse Array as a synchronization lock, and release it /*! @@ -8664,7 +8660,7 @@ void ILibSparseArray_Lock(ILibSparseArray sarray) */ void ILibSparseArray_UnLock(ILibSparseArray sarray) { - sem_post(&(((ILibSparseArray_Root*)sarray)->LOCK)); + ILibSpinLock_UnLock(&(((ILibSparseArray_Root*)sarray)->LOCK)); } int ILibString_IndexOfFirstWhiteSpace(const char *inString, size_t inStringLength) @@ -10540,6 +10536,7 @@ void ILibThread_Join(void *thr) { #ifdef WIN32 WaitForSingleObject((HANDLE)thr, INFINITE); + CloseHandle((HANDLE)thr); #else #if defined(__APPLE__) || defined(ILIB_NO_TIMEDJOIN) if (ILibMemory_CanaryOK(thr) && ((ILibThread_AppleThread*)thr)->joinable!=0) diff --git a/microstack/ILibWebClient.c b/microstack/ILibWebClient.c index 0f9dda4..6fb3cf6 100644 --- a/microstack/ILibWebClient.c +++ b/microstack/ILibWebClient.c @@ -78,7 +78,7 @@ void WebClient_TrackUnLock(const char* MethodName, int Occurance, void *data) #include "ILibRemoteLogging.h" #include "ILibCrypto.h" -extern sem_t *ILibAsyncSocket_GetSendLock(ILibAsyncSocket_SocketModule socketModule); +extern ILibSpinLock *ILibAsyncSocket_GetSpinLock(ILibAsyncSocket_SocketModule socketModule); #ifndef MICROSTACK_NOTLS int ILibWebClientDataObjectIndex = -1; @@ -169,7 +169,7 @@ struct ILibWebClientManager void *timer; int idleCount; - sem_t QLock; + ILibSpinLock QLock; void *user; @@ -523,7 +523,6 @@ void ILibDestroyWebClient(void *object) ILibQueue_Destroy(manager->backlogQueue); ILibDestroyHashTree(manager->idleTable); ILibDestroyHashTree(manager->DataTable); - sem_destroy(&(manager->QLock)); free(manager->socks); #ifndef MICROSTACK_NOTLS @@ -605,8 +604,7 @@ void ILibWebClient_TimerSink(void *object) void *data; void *DisconnectSocket = NULL; - SEM_TRACK(WebClient_TrackLock("ILibWebClient_TimerSink", 1, wcdo->Parent);) - sem_wait(&(wcdo->Parent->QLock)); + ILibSpinLock_Lock(&(wcdo->Parent->QLock)); if (ILibQueue_IsEmpty(wcdo->RequestQueue)!=0) { // @@ -634,8 +632,7 @@ void ILibWebClient_TimerSink(void *object) wcdo2 = (struct ILibWebClientDataObject*)ILibGetEntry(wcdo->Parent->DataTable, key, keyLength); ILibDeleteEntry(wcdo->Parent->DataTable, key, keyLength); ILibDeleteEntry(wcdo->Parent->idleTable, key, keyLength); - SEM_TRACK(WebClient_TrackUnLock("ILibWebClient_TimerSink",2,wcdo->Parent);) - sem_post(&(wcdo->Parent->QLock)); + ILibSpinLock_UnLock(&(wcdo->Parent->QLock)); ILibWebClient_DestroyWebClientDataObject(wcdo2); return; } @@ -652,8 +649,7 @@ void ILibWebClient_TimerSink(void *object) wcdo->DisconnectSent=0; } } - SEM_TRACK(WebClient_TrackUnLock("ILibWebClient_TimerSink", 3, wcdo->Parent);) - sem_post(&(wcdo->Parent->QLock)); + ILibSpinLock_UnLock(&(wcdo->Parent->QLock)); // // Let the user know, the socket has been disconnected // @@ -761,21 +757,18 @@ void ILibWebClient_FinishedResponse(ILibAsyncSocket_SocketModule socketModule, s // so this finished response isn't valid anymore if (wcdo->SOCK == NULL || ILibAsyncSocket_IsFree(wcdo->SOCK)) { - SEM_TRACK(WebClient_TrackLock("ILibWebClient_FinishedResponse", 1, wcdo->Parent);) - sem_wait(&(wcdo->Parent->QLock)); + ILibSpinLock_Lock(&(wcdo->Parent->QLock)); wr = (struct ILibWebRequest*)ILibQueue_DeQueue(wcdo->RequestQueue); if (wr != NULL) { wr->connectionCloseWasSpecified = 2; ILibWebClient_DestroyWebRequest(wr); } - SEM_TRACK(WebClient_TrackUnLock("ILibWebClient_FinishedResponse", 2, wcdo->Parent);) - sem_post(&(wcdo->Parent->QLock)); + ILibSpinLock_UnLock(&(wcdo->Parent->QLock)); return; } - SEM_TRACK(WebClient_TrackLock("ILibWebClient_FinishedResponse", 1, wcdo->Parent);) - sem_wait(&(wcdo->Parent->QLock)); + ILibSpinLock_Lock(&(wcdo->Parent->QLock)); wr = (struct ILibWebRequest*)ILibQueue_DeQueue(wcdo->RequestQueue); if (wr != NULL) { @@ -798,8 +791,7 @@ void ILibWebClient_FinishedResponse(ILibAsyncSocket_SocketModule socketModule, s } } } - SEM_TRACK(WebClient_TrackUnLock("ILibWebClient_FinishedResponse", 2 ,wcdo->Parent);) - sem_post(&(wcdo->Parent->QLock)); + ILibSpinLock_UnLock(&(wcdo->Parent->QLock)); //{{{ REMOVE_THIS_FOR_HTTP/1.0_ONLY_SUPPORT--> }}} if (wr != NULL) @@ -898,14 +890,12 @@ void ILibWebClient_ProcessChunk(ILibAsyncSocket_SocketModule socketModule, struc // if (wcdo->Parent!=NULL) { - SEM_TRACK(WebClient_TrackLock("ILibWebClient_ProcessChunk",1,wcdo->Parent);) - sem_wait(&(wcdo->Parent->QLock)); + ILibSpinLock_Lock(&(wcdo->Parent->QLock)); } wr = (struct ILibWebRequest*)ILibQueue_PeekQueue(wcdo->RequestQueue); if (wcdo->Parent!=NULL) { - SEM_TRACK(WebClient_TrackUnLock("ILibWebClient_ProcessChunk",2,wcdo->Parent);) - sem_post(&(wcdo->Parent->QLock)); + ILibSpinLock_UnLock(&(wcdo->Parent->QLock)); } if (wcdo->chunk==NULL) @@ -1250,7 +1240,7 @@ ILibAsyncSocket_SendStatus ILibWebClient_WebSocket_Send(ILibWebClient_StateObjec #endif #endif - sem_wait(ILibAsyncSocket_GetSendLock(wcdo->SOCK)); + ILibSpinLock_Lock(ILibAsyncSocket_GetSpinLock(wcdo->SOCK)); while (i < _bufferLen) { if (i < 0) { i = 0; } @@ -1304,7 +1294,7 @@ ILibAsyncSocket_SendStatus ILibWebClient_WebSocket_Send(ILibWebClient_StateObjec RetVal = ILibAsyncSocket_SendTo_MultiWrite(wcdo->SOCK, NULL, 2 | ILibAsyncSocket_LOCK_OVERRIDE, header, (size_t)headerLen, ILibAsyncSocket_MemoryOwnership_USER, buffer, (size_t)bufferLen, ILibAsyncSocket_MemoryOwnership_USER); } } - sem_post(ILibAsyncSocket_GetSendLock(wcdo->SOCK)); + ILibSpinLock_UnLock(ILibAsyncSocket_GetSpinLock(wcdo->SOCK)); return RetVal; } void ILibWebClient_WebSocket_SetPingPongHandler(ILibWebClient_StateObject obj, ILibWebClient_WebSocket_PingHandler pingHandler, ILibWebClient_WebSocket_PongHandler pongHandler, void *user) @@ -1514,14 +1504,12 @@ ILibWebClient_DataResults ILibWebClient_OnData(ILibAsyncSocket_SocketModule sock if (wcdo->Server == 0) { - SEM_TRACK(WebClient_TrackLock("ILibWebClient_OnData", 1, wcdo->Parent);) - sem_wait(&(wcdo->Parent->QLock)); + ILibSpinLock_Lock(&(wcdo->Parent->QLock)); } wr = (struct ILibWebRequest*)ILibQueue_PeekQueue(wcdo->RequestQueue); if (wcdo->Server == 0) { - SEM_TRACK(WebClient_TrackUnLock("ILibWebClient_OnData", 2, wcdo->Parent);) - sem_post(&(wcdo->Parent->QLock)); + ILibSpinLock_UnLock(&(wcdo->Parent->QLock)); } if (wr == NULL) { @@ -2083,11 +2071,9 @@ void ILibWebClient_OnConnect(ILibAsyncSocket_SocketModule socketModule, int Conn // Success: Send First Request ILibAsyncSocket_GetLocalInterface(socketModule, (struct sockaddr*)&(wcdo->LocalIP)); - SEM_TRACK(WebClient_TrackLock("ILibWebClient_OnConnect", 1, wcdo->Parent);) - sem_wait(&(wcdo->Parent->QLock)); + ILibSpinLock_Lock(&(wcdo->Parent->QLock)); r = (struct ILibWebRequest*)ILibQueue_PeekQueue(wcdo->RequestQueue); - SEM_TRACK(WebClient_TrackUnLock("ILibWebClient_OnConnect", 2, wcdo->Parent);) - sem_post(&(wcdo->Parent->QLock)); + ILibSpinLock_UnLock(&(wcdo->Parent->QLock)); if (r != NULL) { if (r->ConnectSink != NULL) { r->ConnectSink(r->requestToken); } @@ -2128,16 +2114,14 @@ void ILibWebClient_OnConnect(ILibAsyncSocket_SocketModule socketModule, int Conn // // Retried enough times, give up // - SEM_TRACK(WebClient_TrackLock("ILibWebClient_OnConnect", 3, wcdo->Parent);) - sem_wait(&(wcdo->Parent->QLock)); + ILibSpinLock_Lock(&(wcdo->Parent->QLock)); keyLength = ILibCreateTokenStr((struct sockaddr*)&(wcdo->remote), wcdo->IndexNumber, key); ILibDeleteEntry(wcdo->Parent->DataTable, key, keyLength); ILibDeleteEntry(wcdo->Parent->idleTable, key, keyLength); - SEM_TRACK(WebClient_TrackUnLock("ILibWebClient_OnConnect", 4, wcdo->Parent);) - sem_post(&(wcdo->Parent->QLock)); + ILibSpinLock_UnLock(&(wcdo->Parent->QLock)); ILibWebClient_DestroyWebClientDataObject(wcdo); } @@ -2197,11 +2181,9 @@ void ILibWebClient_OnDisconnectSink(ILibAsyncSocket_SocketModule socketModule, v // ILibAsyncSocket_GetBuffer(socketModule,&buffer,&BeginPointer,&EndPointer); - SEM_TRACK(WebClient_TrackLock("ILibWebClient_OnDisconnect", 1, wcdo->Parent);) - sem_wait(&(wcdo->Parent->QLock)); + ILibSpinLock_Lock(&(wcdo->Parent->QLock)); wr = (struct ILibWebRequest*)ILibQueue_DeQueue(wcdo->RequestQueue); - SEM_TRACK(WebClient_TrackUnLock("ILibWebClient_OnDisconnect", 2, wcdo->Parent);) - sem_post(&(wcdo->Parent->QLock)); + ILibSpinLock_UnLock(&(wcdo->Parent->QLock)); wcdo->InitialRequestAnswered = 1; //{{{ REMOVE_THIS_FOR_HTTP/1.0_ONLY_SUPPORT--> }}} //wcdo->PipelineFlag = PIPELINE_NO; @@ -2232,11 +2214,9 @@ void ILibWebClient_OnDisconnectSink(ILibAsyncSocket_SocketModule socketModule, v if (wcdo->Closing != 0) { return; } - SEM_TRACK(WebClient_TrackLock("ILibWebClient_OnDisconnect", 3, wcdo->Parent);) - sem_wait(&(wcdo->Parent->QLock)); + ILibSpinLock_Lock(&(wcdo->Parent->QLock)); wr = (struct ILibWebRequest*)ILibQueue_PeekQueue(wcdo->RequestQueue); - SEM_TRACK(WebClient_TrackUnLock("ILibWebClient_OnDisconnect", 4, wcdo->Parent);) - sem_post(&(wcdo->Parent->QLock)); + ILibSpinLock_UnLock(&(wcdo->Parent->QLock)); if (wr != NULL) { @@ -2306,8 +2286,7 @@ void ILibWebClient_PreProcess(void* WebClientModule, fd_set *readset, fd_set *wr // Try and satisfy as many things as we can. If we have resources // grab a socket and go // - SEM_TRACK(WebClient_TrackLock("ILibWebClient_PreProcess",1,wcm);) - sem_wait(&(wcm->QLock)); + ILibSpinLock_Lock(&(wcm->QLock)); while (xOK == 0 && ILibQueue_IsEmpty(wcm->backlogQueue) == 0) { xOK = 1; @@ -2376,8 +2355,7 @@ void ILibWebClient_PreProcess(void* WebClientModule, fd_set *readset, fd_set *wr if (ILibQueue_IsEmpty(wcm->backlogQueue) != 0) break; } } - SEM_TRACK(WebClient_TrackUnLock("ILibWebClient_PreProcess", 2, wcm);) - sem_post(&(wcm->QLock)); + ILibSpinLock_UnLock(&(wcm->QLock)); } // @@ -2503,7 +2481,7 @@ ILibWebClient_RequestManager ILibCreateWebClient(int PoolSize, void *Chain) RetVal->socksLength = PoolSize; RetVal->socks = (void**)malloc(PoolSize * sizeof(void*)); if (RetVal->socks == NULL) ILIBCRITICALEXIT(254); - sem_init(&(RetVal->QLock), 0, 1); + ILibSpinLock_Init(&(RetVal->QLock)); RetVal->ChainLink.ParentChain = Chain; RetVal->backlogQueue = ILibQueue_Create(); @@ -2708,8 +2686,7 @@ ILibWebClient_RequestToken ILibWebClient_PipelineRequestEx2( // // Does the client already have a connection to the server? // - SEM_TRACK(WebClient_TrackLock("ILibWebClient_PipelineRequestEx", 1, wcm);) - sem_wait(&(wcm->QLock)); + ILibSpinLock_Lock(&(wcm->QLock)); if (wcm->MaxConnectionsToSameServer > 1) { @@ -2827,8 +2804,7 @@ ILibWebClient_RequestToken ILibWebClient_PipelineRequestEx2( } } - SEM_TRACK(WebClient_TrackUnLock("ILibWebClient_PipelineRequestEx", 2, wcm);) - sem_post(&(wcm->QLock)); + ILibSpinLock_UnLock(&(wcm->QLock)); if (ForceUnBlock != 0) ILibForceUnBlockChain(wcm->ChainLink.ParentChain); SESSION_TRACK(request->requestToken, NULL, "PipelinedRequestEx"); return(request->requestToken); @@ -2932,8 +2908,7 @@ void ILibWebClient_DeleteRequests(ILibWebClient_RequestManager WebClientToken, s // // Are there any pending requests to this IP/Port combo? // - SEM_TRACK(WebClient_TrackLock("ILibWebClient_DeleteRequests", 1, wcm);) - sem_wait(&(wcm->QLock)); + ILibSpinLock_Lock(&(wcm->QLock)); if (ILibHasEntry(wcm->DataTable, RequestToken, RequestTokenLength) != 0) { // @@ -2958,8 +2933,7 @@ void ILibWebClient_DeleteRequests(ILibWebClient_RequestManager WebClientToken, s ILibLifeTime_Remove(wcdo->Parent->timer, wcdo); } } - SEM_TRACK(WebClient_TrackUnLock("ILibWebClient_DeleteRequests",2,wcm);) - sem_post(&(wcm->QLock)); + ILibSpinLock_UnLock(&(wcm->QLock)); } @@ -3065,8 +3039,7 @@ void ILibWebClient_CancelRequestEx2(ILibWebClient_StateObject wcdo, void *userRe { PendingRequestQ = ILibQueue_Create(); - SEM_TRACK(WebClient_TrackLock("ILibWebClient_CancelRequest",1,_wcdo->Parent);) - sem_wait(&(_wcdo->Parent->QLock)); + ILibSpinLock_Lock(&(_wcdo->Parent->QLock)); head = node = ILibLinkedList_GetNode_Head(_wcdo->RequestQueue); while (node != NULL) @@ -3107,13 +3080,11 @@ void ILibWebClient_CancelRequestEx2(ILibWebClient_StateObject wcdo, void *userRe _wcdo->Closing = 2; _wcdo->CancelRequest = 1; - SEM_TRACK(WebClient_TrackUnLock("ILibWebClient_CancelRequest", 2, _wcdo->Parent);) - sem_post(&(_wcdo->Parent->QLock)); + ILibSpinLock_UnLock(&(_wcdo->Parent->QLock)); ILibWebClient_Disconnect(_wcdo); - SEM_TRACK(WebClient_TrackLock("ILibWebClient_CancelRequest", 3, _wcdo->Parent);) - sem_wait(&(_wcdo->Parent->QLock)); + ILibSpinLock_Lock(&(_wcdo->Parent->QLock)); _wcdo->Closing = 0; _wcdo->CancelRequest = 0; @@ -3131,8 +3102,7 @@ void ILibWebClient_CancelRequestEx2(ILibWebClient_StateObject wcdo, void *userRe } } - SEM_TRACK(WebClient_TrackUnLock("ILibWebClient_CancelRequest", 2, _wcdo->Parent);) - sem_post(&(_wcdo->Parent->QLock)); + ILibSpinLock_UnLock(&(_wcdo->Parent->QLock)); wr = (struct ILibWebRequest*)ILibQueue_DeQueue(PendingRequestQ); while (wr != NULL) @@ -3803,14 +3773,14 @@ void ILibWebClient_RequestToken_ConnectionHandler_Set(ILibWebClient_RequestToken if (wcdo != NULL) { - sem_wait(&(wcdo->Parent->QLock)); + ILibSpinLock_Lock(&(wcdo->Parent->QLock)); wr = (struct ILibWebRequest*)ILibQueue_PeekTail(wcdo->RequestQueue); if (wr != NULL) { wr->ConnectSink = OnConnect; wr->DisconnectSink = OnDisconnect; } - sem_post(&(wcdo->Parent->QLock)); + ILibSpinLock_UnLock(&(wcdo->Parent->QLock)); } } #ifdef MICROSTACK_PROXY diff --git a/microstack/ILibWebRTC.c b/microstack/ILibWebRTC.c index 1e4209a..8800050 100644 --- a/microstack/ILibWebRTC.c +++ b/microstack/ILibWebRTC.c @@ -694,7 +694,7 @@ typedef struct ILibStun_dTlsSession unsigned int userTSN; long long lastResent; int state; // 0 = Free, 1 = Setup, 2 = Connecting, 3 = Disconnecting, 4 = Handshake - sem_t Lock; + ILibSpinLock Lock; ILibSparseArray DataChannelMetaDeta; ILibSparseArray DataChannelMetaDetaValues; @@ -1322,9 +1322,9 @@ int ILibSCTP_GetUser4(void* module) { return ((struct ILibStun_dTlsSession*)modu int ILibSCTP_GetPendingBytesToSend(void* sctpSession) { int r; - sem_wait(&(((struct ILibStun_dTlsSession*)sctpSession)->Lock)); + ILibSpinLock_Lock(&(((struct ILibStun_dTlsSession*)sctpSession)->Lock)); r = ((struct ILibStun_dTlsSession*)sctpSession)->holdingByteCount; - sem_post(&(((struct ILibStun_dTlsSession*)sctpSession)->Lock)); + ILibSpinLock_UnLock(&(((struct ILibStun_dTlsSession*)sctpSession)->Lock)); if (r < 0) return 0 - r; return 0; } @@ -1618,7 +1618,7 @@ void ILibWebRTC_CloseDataChannel_Timeout(void *obj) struct ILibStun_dTlsSession *o = ILibWebRTC_DTLS_FROM_TIMER_OBJECT(obj); int newTimeout; - sem_wait(&o->Lock); + ILibSpinLock_Lock(&o->Lock); ++o->reconfigFailures; newTimeout = RTO_MIN * (0x01 << o->reconfigFailures); // Exponential Backoff @@ -1630,7 +1630,7 @@ void ILibWebRTC_CloseDataChannel_Timeout(void *obj) o->pendingReconfigPacket = NULL; o->reconfigFailures = 0; - sem_post(&(o->Lock)); + ILibSpinLock_UnLock(&(o->Lock)); if (dup != NULL) { ILibWebRTC_PropagateChannelCloseEx(dup, o); } } @@ -1640,7 +1640,7 @@ void ILibWebRTC_CloseDataChannel_Timeout(void *obj) ILibRemoteLogging_printf(ILibChainGetLogger(o->Transport.ChainLink.ParentChain), ILibRemoteLogging_Modules_WebRTC_SCTP, ILibRemoteLogging_Flags_VerbosityLevel_1, "RECONFIG CHUNK retry attempt %d on Dtls Session: %d", o->reconfigFailures, o->sessionId); ILibLifeTime_AddEx(o->parent->Timer, ILibWebRTC_DTLS_TO_TIMER_OBJECT(o), newTimeout, &ILibWebRTC_CloseDataChannel_Timeout, NULL); ILibStun_SendSctpPacket(o->parent, o->sessionId, o->pendingReconfigPacket, (int)ntohs(((unsigned short*)(o->pendingReconfigPacket + 14))[0])); - sem_post(&o->Lock); + ILibSpinLock_UnLock(&o->Lock); } } @@ -3402,9 +3402,9 @@ ILibTransport_DoneState ILibSCTP_SendEx(void* sctpSession, unsigned short stream ILibTransport_DoneState r; struct ILibStun_dTlsSession* obj = (struct ILibStun_dTlsSession*)sctpSession; if (obj->state != 2) return ILibTransport_DoneState_ERROR; // Error - sem_wait(&(obj->Lock)); + ILibSpinLock_Lock(&(obj->Lock)); r = ILibStun_SctpSendData(obj->parent, obj->sessionId, streamId, dataType, data, datalen); - sem_post(&(obj->Lock)); + ILibSpinLock_UnLock(&(obj->Lock)); RCTPDEBUG(printf("ILibSCTP_Send() len=%d, r=%d\r\n", datalen, r);) return r; } @@ -3416,7 +3416,7 @@ void ILibStun_SctpProcessStreamData(struct ILibStun_Module *obj, int session, un // TODO: Add error case for when invalid streamId is specified. Bryan - sem_wait(&(obj->dTlsSessions[session]->Lock)); + ILibSpinLock_Lock(&(obj->dTlsSessions[session]->Lock)); if(pid == 50) { // WebRTC Control @@ -3434,9 +3434,9 @@ void ILibStun_SctpProcessStreamData(struct ILibStun_Module *obj, int session, un ILibRemoteLogging_printf(ILibChainGetLogger(obj->ChainLink.ParentChain), ILibRemoteLogging_Modules_WebRTC_SCTP, ILibRemoteLogging_Flags_VerbosityLevel_1, "Data Channel ACK on session: %u for StreamId: %u", session, streamId); - sem_post(&(obj->dTlsSessions[session]->Lock)); + ILibSpinLock_UnLock(&(obj->dTlsSessions[session]->Lock)); if (obj->OnWebRTCDataChannelAck != NULL) { obj->OnWebRTCDataChannelAck(obj, obj->dTlsSessions[session], streamId); } - sem_wait(&(obj->dTlsSessions[session]->Lock)); + ILibSpinLock_Lock(&(obj->dTlsSessions[session]->Lock)); } break; case 0x03: // WebRTC Data Channel Protocol: DATA_CHANNEL_OPEN @@ -3497,9 +3497,9 @@ void ILibStun_SctpProcessStreamData(struct ILibStun_Module *obj, int session, un ILibSparseArray_Add(obj->dTlsSessions[session]->DataChannelMetaDeta, streamId, attributes.Raw); ILibSparseArray_Add(obj->dTlsSessions[session]->DataChannelMetaDetaValues, streamId, attributesData.Raw); - sem_post(&(obj->dTlsSessions[session]->Lock)); + ILibSpinLock_UnLock(&(obj->dTlsSessions[session]->Lock)); if (obj->OnWebRTCDataChannel != NULL) { sendAck = obj->OnWebRTCDataChannel(obj, obj->dTlsSessions[session], streamId, data + 12, channelNameLength); } - sem_wait(&(obj->dTlsSessions[session]->Lock)); + ILibSpinLock_Lock(&(obj->dTlsSessions[session]->Lock)); if (sendAck == 0) { @@ -3519,10 +3519,10 @@ void ILibStun_SctpProcessStreamData(struct ILibStun_Module *obj, int session, un // This is a full data block if (obj->OnData != NULL && obj->dTlsSessions[session]->state == 2) { - sem_post(&(obj->dTlsSessions[session]->Lock)); + ILibSpinLock_UnLock(&(obj->dTlsSessions[session]->Lock)); obj->OnData(obj, obj->dTlsSessions[session], streamId, pid, data, datalen, &(obj->dTlsSessions[session]->User)); if (obj->dTlsSessions[session] == NULL || obj->dTlsSessions[session]->state != 2) return; - sem_wait(&(obj->dTlsSessions[session]->Lock)); + ILibSpinLock_Lock(&(obj->dTlsSessions[session]->Lock)); } // ILibStun_SctpSendData(obj, session, 0, pid, data, datalen); // ECHO } @@ -3557,10 +3557,10 @@ void ILibStun_SctpProcessStreamData(struct ILibStun_Module *obj, int session, un { if (obj->OnData != NULL && obj->dTlsSessions[session]->state == 2) { - sem_post(&(obj->dTlsSessions[session]->Lock)); + ILibSpinLock_UnLock(&(obj->dTlsSessions[session]->Lock)); obj->OnData(obj, obj->dTlsSessions[session], streamId, pid, acc->buffer, acc->bufferPtr, &(obj->dTlsSessions[session]->User)); if (obj->dTlsSessions[session] == NULL || obj->dTlsSessions[session]->state != 2) return; - sem_wait(&(obj->dTlsSessions[session]->Lock)); + ILibSpinLock_Lock(&(obj->dTlsSessions[session]->Lock)); } acc->bufferPtr = -1; } @@ -3595,7 +3595,7 @@ void ILibStun_SctpProcessStreamData(struct ILibStun_Module *obj, int session, un } } - sem_post(&(obj->dTlsSessions[session]->Lock)); + ILibSpinLock_UnLock(&(obj->dTlsSessions[session]->Lock)); } void ILibStun_SctpDisconnect_Final(void *obj) @@ -3646,8 +3646,7 @@ void ILibStun_SctpDisconnect_Final(void *obj) // Free the session o->state = 0; - sem_post(&(o->Lock)); - sem_destroy(&(o->Lock)); + ILibSpinLock_UnLock(&(o->Lock)); ILibRemoteLogging_printf(ILibChainGetLogger(o->Transport.ChainLink.ParentChain), ILibRemoteLogging_Modules_WebRTC_SCTP, ILibRemoteLogging_Flags_VerbosityLevel_1, "Cleaning up Dtls Session Object for session: %d", o->sessionId); ILibLifeTime_Remove(o->parent->Timer, ILibWebRTC_DTLS_TO_TIMER_OBJECT(o)); @@ -3669,16 +3668,16 @@ void ILibStun_SctpDisconnect_Continue(void *chain, void *j) ILibWebRTC_CloseDataChannel_ALL(o); - sem_wait(&(o->Lock)); - if (o->state < 1 || o->state > 2) { sem_post(&(o->Lock)); return; } + ILibSpinLock_Lock(&(o->Lock)); + if (o->state < 1 || o->state > 2) { ILibSpinLock_UnLock(&(o->Lock)); return; } // Send the event if (o->state == 2 && obj->OnConnect != NULL) { o->state = 3; - sem_post(&(o->Lock)); + ILibSpinLock_UnLock(&(o->Lock)); obj->OnConnect(obj, o, 0); - sem_wait(&(o->Lock)); + ILibSpinLock_Lock(&(o->Lock)); } else { @@ -3949,9 +3948,9 @@ void ILibStun_SctpResent(struct ILibStun_dTlsSession *obj) void ILibStun_SctpOnTimeout(void *object) { struct ILibStun_dTlsSession *obj = ILibWebRTC_DTLS_FROM_SCTP_HEARTBEAT_TIMER_OBJECT(object); - sem_wait(&(obj->Lock)); + ILibSpinLock_Lock(&(obj->Lock)); // printf("Timer state=%d, value=%d\r\n", obj->state, obj->timervalue); - if (obj->state < 1 || obj->state > 2) { sem_post(&(obj->Lock)); return; } // Check if we are still needed, connecting or connected state only. + if (obj->state < 1 || obj->state > 2) { ILibSpinLock_UnLock(&(obj->Lock)); return; } // Check if we are still needed, connecting or connected state only. obj->timervalue++; if (obj->timervalue < 80) @@ -3963,7 +3962,7 @@ void ILibStun_SctpOnTimeout(void *object) { // Close the connection printf("************************************\n"); - sem_post(&(obj->Lock)); + ILibSpinLock_UnLock(&(obj->Lock)); ILibRemoteLogging_printf(ILibChainGetLogger(obj->Transport.ChainLink.ParentChain), ILibRemoteLogging_Modules_WebRTC_SCTP, ILibRemoteLogging_Flags_VerbosityLevel_1, "SCTP Timeout on Session: %d", obj->sessionId); ILibStun_SctpDisconnect(obj->parent, obj->sessionId); return; @@ -3978,7 +3977,7 @@ void ILibStun_SctpOnTimeout(void *object) } ILibLifeTime_AddEx(obj->parent->Timer, ILibWebRTC_DTLS_TO_SCTP_HEARTBEAT_TIMER_OBJECT(obj), 100 + (200 * obj->timervalue), &ILibStun_SctpOnTimeout, NULL); - sem_post(&(obj->Lock)); + ILibSpinLock_UnLock(&(obj->Lock)); } int ILibSCTP_AddOptionalVariableParameter(char* insertionPoint, unsigned short parameterType, void *parameterData, int parameterDataLen) @@ -4266,10 +4265,10 @@ void ILibStun_ProcessSctpPacket(struct ILibStun_Module *obj, int session, char* ILibLifeTime_Add(obj->Timer, ILibWebRTC_DTLS_TO_CONSENT_FRESHNESS_TIMER_OBJECT(o), ILibStun_MaxConsentFreshnessTimeoutSeconds, ILibStun_WebRTC_ConsentFreshness_Start, NULL); } - sem_wait(&(o->Lock)); + ILibSpinLock_Lock(&(o->Lock)); // Decode the rest of the header - if (o->tag != ((unsigned int*)buffer)[1] && ((unsigned int*)buffer)[1] != 0) { sem_post(&(o->Lock)); return; } // Check the verification tag + if (o->tag != ((unsigned int*)buffer)[1] && ((unsigned int*)buffer)[1] != 0) { ILibSpinLock_UnLock(&(o->Lock)); return; } // Check the verification tag // Setup the response packet rptr = &(o->rpacketptr); @@ -4355,9 +4354,9 @@ void ILibStun_ProcessSctpPacket(struct ILibStun_Module *obj, int session, char* ILibSparseArray dup = ILibSparseArray_Move(o->DataChannelMetaDeta); ILibRemoteLogging_printf(ILibChainGetLogger(obj->ChainLink.ParentChain), ILibRemoteLogging_Modules_WebRTC_SCTP, ILibRemoteLogging_Flags_VerbosityLevel_1, "......Resetting all streams"); - sem_post(&(o->Lock)); + ILibSpinLock_UnLock(&(o->Lock)); ILibWebRTC_PropagateChannelCloseEx(dup, o); - sem_wait(&(o->Lock)); + ILibSpinLock_Lock(&(o->Lock)); } else { @@ -4375,10 +4374,10 @@ void ILibStun_ProcessSctpPacket(struct ILibStun_Module *obj, int session, char* ILibSparseArray_Remove(o->DataChannelMetaDetaValues, streamId); // Clear associated data with this stream ID if(obj->OnWebRTCDataChannelClosed != NULL) { - sem_post(&(o->Lock)); + ILibSpinLock_UnLock(&(o->Lock)); obj->OnWebRTCDataChannelClosed(obj, o, streamId); if (obj->dTlsSessions[session] == NULL) { return; } - sem_wait(&(o->Lock)); + ILibSpinLock_Lock(&(o->Lock)); } } else @@ -4497,9 +4496,9 @@ void ILibStun_ProcessSctpPacket(struct ILibStun_Module *obj, int session, char* ILibSparseArray_Remove(o->DataChannelMetaDetaValues, streamId); // Clear associated data with this stream ID if (obj->OnWebRTCDataChannelClosed != NULL) { - sem_post(&(o->Lock)); + ILibSpinLock_UnLock(&(o->Lock)); obj->OnWebRTCDataChannelClosed(obj, o, streamId); - sem_wait(&(o->Lock)); + ILibSpinLock_Lock(&(o->Lock)); } } outRequest->Streams[streamCount-1] = htons(streamId); @@ -4524,9 +4523,9 @@ void ILibStun_ProcessSctpPacket(struct ILibStun_Module *obj, int session, char* o->pendingReconfigPacket = NULL; // We need to shed the Lock before we call up the stack - sem_post(&(o->Lock)); + ILibSpinLock_UnLock(&(o->Lock)); ILibWebRTC_PropagateChannelCloseEx(arr, o); - sem_wait(&(o->Lock)); + ILibSpinLock_Lock(&(o->Lock)); } } } @@ -4552,10 +4551,10 @@ void ILibStun_ProcessSctpPacket(struct ILibStun_Module *obj, int session, char* if (obj->OnConnect != NULL && o->state == 1) { o->state = 2; - sem_post(&(o->Lock)); + ILibSpinLock_UnLock(&(o->Lock)); obj->OnConnect(obj, o, 1); if (obj->dTlsSessions[session] == NULL || obj->dTlsSessions[session]->state == 0) return; - sem_wait(&(o->Lock)); + ILibSpinLock_Lock(&(o->Lock)); } } case RCTP_CHUNK_TYPE_INITACK: @@ -4615,7 +4614,7 @@ void ILibStun_ProcessSctpPacket(struct ILibStun_Module *obj, int session, char* if (chunksize < 20 || session == -1 || o->state != 1) break; o->sessionId = session; o->tag = ((unsigned int*)(buffer + ptr + 4))[0]; - if (o->tag == 0) { sem_post(&(o->Lock)); return; } // This tag can't be zeroes + if (o->tag == 0) { ILibSpinLock_UnLock(&(o->Lock)); return; } // This tag can't be zeroes o->receiverCredits = ntohl(((unsigned int*)(buffer + ptr + 8))[0]); #if ILibSCTP_MaxSenderCredits > 0 if (o->receiverCredits > ILibSCTP_MaxSenderCredits) o->receiverCredits = ILibSCTP_MaxSenderCrtedits; // Since we do real-time KVM, reduce the buffering. @@ -5039,11 +5038,11 @@ void ILibStun_ProcessSctpPacket(struct ILibStun_Module *obj, int session, char* // If we can now send more packets, notify the application if (obj->OnSendOK != NULL && o->holdingCount == 0 && oldHoldCount > 0) { - sem_post(&(o->Lock)); + ILibSpinLock_UnLock(&(o->Lock)); // printf("SendOK\r\n"); obj->OnSendOK(obj, o, o->User); if (obj->dTlsSessions[session] == NULL || obj->dTlsSessions[session]->state != 2) return; - sem_wait(&(o->Lock)); + ILibSpinLock_Lock(&(o->Lock)); } } break; @@ -5064,7 +5063,7 @@ void ILibStun_ProcessSctpPacket(struct ILibStun_Module *obj, int session, char* { unsigned short len = ntohs(chunkHdr->chunkLength) - 4; unsigned short start = 0; - sem_post(&(o->Lock)); + ILibSpinLock_UnLock(&(o->Lock)); while(start < len) { @@ -5083,7 +5082,7 @@ void ILibStun_ProcessSctpPacket(struct ILibStun_Module *obj, int session, char* case RCTP_CHUNK_TYPE_SHUTDOWN: case RCTP_CHUNK_TYPE_SHUTDOWNACK: case RCTP_CHUNK_TYPE_ERROR: - sem_post(&(o->Lock)); + ILibSpinLock_UnLock(&(o->Lock)); ILibRemoteLogging_printf(ILibChainGetLogger(obj->ChainLink.ParentChain), ILibRemoteLogging_Modules_WebRTC_SCTP, ILibRemoteLogging_Flags_VerbosityLevel_1, "SCTP: %d received [SHUTDOWN/ERROR] (%u)", session, chunktype); ILibStun_SctpDisconnect(obj, session); return; @@ -5099,10 +5098,10 @@ void ILibStun_ProcessSctpPacket(struct ILibStun_Module *obj, int session, char* if (obj->OnConnect != NULL && o->state == 1) { o->state = 2; - sem_post(&(o->Lock)); + ILibSpinLock_UnLock(&(o->Lock)); obj->OnConnect(obj, o, 1); if (obj->dTlsSessions[session] == NULL || obj->dTlsSessions[session]->state == 0) return; - sem_wait(&(o->Lock)); + ILibSpinLock_Lock(&(o->Lock)); } break; case RCTP_CHUNK_TYPE_FWDTSN: @@ -5224,10 +5223,10 @@ void ILibStun_ProcessSctpPacket(struct ILibStun_Module *obj, int session, char* if ((chunkflags & ILibSCTP_UnorderedFlag) != ILibSCTP_UnorderedFlag || ((chunkflags & 0x03) != 0x03)) { // Only continue processing here, if 'Unordered Delivery' was not specified, or we have a partial fragment - sem_post(&(o->Lock)); + ILibSpinLock_UnLock(&(o->Lock)); ILibStun_SctpProcessStreamData(obj, session, streamId, streamSeq, chunkflags, pid, data->UserData, chunksize - 16); if (obj->dTlsSessions[session] == NULL || obj->dTlsSessions[session]->state == 0) return; - sem_wait(&(o->Lock)); + ILibSpinLock_Lock(&(o->Lock)); } // Pull as many packets as we can out of the receive hold queue @@ -5253,10 +5252,10 @@ void ILibStun_ProcessSctpPacket(struct ILibStun_Module *obj, int session, char* if (ILibSCTP_GetHoldingQueueFlags(ILibLinkedList_GetNode_Head(o->receiveHoldBuffer))->DataPropagated == 0) { // Only propagate this up, if it hasn't been propagated already - sem_post(&(o->Lock)); + ILibSpinLock_UnLock(&(o->Lock)); ILibStun_SctpProcessStreamData(obj, session, streamId, streamSeq, chunkflagsx, pid, payload->UserData, chunksizex - 16); if (obj->dTlsSessions[session] == NULL || obj->dTlsSessions[session]->state == 0) return; - sem_wait(&(o->Lock)); + ILibSpinLock_Lock(&(o->Lock)); } free(payload); @@ -5311,7 +5310,7 @@ void ILibStun_ProcessSctpPacket(struct ILibStun_Module *obj, int session, char* ILibRemoteLogging_printf(ILibChainGetLogger(obj->ChainLink.ParentChain), ILibRemoteLogging_Modules_WebRTC_SCTP, ILibRemoteLogging_Flags_VerbosityLevel_2, "...Buffer Index = %d", ptr); } ILibRemoteLogging_printf(ILibChainGetLogger(obj->ChainLink.ParentChain), ILibRemoteLogging_Modules_WebRTC_SCTP, ILibRemoteLogging_Flags_VerbosityLevel_1, "...Stopped Reading SCTP, rptr = %d", *rptr); - if (session == -1) { sem_post(&(o->Lock)); return; } + if (session == -1) { ILibSpinLock_UnLock(&(o->Lock)); return; } if (*rptr > 12) { #ifdef _REMOTELOGGING @@ -5325,7 +5324,7 @@ void ILibStun_ProcessSctpPacket(struct ILibStun_Module *obj, int session, char* ILibStun_SendSctpPacket(obj, session, rpacket, *rptr); } *rptr = 0; - sem_post(&(o->Lock)); + ILibSpinLock_UnLock(&(o->Lock)); } //! Pause processing of inbound SCTP data @@ -5337,9 +5336,9 @@ void ILibSCTP_Pause(void* sctpSession) struct ILibStun_dTlsSession* obj = (struct ILibStun_dTlsSession*)sctpSession; ILibRemoteLogging_printf(ILibChainGetLogger(obj->Transport.ChainLink.ParentChain), ILibRemoteLogging_Modules_WebRTC_SCTP, ILibRemoteLogging_Flags_VerbosityLevel_1, "SCTP: %d was PAUSED by the USER", obj->sessionId); - sem_wait(&(obj->Lock)); + ILibSpinLock_Lock(&(obj->Lock)); obj->flags |= DTLS_PAUSE_FLAG; - sem_post(&(obj->Lock)); + ILibSpinLock_UnLock(&(obj->Lock)); } //! Resume processing of inbound SCTP data /*! @@ -5356,7 +5355,7 @@ void ILibSCTP_Resume(void* sctpSession) ILibRemoteLogging_printf(ILibChainGetLogger(obj->Transport.ChainLink.ParentChain), ILibRemoteLogging_Modules_WebRTC_SCTP, ILibRemoteLogging_Flags_VerbosityLevel_1, "SCTP: %d RESUME operation begin", obj->sessionId); - sem_wait(&(obj->Lock)); + ILibSpinLock_Lock(&(obj->Lock)); if((obj->flags & DTLS_PAUSE_FLAG) == DTLS_PAUSE_FLAG) { obj->flags ^= DTLS_PAUSE_FLAG; @@ -5370,10 +5369,10 @@ void ILibSCTP_Resume(void* sctpSession) // This packet is the next expected packet for the user obj->userTSN = ntohl(payload->TSN); pulled += payload->length; - sem_post(&(obj->Lock)); + ILibSpinLock_UnLock(&(obj->Lock)); ILibStun_SctpProcessStreamData(obj->parent, obj->sessionId, ntohs(payload->StreamID), ntohs(payload->StreamSequenceNumber), payload->flags, ntohl(payload->ProtocolID), payload->UserData, ntohs(payload->length) - 16); if (sobj->dTlsSessions[sessionID] == NULL || sobj->dTlsSessions[sessionID]->state == 0) return; // Referencing Dtls object this way, in case it was closed/freed by the user in the last call - sem_wait(&(obj->Lock)); + ILibSpinLock_Lock(&(obj->Lock)); free(payload); ILibLinkedList_Remove(node); } @@ -5383,7 +5382,7 @@ void ILibSCTP_Resume(void* sctpSession) } } if (pulled > 0) ReceiveHoldBuffer_Decrement(obj->receiveHoldBuffer, pulled); - sem_post(&(obj->Lock)); + ILibSpinLock_UnLock(&(obj->Lock)); ILibRemoteLogging_printf(ILibChainGetLogger(obj->Transport.ChainLink.ParentChain), ILibRemoteLogging_Modules_WebRTC_SCTP, ILibRemoteLogging_Flags_VerbosityLevel_1, "SCTP: %d RESUME operation complete", sessionID); } @@ -5578,9 +5577,9 @@ ILibWebRTC_DataChannel_CloseStatus ILibWebRTC_CloseDataChannelEx(void *WebRTCMod struct ILibStun_dTlsSession* obj = (struct ILibStun_dTlsSession*)WebRTCModule; ILibWebRTC_DataChannel_CloseStatus retVal; - sem_wait(&obj->Lock); + ILibSpinLock_Lock(&obj->Lock); retVal = ILibWebRTC_CloseDataChannelEx2(WebRTCModule, streamIds, streamIdLength); - sem_post(&obj->Lock); + ILibSpinLock_UnLock(&obj->Lock); return retVal; } @@ -5630,7 +5629,6 @@ void ILibStun_CreateDtlsSession(struct ILibStun_Module *obj, int sessionId, int } else { - sem_destroy(&(obj->dTlsSessions[sessionId]->Lock)); ILibWebRTC_DestroySparseArrayTables(obj->dTlsSessions[sessionId]); memset(obj->dTlsSessions[sessionId], 0, sizeof(struct ILibStun_dTlsSession)); @@ -5650,7 +5648,7 @@ void ILibStun_CreateDtlsSession(struct ILibStun_Module *obj, int sessionId, int obj->dTlsSessions[sessionId]->iceStateSlot = iceSlot; obj->dTlsSessions[sessionId]->state = 4; // Bryan: Changed this to 4 from 1, because we need to call SSL_do_handshake to determine when DTLS was successful obj->dTlsSessions[sessionId]->sessionId = sessionId; - sem_init(&(obj->dTlsSessions[sessionId]->Lock), 0, 1); + ILibSpinLock_Init(&(obj->dTlsSessions[sessionId]->Lock)); obj->dTlsSessions[sessionId]->parent = obj; memcpy_s(obj->dTlsSessions[sessionId]->remoteInterface, sizeof(struct sockaddr_in6), remoteInterface, INET_SOCKADDR_LENGTH(remoteInterface->sin6_family)); obj->dTlsSessions[sessionId]->senderCredits = 4 * ILibRUDP_StartMTU; @@ -6057,7 +6055,7 @@ void ILibStun_OnUDP(ILibAsyncUDPSocket_SocketModule socketModule, char* buffer, // If we have an existing dTLS session, process the data. This can also happen right after we create the session above. if (existingSession != -1 && (obj->dTlsSessions[existingSession]->state == 1 || obj->dTlsSessions[existingSession]->state == 2 || obj->dTlsSessions[existingSession]->state == 4)) { - sem_wait(&(obj->dTlsSessions[existingSession]->Lock)); + ILibSpinLock_Lock(&(obj->dTlsSessions[existingSession]->Lock)); BIO_write(SSL_get_rbio(obj->dTlsSessions[existingSession]->ssl), buffer, bufferLength); if (obj->dTlsSessions[existingSession]->state == 4) { @@ -6088,12 +6086,12 @@ void ILibStun_OnUDP(ILibAsyncUDPSocket_SocketModule socketModule, char* buffer, // SSL_WANT_READ most likely, so do nothing for now break; } - sem_post(&(obj->dTlsSessions[existingSession]->Lock)); //ToDo: Bryan/Is this right? + ILibSpinLock_UnLock(&(obj->dTlsSessions[existingSession]->Lock)); //ToDo: Bryan/Is this right? } else { i = SSL_read(obj->dTlsSessions[existingSession]->ssl, tbuffer, 4096); - sem_post(&(obj->dTlsSessions[existingSession]->Lock)); + ILibSpinLock_UnLock(&(obj->dTlsSessions[existingSession]->Lock)); if (i > 0) { // We got new dTLS data @@ -6114,7 +6112,7 @@ void ILibStun_OnUDP(ILibAsyncUDPSocket_SocketModule socketModule, char* buffer, if (obj->dTlsSessions[existingSession] != NULL && obj->dTlsSessions[existingSession]->state != 0) { - sem_wait(&(obj->dTlsSessions[existingSession]->Lock)); + ILibSpinLock_Lock(&(obj->dTlsSessions[existingSession]->Lock)); if(obj->dTlsSessions[existingSession]->writeBIOBuffer->length > 0) { BIO_clear_retry_flags(obj->dTlsSessions[existingSession]->writeBIO); // Klocwork reports this could block, but this is a memory bio, so it will never block. @@ -6140,7 +6138,7 @@ void ILibStun_OnUDP(ILibAsyncUDPSocket_SocketModule socketModule, char* buffer, if(obj->dTlsSessions[existingSession]->state == 4) {ILibWebRTC_DTLS_HandshakeDetect(obj, "S ", obj->dTlsSessions[existingSession]->writeBIOBuffer->data, 0, (int)obj->dTlsSessions[existingSession]->writeBIOBuffer->length);} ignore_result(BIO_reset(obj->dTlsSessions[existingSession]->writeBIO)); } - sem_post(&(obj->dTlsSessions[existingSession]->Lock)); + ILibSpinLock_UnLock(&(obj->dTlsSessions[existingSession]->Lock)); } } } diff --git a/microstack/ILibWebServer.c b/microstack/ILibWebServer.c index c33d044..62589e1 100644 --- a/microstack/ILibWebServer.c +++ b/microstack/ILibWebServer.c @@ -102,7 +102,7 @@ typedef struct ILibWebServer_Session_SystemData int CloseOverrideFlag; // Close Override Flag void *DisconnectFlagPointer; // DisconnectFlagPointer - sem_t SessionLock; // Session Lock + ILibSpinLock SessionLock; // Session Lock int ReferenceCounter; // Reference Counter; int OverrideVirDirStruct; // Override VirDir Struct @@ -467,7 +467,7 @@ void ILibWebServer_OnConnect(void *AsyncServerSocketModule, void *ConnectionToke ws->Reserved_Transport.PendingBytesPtr = (ILibTransport_PendingBytesToSendPtr)&ILibWebServer_Session_GetPendingBytesToSend; ws->ParentExtraMemory = wsm->ChainLink.ExtraMemoryPtr; - sem_init(&(ILibWebServer_Session_GetSystemData(ws)->SessionLock), 0, 1); // Initialize the SessionLock + ILibSpinLock_Init(&(ILibWebServer_Session_GetSystemData(ws)->SessionLock)); // Initialize the SessionLock ILibWebServer_Session_GetSystemData(ws)->ReferenceCounter = 1; // Reference Counter, Initial count should be 1 ILibWebServer_Session_GetSystemData(ws)->AsyncServerSocket = AsyncServerSocketModule; ILibWebServer_Session_GetSystemData(ws)->ConnectionToken = ConnectionToken; @@ -475,7 +475,7 @@ void ILibWebServer_OnConnect(void *AsyncServerSocketModule, void *ConnectionToke //printf("#### ALLOCATED (%d) ####\r\n", ConnectionToken); - sem_init(&(ILibWebServer_Session_GetSystemData(ws)->SessionLock), 0, 1); // Initialize the SessionLock + ILibSpinLock_Init(&(ILibWebServer_Session_GetSystemData(ws)->SessionLock)); // Initialize the SessionLock ws->Parent = wsm; ws->User = wsm->User; *user = ws; @@ -691,9 +691,9 @@ int ILibWebServer_ProcessWebSocketData(struct ILibWebServer_Session *ws, char* b { int sendResponse = 0; // CONNECTION-CLOSE - sem_wait(&(ILibWebServer_Session_GetSystemData(ws)->SessionLock)); + ILibSpinLock_Lock(&(ILibWebServer_Session_GetSystemData(ws)->SessionLock)); if (ILibWebServer_Session_GetSystemData(ws)->WebSocketCloseFrameSent == 0) { ILibWebServer_Session_GetSystemData(ws)->WebSocketCloseFrameSent = 1; sendResponse = 1; } - sem_post(&(ILibWebServer_Session_GetSystemData(ws)->SessionLock)); + ILibSpinLock_UnLock(&(ILibWebServer_Session_GetSystemData(ws)->SessionLock)); if (sendResponse != 0) { @@ -725,9 +725,9 @@ ILibExportMethod void ILibWebServer_WebSocket_Close(struct ILibWebServer_Session int sent = 0; unsigned short code = htons(1000); // Normal Closure - sem_wait(&(ILibWebServer_Session_GetSystemData(ws)->SessionLock)); + ILibSpinLock_Lock(&(ILibWebServer_Session_GetSystemData(ws)->SessionLock)); if (ILibWebServer_Session_GetSystemData(ws)->WebSocketCloseFrameSent == 0) { ILibWebServer_Session_GetSystemData(ws)->WebSocketCloseFrameSent = 1; sent = 1; } - sem_post(&(ILibWebServer_Session_GetSystemData(ws)->SessionLock)); + ILibSpinLock_UnLock(&(ILibWebServer_Session_GetSystemData(ws)->SessionLock)); if (sent != 0) { @@ -1539,13 +1539,13 @@ ILibExportMethod enum ILibWebServer_Status ILibWebServer_WebSocket_Send(struct I } } - sem_wait(&(ILibWebServer_Session_GetSystemData(session)->SessionLock)); // We need to do this, because we need to be able to correctly interleave sends + ILibSpinLock_Lock(&(ILibWebServer_Session_GetSystemData(session)->SessionLock)); // We need to do this, because we need to be able to correctly interleave sends RetVal = (enum ILibWebServer_Status)ILibAsyncServerSocket_Send(ILibWebServer_Session_GetSystemData(session)->AsyncServerSocket, ILibWebServer_Session_GetSystemData(session)->ConnectionToken, header, headerLen, ILibAsyncSocket_MemoryOwnership_USER); if (bufferLen > 0) { RetVal = (enum ILibWebServer_Status)ILibAsyncServerSocket_Send(ILibWebServer_Session_GetSystemData(session)->AsyncServerSocket, ILibWebServer_Session_GetSystemData(session)->ConnectionToken, buffer, bufferLen, userFree); } - sem_post(&(ILibWebServer_Session_GetSystemData(session)->SessionLock)); + ILibSpinLock_UnLock(&(ILibWebServer_Session_GetSystemData(session)->SessionLock)); return RetVal; } @@ -2018,9 +2018,9 @@ void ILibWebServer_AddRef(struct ILibWebServer_Session *session) { SESSION_TRACK(session, "AddRef"); - sem_wait(&(ILibWebServer_Session_GetSystemData(session)->SessionLock)); + ILibSpinLock_Lock(&(ILibWebServer_Session_GetSystemData(session)->SessionLock)); ++ILibWebServer_Session_GetSystemData(session)->ReferenceCounter; - sem_post(&(ILibWebServer_Session_GetSystemData(session)->SessionLock)); + ILibSpinLock_UnLock(&(ILibWebServer_Session_GetSystemData(session)->SessionLock)); } /*! \fn ILibWebServer_Release(struct ILibWebServer_Session *session) @@ -2034,7 +2034,7 @@ void ILibWebServer_Release(struct ILibWebServer_Session *session) int OkToFree = 0; SESSION_TRACK(session, "Release"); - sem_wait(&(ILibWebServer_Session_GetSystemData(session)->SessionLock)); + ILibSpinLock_Lock(&(ILibWebServer_Session_GetSystemData(session)->SessionLock)); if (--ILibWebServer_Session_GetSystemData(session)->ReferenceCounter == 0) { // @@ -2043,7 +2043,7 @@ void ILibWebServer_Release(struct ILibWebServer_Session *session) // OkToFree = 1; } - sem_post(&(ILibWebServer_Session_GetSystemData(session)->SessionLock)); + ILibSpinLock_UnLock(&(ILibWebServer_Session_GetSystemData(session)->SessionLock)); if (session->SessionInterrupted == 0) { ILibLifeTime_Remove(((struct ILibWebServer_StateModule*)session->Parent)->LifeTime, session); @@ -2056,7 +2056,6 @@ void ILibWebServer_Release(struct ILibWebServer_Session *session) ILibWebClient_DestroyWebClientDataObject(ILibWebServer_Session_GetSystemData(session)->WebClientDataObject); } SESSION_TRACK(session, "** Destroyed **"); - sem_destroy(&(ILibWebServer_Session_GetSystemData(session)->SessionLock)); if (ILibWebServer_Session_GetSystemData(session)->DigestTable != NULL) { ILibDestroyHashTree(ILibWebServer_Session_GetSystemData(session)->DigestTable); } if (ILibWebServer_Session_GetSystemData(session)->WebSocketFragmentBuffer != NULL) { free(ILibWebServer_Session_GetSystemData(session)->WebSocketFragmentBuffer); } if (ILibWebServer_Session_GetSystemData(session)->WebSocket_Request != NULL) { ILibDestructPacket((struct packetheader*)ILibWebServer_Session_GetSystemData(session)->WebSocket_Request); }