/** * initialize the directory package. * * @param[in] abuffers size of directory buffer cache * * @return operation status * @retval 0 success */ int DInit(int abuffers) { /* Initialize the venus buffer system. */ int i, tsize; struct buffer *tb; char *tp; Lock_Init(&afs_bufferLock); /* Align each element of Buffers on a doubleword boundary */ tsize = (sizeof(struct buffer) + 7) & ~7; tp = (char *)malloc(abuffers * tsize); Buffers = (struct buffer **)malloc(abuffers * sizeof(struct buffer *)); BufferData = (char *)malloc(abuffers * BUFFER_PAGE_SIZE); timecounter = 0; LastBuffer = (struct buffer *)tp; nbuffers = abuffers; for (i = 0; i < PHSIZE; i++) phTable[i] = 0; for (i = 0; i < abuffers; i++) { /* Fill in each buffer with an empty indication. */ tb = (struct buffer *)tp; Buffers[i] = tb; tp += tsize; FidZero(tb->fid); tb->accesstime = tb->lockers = 0; tb->data = &BufferData[BUFFER_PAGE_SIZE * i]; tb->hashIndex = 0; tb->dirty = 0; Lock_Init(&tb->lock); } return 0; }
void initStatus(void) { dlqInit(&statusHead); Lock_Init(&statusQueueLock); Lock_Init(&cmdLineLock); }
static EXPECTED_SEND_DATA* EventData_Create(void) { EXPECTED_SEND_DATA* result = (EXPECTED_SEND_DATA*)malloc(sizeof(EXPECTED_SEND_DATA)); if (result != NULL) { if ((result->lock = Lock_Init()) == NULL) { ASSERT_FAIL("unable to Lock_Init"); } else { char temp[1000]; char* tempString; time_t t = time(NULL); sprintf(temp, TEST_EVENT_DATA_FMT, ctime(&t), g_iotHubTestId); if ((tempString = (char*)malloc(strlen(temp) + 1)) == NULL) { Lock_Deinit(result->lock); free(result); result = NULL; } else { strcpy(tempString, temp); result->expectedString = tempString; result->wasFound = false; result->dataWasRecv = false; } } } return result; }
int gbnetwork_init(void) { int result; if (gbnetworkState != GBNETWORK_STATE_NOT_INIT) { result = __FAILURE__; } else if ((gbnetworkThreadSafeLock = Lock_Init()) == NULL) { result = __FAILURE__; } else { gbnetworkState = GBNETWORK_STATE_INIT; g_send_bytes = 0; g_send_number = 0; g_recv_bytes = 0; g_recv_number = 0; result = 0; } return result; }
static void ObtainLock(struct Lock *lock, char type) { PROCESS pid; assert(LWP_CurrentProcess(&pid) == 0); if (!lock->initialized) Lock_Init(lock); lwp_LEAVE(pid); lwp_mutex_lock(&lock->_access); { /* now start waiting, writers wait until all readers have left, all * lockers wait for the excl flag to be cleared */ /* this is a safe cancellation point because we (should) only hold * the access mutex, and we take ourselves off the pending list in the * cleanup handler */ while (lock->excl || (type == 'W' && lock->readers)) pthread_cond_wait(&lock->wakeup, &lock->_access); /* Obtain the correct lock flags, read locks increment readers, write * locks set the excl flag and shared locks do both */ if (type != 'R') lock->excl = pid; if (type != 'W') lock->readers++; /* signal other threads, there might be more readers */ if (type == 'R') pthread_cond_broadcast(&lock->wakeup); lwp_dbg(LWP_DBG_LOCKS, "%c+ pid %p lock %p\n", type, pid, lock); } lwp_mutex_unlock(&lock->_access); lwp_YIELD(pid); }
static PHYSICAL_DEVICE* physical_device_new(thingie_t *iot_device) { PHYSICAL_DEVICE *retValue = malloc(sizeof(PHYSICAL_DEVICE)); if (retValue == NULL) { LogError("failed to allocate memory for physical device structure"); } else { retValue->status_lock = Lock_Init(); if (retValue->status_lock == NULL) { LogError("failed to create a lock"); free(retValue); retValue = NULL; } else { retValue->iot_device = iot_device; retValue->status = waiting; retValue->new_firmware_URI = NULL; } } return retValue; }
static EXPECTED_SEND_DATA* SendTestData_Create(void) { EXPECTED_SEND_DATA* result = (EXPECTED_SEND_DATA*)malloc(sizeof(EXPECTED_SEND_DATA)); if (result != NULL) { if ((result->lock = Lock_Init()) == NULL) { free(result); result = NULL; } else { char temp[1000]; char* tempString; time_t t = time(NULL); sprintf(temp, TEST_SEND_DATA_FMT, ctime(&t), g_uniqueTestId); if ((tempString = (char*)malloc(strlen(temp) + 1)) == NULL) { Lock_Deinit(result->lock); free(result); result = NULL; } else { strcpy(tempString, temp); result->expectedString = tempString; result->wasFound = false; result->dataWasSent = false; } } } return result; }
int gballoc_init(void) { int result; if (gballocState != GBALLOC_STATE_NOT_INIT) { /* Codes_SRS_GBALLOC_01_025: [Init after Init shall fail and return a non-zero value.] */ result = __LINE__; } /* Codes_SRS_GBALLOC_01_026: [gballoc_Init shall create a lock handle that will be used to make the other gballoc APIs thread-safe.] */ else if ((gballocThreadSafeLock = Lock_Init()) == NULL) { /* Codes_SRS_GBALLOC_01_027: [If the Lock creation fails, gballoc_init shall return a non-zero value.]*/ result = __LINE__; } else { gballocState = GBALLOC_STATE_INIT; /* Codes_ SRS_GBALLOC_01_002: [Upon initialization the total memory used and maximum total memory used tracked by the module shall be set to 0.] */ totalSize = 0; maxSize = 0; /* Codes_SRS_GBALLOC_01_024: [gballoc_init shall initialize the gballoc module and return 0 upon success.] */ result = 0; } return result; }
static EXPECTED_SEND_DATA* SendMacroTestData_Create(const char* pszTime) { EXPECTED_SEND_DATA* result = (EXPECTED_SEND_DATA*)malloc(sizeof(EXPECTED_SEND_DATA)); if (result != NULL) { if ((result->lock = Lock_Init()) == NULL) { free(result); result = NULL; } else { char temp[1000]; char* tempString; sprintf(temp, TEST_MACRO_CMP_DATA_FMT, g_uniqueTestId, pszTime); if ((tempString = (char*)malloc(strlen(temp) + 1)) == NULL) { Lock_Deinit(result->lock); free(result); result = NULL; } else { strcpy(tempString, temp); result->expectedString = tempString; result->wasFound = false; result->dataWasSent = false; } } } return result; }
static EXPECTED_RECEIVE_DATA* MessageData_Create(void) { EXPECTED_RECEIVE_DATA* result = (EXPECTED_RECEIVE_DATA*)malloc(sizeof(EXPECTED_RECEIVE_DATA)); if (result != NULL) { if ((result->lock = Lock_Init()) == NULL) { free(result); result = NULL; } else { char temp[1000]; char* tempString; time_t t = time(NULL); sprintf(temp, TEST_MESSAGE_DATA_FMT, ctime(&t), g_iotHubTestId); if ((tempString = (char*)malloc(strlen(temp) + 1)) == NULL) { (void)Lock_Deinit(result->lock); free(result); result = NULL; } else { strcpy(tempString, temp); result->data = tempString; result->dataSize = strlen(result->data); result->wasFound = false; result->toBeSend = (const unsigned char*)tempString; result->toBeSendSize = strlen(tempString); } } } return result; }
static void deadlock_read2 (void) { struct Lock lock; Lock_Init (&lock); ObtainReadLock(&lock); ObtainWriteLock(&lock); }
static void deadlock_write (void) { struct Lock lock; Lock_Init (&lock); ObtainWriteLock(&lock); ObtainWriteLock(&lock); }
static BROKER_RESULT init_module(BROKER_MODULEINFO* module_info, const MODULE* module) { BROKER_RESULT result; /*Codes_SRS_BROKER_13_107: The function shall assign the `module` handle to `BROKER_MODULEINFO::module`.*/ module_info->module = (MODULE*)malloc(sizeof(MODULE)); if (module_info->module == NULL) { LogError("Allocate module failed"); result = BROKER_ERROR; } else { module_info->module->module_apis = module->module_apis; module_info->module->module_handle = module->module_handle; /*Codes_SRS_BROKER_13_099: [The function shall initialize BROKER_MODULEINFO::socket_lock with a valid lock handle.]*/ module_info->socket_lock = Lock_Init(); if (module_info->socket_lock == NULL) { /*Codes_SRS_BROKER_13_047: [ This function shall return BROKER_ERROR if an underlying API call to the platform causes an error or BROKER_OK otherwise. ]*/ LogError("Lock_Init for socket lock failed"); result = BROKER_ERROR; } else { char uuid[BROKER_GUID_SIZE]; memset(uuid, 0, BROKER_GUID_SIZE); /*Codes_SRS_BROKER_17_020: [ The function shall create a unique ID used as a quit signal. ]*/ if (UniqueId_Generate(uuid, BROKER_GUID_SIZE) != UNIQUEID_OK) { /*Codes_SRS_BROKER_13_047: [ This function shall return BROKER_ERROR if an underlying API call to the platform causes an error or BROKER_OK otherwise. ]*/ LogError("Lock_Init for socket lock failed"); Lock_Deinit(module_info->socket_lock); result = BROKER_ERROR; } else { module_info->quit_message_guid = STRING_construct(uuid); if (module_info->quit_message_guid == NULL) { /*Codes_SRS_BROKER_13_047: [ This function shall return BROKER_ERROR if an underlying API call to the platform causes an error or BROKER_OK otherwise. ]*/ LogError("String construct failed for module guid"); Lock_Deinit(module_info->socket_lock); result = BROKER_ERROR; } else { result = BROKER_OK; } } } } return result; }
/** * initialize a struct VDiskLock. * * @param[in] dl struct VDiskLock to initialize * @param[in] lf the struct VLockFile to associate with this disk lock */ void VDiskLockInit(struct VDiskLock *dl, struct VLockFile *lf, afs_uint32 offset) { assert(lf); memset(dl, 0, sizeof(*dl)); Lock_Init(&dl->rwlock); assert(pthread_mutex_init(&dl->mutex, NULL) == 0); assert(pthread_cond_init(&dl->cv, NULL) == 0); dl->lockfile = lf; dl->offset = offset; }
IOTHUB_MESSAGING_CLIENT_HANDLE IoTHubMessaging_Create(IOTHUB_SERVICE_CLIENT_AUTH_HANDLE serviceClientHandle) { IOTHUB_MESSAGING_CLIENT_INSTANCE* result; /*Codes_SRS_IOTHUBMESSAGING_12_001: [ IoTHubMessaging_Create shall verify the serviceClientHandle input parameter and if it is NULL then return NULL. ]*/ if (serviceClientHandle == NULL) { LogError("serviceClientHandle input parameter cannot be NULL"); result = NULL; } else { /*Codes_SRS_IOTHUBMESSAGING_12_002: [ IoTHubMessaging_Create shall allocate a new IoTHubMessagingClient instance. ]*/ if ((result = (IOTHUB_MESSAGING_CLIENT_INSTANCE*)malloc(sizeof(IOTHUB_MESSAGING_CLIENT_INSTANCE))) == NULL) { /*Codes_SRS_IOTHUBMESSAGING_12_003: [If allocating memory for the new IoTHubMessagingClient instance fails, then IoTHubMessaging_Create shall return NULL. ]*/ LogError("malloc failed for IoTHubMessagingClient"); result = NULL; } else { /*Codes_SRS_IOTHUBMESSAGING_12_004: [IoTHubMessaging_Create shall create a lock object to be used later for serializing IoTHubMessagingClient calls. ]*/ result->LockHandle = Lock_Init(); if (result->LockHandle == NULL) { /*Codes_SRS_IOTHUBMESSAGING_12_005: [If creating the lock fails, then IoTHubMessaging_Create shall return NULL. ]*/ /*Codes_SRS_IOTHUBMESSAGING_12_008: [If IoTHubMessaging_Create fails, all resources allocated by it shall be freed. ]*/ LogError("Lock_Init failed"); free(result); result = NULL; } else { /*Codes_SRS_IOTHUBMESSAGING_12_006: [IoTHubMessaging_Create shall instantiate a new IoTHubMessaging_LL instance by calling IoTHubMessaging_LL_Create and passing the serviceClientHandle argument. ]*/ result->IoTHubMessagingHandle = IoTHubMessaging_LL_Create(serviceClientHandle); if (result->IoTHubMessagingHandle == NULL) { /*Codes_SRS_IOTHUBMESSAGING_12_007: [ If IoTHubMessaging_LL_Create fails, then IoTHubMessaging_Create shall return NULL. ]*/ /*Codes_SRS_IOTHUBMESSAGING_12_008: [If IoTHubMessaging_Create fails, all resources allocated by it shall be freed. ]*/ LogError("IoTHubMessaging_LL_Create failed"); Lock_Deinit(result->LockHandle); free(result); result = NULL; } else { result->StopThread = 0; result->ThreadHandle = NULL; } } } } return (IOTHUB_MESSAGING_CLIENT_HANDLE)result; }
/** * initialize a struct VDiskLock. * * @param[in] dl struct VDiskLock to initialize * @param[in] lf the struct VLockFile to associate with this disk lock */ void VDiskLockInit(struct VDiskLock *dl, struct VLockFile *lf, afs_uint32 offset) { osi_Assert(lf); memset(dl, 0, sizeof(*dl)); Lock_Init(&dl->rwlock); MUTEX_INIT(&dl->mutex, "disklock", MUTEX_DEFAULT, 0); CV_INIT(&dl->cv, "disklock cv", CV_DEFAULT, 0); dl->lockfile = lf; dl->offset = offset; }
/** * initialize a struct VDiskLock. * * @param[in] dl struct VDiskLock to initialize * @param[in] lf the struct VLockFile to associate with this disk lock */ void VDiskLockInit(struct VDiskLock *dl, struct VLockFile *lf, afs_uint32 offset) { opr_Assert(lf); memset(dl, 0, sizeof(*dl)); Lock_Init(&dl->rwlock); opr_mutex_init(&dl->mutex); opr_cv_init(&dl->cv); dl->lockfile = lf; dl->offset = offset; }
TNetWork *net_Create(int _iType) { TNetWorkMsg *ptNetWorkMsg = (TNetWorkMsg *)malloc(sizeof(TNetWorkMsg)); if(NULL == ptNetWorkMsg) { dbg(); return NULL; } Lock_Init(ptNetWorkMsg->m_SendMux); Lock_Init(ptNetWorkMsg->m_RecvMux); ptNetWorkMsg->m_iType = _iType; ptNetWorkMsg->m_iSocket = INVALID_SOCKET; ptNetWorkMsg->m_pcIp[0] = 0; ptNetWorkMsg->m_iPort = -1; return (TNetWork *)ptNetWorkMsg; }
TNetWork *net_CreateByIp(int _iType, const char *_pcIp, int _iPort) { TNetWorkMsg *ptNetWorkMsg = (TNetWorkMsg *)malloc(sizeof(TNetWorkMsg)); if(NULL == ptNetWorkMsg) { dbg(); return NULL; } Lock_Init(ptNetWorkMsg->m_SendMux); Lock_Init(ptNetWorkMsg->m_RecvMux); ptNetWorkMsg->m_iType = _iType; ptNetWorkMsg->m_iSocket = INVALID_SOCKET; strncpy(ptNetWorkMsg->m_pcIp, _pcIp, MAX_IP_LEN); ptNetWorkMsg->m_iPort = _iPort; return (TNetWork *)ptNetWorkMsg; }
static EXPECTED_RECEIVE_DATA* MessageData_Create(void) { EXPECTED_RECEIVE_DATA* result; time_t t; if ((t = time(NULL)) == INDEFINITE_TIME) { LogError("Failed creating data for EXPECTED_RECEIVE_DATA (time(NULL) failed)"); result = NULL; } else { if ((result = (EXPECTED_RECEIVE_DATA*)malloc(sizeof(EXPECTED_RECEIVE_DATA))) == NULL) { LogError("MessageData_Create failed (malloc failure)"); } else { if ((result->lock = Lock_Init()) == NULL) { LogError("Failed initializing lock on MessageData_Create()."); free(result); result = NULL; } else { char temp[1000]; char* tempString; sprintf(temp, TEST_MESSAGE_DATA_FMT, ctime(&t), g_iotHubTestId); if ((tempString = (char*)malloc(strlen(temp) + 1)) == NULL) { LogError("Failed allocating memory to create EXPECTED_RECEIVE_DATA"); (void)Lock_Deinit(result->lock); free(result); result = NULL; } else { strcpy(tempString, temp); result->data = tempString; result->dataSize = strlen(result->data); result->receivedByClient = false; result->data = (const char*)tempString; result->dataSize = strlen(tempString); } } } } return result; }
ds_safeq_t * ds_safeq_create() { ds_safeq_t *result; ALLOC(result,ds_safeq_t); result->sq_magic = ds_safeq_magic; Lock_Init(&result->sq_lock); result->sq_list = ds_list_create(NULL, FALSE, TRUE); CODA_ASSERT(result->sq_list); return result; }
bbuf::bbuf(int bound, int lfm) { head = 0; tail = 0; count = 0; bnd = bound; low_fuel_mark = lfm; buf = new bbuf_item[bound]; low_fuel = new (char); // set valid addresses to the conditions; full_tank = new (char); Lock_Init(&lock); // initialize the lock; dbg = mfalse; }
static EXPECTED_RECEIVE_DATA* ReceiveUserContext_Create(void) { EXPECTED_RECEIVE_DATA* result = (EXPECTED_RECEIVE_DATA*)malloc(sizeof(EXPECTED_RECEIVE_DATA)); if (result != NULL) { result->wasFound = false; if ((result->lock = Lock_Init()) == NULL) { free(result); result = NULL; } } return result; }
void PC_Init(PC *pc, int cap, int maxColor) { Lock_Init(&pc->lock); Cond_Init(&pc->spaceAvail, &pc->lock); Cond_Init(&pc->stuffAvail, &pc->lock); List_Init(&(pc->list)); pc->capacity = cap; pc->used = 0; pc->maxColor = maxColor; pc->waitingP = 0; pc->waitingC = 0; return; }
static EXPECTED_RECEIVE_DATA* RecvTestData_Create(void) { EXPECTED_RECEIVE_DATA* result; result = (EXPECTED_RECEIVE_DATA*)malloc(sizeof(EXPECTED_RECEIVE_DATA)); if (result != NULL) { if ((result->lock = Lock_Init()) == NULL) { free(result); result = NULL; } else { char temp[1000]; char* tempString; result->wasFound = false; time_t t = time(NULL); (void)sprintf_s(temp, sizeof(temp), TEST_CMP_DATA_FMT, ctime(&t), g_uniqueTestId); result->compareDataSize = strlen(temp); tempString = (char*)malloc(result->compareDataSize+1); if (tempString == NULL) { (void)Lock_Deinit(result->lock); free(result); result = NULL; } else { strcpy(tempString, temp); result->compareData = tempString; (void)sprintf_s(temp, sizeof(temp), TEST_RECV_DATA_FMT, ctime(&t), g_uniqueTestId); tempString = (char*)malloc(strlen(temp) + 1); if (tempString == NULL) { (void)Lock_Deinit(result->lock); free((void*)result->compareData); free(result); result = NULL; } else { strcpy(tempString, temp); result->toBeSendSize = strlen(tempString); result->toBeSend = tempString; } } } } return result; }
static EXPECTED_SEND_DATA* EventData_Create(void) { EXPECTED_SEND_DATA* result; time_t t; if ((t = time(NULL)) == INDEFINITE_TIME) { LogError("Failed creating data for EXPECTED_SEND_DATA (time(NULL) failed)"); result = NULL; } else { if ((result = (EXPECTED_SEND_DATA*)malloc(sizeof(EXPECTED_SEND_DATA))) == NULL) { LogError("EventData_Create failed (malloc failure)"); } else { if ((result->lock = Lock_Init()) == NULL) { LogError("Unable to Lock_Init"); } else { char temp[1000]; char* tempString; sprintf(temp, TEST_EVENT_DATA_FMT, ctime(&t), g_iotHubTestId); if ((tempString = (char*)malloc(strlen(temp) + 1)) == NULL) { Lock_Deinit(result->lock); free(result); result = NULL; } else { strcpy(tempString, temp); result->expectedString = tempString; result->wasFoundInHub = false; result->dataWasSent = false; result->timeSent = 0; result->timeReceived = 0; } } } } return result; }
static EXPECTED_RECEIVE_DATA* RecvMacroTestData_Create(void) { EXPECTED_RECEIVE_DATA* result; result = (EXPECTED_RECEIVE_DATA*)malloc(sizeof(EXPECTED_RECEIVE_DATA)); if (result != NULL) { if ((result->lock = Lock_Init()) == NULL) { free(result); result = NULL; } else { char* tempString; result->wasFound = false; tempString = (char*)malloc(TIME_DATA_LENGTH); if (tempString == NULL) { (void)Lock_Deinit(result->lock); free(result); result = NULL; } else { time_t t = time(NULL); (void)sprintf_s(tempString, TIME_DATA_LENGTH, "%.24s", ctime(&t) ); result->compareData = tempString; result->compareDataSize = strlen(result->compareData); size_t nLen = result->compareDataSize+strlen(TEST_MACRO_RECV_DATA_FMT)+4; tempString = (char*)malloc(nLen); if (tempString == NULL) { (void)Lock_Deinit(result->lock); free((void*)result->compareData); free(result); result = NULL; } else { (void)sprintf_s(tempString, nLen, TEST_MACRO_RECV_DATA_FMT, result->compareData, g_uniqueTestId); result->toBeSendSize = strlen(tempString); result->toBeSend = tempString; } } } } return result; }
void init_kadatabase(int initFlags) { Lock_Init(&keycache_lock); maxCachedKeys = 10; keyCache = malloc(maxCachedKeys * sizeof(struct cachedKey)); keyCacheVersion = 0; if (initFlags & 4) { maxKeyLifetime = 90; } else { maxKeyLifetime = MAXKTCTICKETLIFETIME; } if (initFlags & 8) dbfixup++; }
/* afs_InitCBQueue * called to initialize static and global variables associated with * the Callback expiration management mechanism. */ void afs_InitCBQueue(int doLockInit) { register int i; memset((char *)cbHashT, 0, CBHTSIZE * sizeof(struct bucket)); for (i = 0; i < CBHTSIZE; i++) { QInit(&(cbHashT[i].head)); /* Lock_Init(&(cbHashT[i].lock)); only if you want lots of locks, which * don't seem too useful at present. */ } base = 0; basetime = osi_Time(); if (doLockInit) Lock_Init(&afs_xcbhash); }
int ProxyGateway_StartWorkerThread ( REMOTE_MODULE_HANDLE remote_module ) { int result; if (NULL == remote_module) { /* Codes_SRS_PROXY_GATEWAY_027_017: [Prerequisite Check - If the `remote_module` parameter is `NULL`, then `ProxyGateway_StartWorkerThread` shall do nothing and return a non-zero value] */ LogError("%s: NULL parameter - remote_module!", __FUNCTION__); result = __LINE__; } else if (NULL != remote_module->message_thread) { /* Codes_SRS_PROXY_GATEWAY_027_018: [Prerequisite Check - If a work thread already exist for the given handle, then `ProxyGateway_StartWorkerThread` shall do nothing and return zero] */ LogInfo("%s: Worker thread has already been initialized.", __FUNCTION__); result = 0; /* Codes_SRS_PROXY_GATEWAY_027_019: [`ProxyGateway_StartWorkerThread` shall allocate the memory required to support the worker thread] */ } else if (NULL == (remote_module->message_thread = (MESSAGE_THREAD_HANDLE)calloc(1, sizeof(MESSAGE_THREAD)))) { /* Codes_SRS_PROXY_GATEWAY_027_020: [If memory allocation fails for the worker thread data, then `ProxyGateway_StartWorkerThread` shall return a non-zero value] */ LogError("%s: Unable to allocate memory!", __FUNCTION__); result = __LINE__; /* Codes_SRS_PROXY_GATEWAY_027_021: [`ProxyGateway_StartWorkerThread` shall create a mutex by calling `LOCK_HANDLE Lock_Init(void)`] */ } else if (NULL == (remote_module->message_thread->mutex = Lock_Init())) { /* Codes_SRS_PROXY_GATEWAY_027_022: [If a mutex is unable to be created, then `ProxyGateway_StartWorkerThread` shall free any previously allocated memory and return a non-zero value] */ LogError("%s: Unable to create mutex!", __FUNCTION__); result = __LINE__; free(remote_module->message_thread); remote_module->message_thread = (MESSAGE_THREAD_HANDLE)NULL; /* Codes_SRS_PROXY_GATEWAY_027_023: [`ProxyGateway_StartWorkerThread` shall start a worker thread by calling `THREADAPI_RESULT ThreadAPI_Create(&THREAD_HANDLE threadHandle, THREAD_START_FUNC func, void * arg)` with an empty thread handle for `threadHandle`, a function that loops polling the messages for `func`, and `remote_module` for `arg`] */ } else if (THREADAPI_OK != ThreadAPI_Create(&remote_module->message_thread->thread, worker_thread, remote_module)) { /* Codes_SRS_PROXY_GATEWAY_027_024: [If the worker thread failed to start, then `ProxyGateway_StartWorkerThread` shall free any previously allocated memory and return a non-zero value] */ LogError("%s: Unable to create worker thread!", __FUNCTION__); result = __LINE__; (void)Lock_Deinit(remote_module->message_thread->mutex); free(remote_module->message_thread); remote_module->message_thread = (MESSAGE_THREAD_HANDLE)NULL; } else { /* Codes_SRS_PROXY_GATEWAY_027_025: [If no errors are encountered, then `ProxyGateway_StartWorkerThread` shall return zero] */ result = 0; } return result; }