CAResult_t CAInitializeLENetworkMonitor() { /** * @note "Network monitor" operations are started in the * @c CAStartLEAdapter() function rather than this function * due to glib/D-Bus signal handling threads related * issues. * * @see @c CAStartLEAdapter() for further details. */ g_context.lock = ca_mutex_new(); g_context.condition = ca_cond_new(); static int const PSHARED = 0; // shared between threads static unsigned int const VALUE = 0; // force sem_wait() to block if (sem_init(&g_context.le_started, PSHARED, VALUE) != 0) { return CA_STATUS_FAILED; } /* The CA LE interface doesn't expose a CAInitializeLEGattServer() function so perform initialization here. */ CAPeripheralInitialize(); return CA_STATUS_OK; }
CAResult_t CAManagerInitLEAutoConnection() { if (NULL == g_connectRetryMutex) { g_connectRetryMutex = ca_mutex_new(); if (NULL == g_connectRetryMutex) { OIC_LOG(ERROR, TAG, "ca_mutex_new has failed"); return CA_STATUS_FAILED; } } if (NULL == g_connectRetryCond) { g_connectRetryCond = ca_cond_new(); if (NULL == g_connectRetryCond) { OIC_LOG(ERROR, TAG, "ca_cond_new has failed"); return CA_STATUS_FAILED; } } if (NULL == g_recoveryMutex) { g_recoveryMutex = ca_mutex_new(); if (NULL == g_recoveryMutex) { OIC_LOG(ERROR, TAG, "ca_mutex_new has failed"); return CA_STATUS_FAILED; } } if (NULL == g_recoveryCond) { g_recoveryCond = ca_cond_new(); if (NULL == g_recoveryCond) { OIC_LOG(ERROR, TAG, "ca_cond_new has failed"); return CA_STATUS_FAILED; } } return CA_STATUS_OK; }
static CAResult_t CATCPCreateCond() { if (!g_condObjectList) { g_condObjectList = ca_cond_new(); if (!g_condObjectList) { OIC_LOG(ERROR, TAG, "Failed to created cond!"); return CA_STATUS_FAILED; } } return CA_STATUS_OK; }
void CAPeripheralInitialize() { g_context.lock = ca_mutex_new(); g_context.condition = ca_cond_new(); }
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"); }
CAResult_t CAInitGattClientMutexVariables() { OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "IN"); if (NULL == g_bleClientStateMutex) { g_bleClientStateMutex = ca_mutex_new(); if (NULL == g_bleClientStateMutex) { OIC_LOG(ERROR, TZ_BLE_CLIENT_TAG, "ca_mutex_new failed"); return CA_STATUS_FAILED; } } if (NULL == g_bleServiceListMutex) { g_bleServiceListMutex = ca_mutex_new(); if (NULL == g_bleServiceListMutex) { OIC_LOG(ERROR, TZ_BLE_CLIENT_TAG, "ca_mutex_new failed"); return CA_STATUS_FAILED; } } if (NULL == g_bleReqRespClientCbMutex) { g_bleReqRespClientCbMutex = ca_mutex_new(); if (NULL == g_bleReqRespClientCbMutex) { OIC_LOG(ERROR, TZ_BLE_CLIENT_TAG, "ca_mutex_new failed"); return CA_STATUS_FAILED; } } if (NULL == g_bleClientThreadPoolMutex) { g_bleClientThreadPoolMutex = ca_mutex_new(); if (NULL == g_bleClientThreadPoolMutex) { OIC_LOG(ERROR, TZ_BLE_CLIENT_TAG, "ca_mutex_new failed"); return CA_STATUS_FAILED; } } if (NULL == g_bleClientConnectMutex) { g_bleClientConnectMutex = ca_mutex_new(); if (NULL == g_bleClientConnectMutex) { OIC_LOG(ERROR, TZ_BLE_CLIENT_TAG, "ca_mutex_new failed"); return CA_STATUS_FAILED; } } if (NULL == g_bleClientSendCondWait) { g_bleClientSendCondWait = ca_cond_new(); if (NULL == g_bleClientSendCondWait) { OIC_LOG(ERROR, TZ_BLE_CLIENT_TAG, "ca_cond_new failed"); return CA_STATUS_FAILED; } } if (NULL == g_bleServerBDAddressMutex) { g_bleServerBDAddressMutex = ca_mutex_new(); if (NULL == g_bleServerBDAddressMutex) { OIC_LOG(ERROR, TZ_BLE_CLIENT_TAG, "ca_mutex_new failed"); return CA_STATUS_FAILED; } } OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "OUT"); return CA_STATUS_OK; }