void CAManagerTerminateLEAutoConnection() { if (g_connectRetryCond) { ca_cond_signal(g_connectRetryCond); ca_cond_free(g_connectRetryCond); g_connectRetryCond = NULL; } if (g_connectRetryMutex) { ca_mutex_free(g_connectRetryMutex); g_connectRetryMutex = NULL; } if (g_recoveryCond) { ca_cond_signal(g_recoveryCond); ca_cond_free(g_recoveryCond); g_recoveryCond = NULL; } if (g_recoveryMutex) { ca_mutex_free(g_recoveryMutex); g_recoveryMutex = NULL; } }
void CATerminateGattClientMutexVariables() { OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "IN"); ca_mutex_free(g_bleClientStateMutex); g_bleClientStateMutex = NULL; ca_mutex_free(g_bleServiceListMutex); g_bleServiceListMutex = NULL; ca_mutex_free(g_bleReqRespClientCbMutex); g_bleReqRespClientCbMutex = NULL; ca_mutex_free(g_bleClientConnectMutex); g_bleClientConnectMutex = NULL; ca_mutex_free(g_bleClientThreadPoolMutex); g_bleClientThreadPoolMutex = NULL; ca_mutex_free(g_bleServerBDAddressMutex); g_bleServerBDAddressMutex = NULL; ca_cond_free(g_bleClientSendCondWait); g_bleClientSendCondWait = NULL; OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "OUT"); }
static void CATCPDestroyCond() { if (g_condObjectList) { ca_cond_free(g_condObjectList); g_condObjectList = NULL; } }
void CATerminateLENetworkMonitor() { /** * @note "Network monitor" operations are stopped in @c CALEStop() * since they are started in @c CAStartLEAdapter() rather * than @c CAInitializeLENetworkMonitor(). * * @see @c CAStartLEAdapter() for further details. */ /* Since the CA LE interface doesn't expose a CAInitializeLEGattServer() function, finalize the LE server (peripheral) here rather than in CATerminateLEGattServer() to ensure finalization is correctly paired with initialization. */ CAPeripheralFinalize(); (void) sem_destroy(&g_context.le_started); ca_mutex_lock(g_context.lock); g_context.on_device_state_changed = NULL; g_context.on_server_received_data = NULL; g_context.on_client_received_data = NULL; g_context.client_thread_pool = NULL; g_context.server_thread_pool = NULL; g_context.on_client_error = NULL; g_context.on_server_error = NULL; ca_cond_free(g_context.condition); g_context.condition = NULL; ca_mutex_unlock(g_context.lock); ca_mutex_free(g_context.lock); g_context.lock = NULL; }
void CAPeripheralFinalize() { ca_cond_free(g_context.condition); ca_mutex_free(g_context.lock); }
void testThreadPool(void) { char *string = "Test thread pool"; //Initialize the mutex printf("[testThreadPool] Initializing mutex\n"); //Initialize the thread pool printf("[testThreadPool] Initializing thread pool\n"); if (CA_STATUS_OK != ca_thread_pool_init(2, &g_threadPoolHandle)) { printf("thread_pool_init failed!\n"); return; } //Create the mutex printf("[testThreadPool] Creating mutex\n"); g_mutex = ca_mutex_new(); if (NULL == g_mutex) { printf("[testThreadPool] Failed to create mutex!\n"); ca_thread_pool_free(g_threadPoolHandle); return; } //Create the condition printf("[testThreadPool] Creating Condition\n"); g_cond = ca_cond_new(); if (NULL == g_cond) { printf("[testThreadPool] Failed to create condition!\n"); ca_mutex_free(g_mutex); ca_thread_pool_free(g_threadPoolHandle); return; } //Lock the mutex printf("[testThreadPool] Locking the mutex\n"); ca_mutex_lock(g_mutex); g_condFlag = false; //Add task to thread pool printf("[testThreadPool] Adding the task to thread pool\n"); if (CA_STATUS_OK != ca_thread_pool_add_task(g_threadPoolHandle, task, (void *) string)) { printf("[testThreadPool] thread_pool_add_task failed!\n"); ca_thread_pool_free(g_threadPoolHandle); ca_mutex_unlock(g_mutex); ca_mutex_free(g_mutex); ca_cond_free(g_cond); return; } //Wait for the task to be executed printf("[testThreadPool] Waiting for the task to be completed\n"); while (!g_condFlag) { ca_cond_wait(g_cond, g_mutex); } //Unlock the mutex printf("[testThreadPool] Got the signal and unlock the mutex\n"); ca_mutex_unlock(g_mutex); printf("[testThreadPool] Task is completed and terminating threadpool\n"); ca_cond_free(g_cond); ca_mutex_free(g_mutex); ca_thread_pool_free(g_threadPoolHandle); printf("Exiting from testThreadPool\n"); }