* entries.
* @param list the list to operate on.
* @param count the size to attempt to reserve room for.
+ * @return true if success, false otherwise.
*/
-void u_arraylist_reserve(u_arraylist_t *list, size_t count);
+bool u_arraylist_reserve(u_arraylist_t *list, size_t count);
/**
* Request that the storage in the list be reduced to fit its current length.
info->func = method;
info->data = data;
+ oc_mutex_lock(thread_pool->details->list_lock);
+ if (thread_pool->details->threads_list->capacity <= thread_pool->details->threads_list->length)
+ {
+ size_t new_capacity = ((thread_pool->details->threads_list->capacity * 3) + 1) / 2;
+ bool reserveResult = u_arraylist_reserve(thread_pool->details->threads_list, new_capacity);
+ if (!reserveResult)
+ {
+ oc_mutex_unlock(thread_pool->details->list_lock);
+ OIC_LOG(ERROR, TAG, "Arraylist reserve failed");
+ return CA_STATUS_FAILED;
+ }
+ }
+
oc_thread thread;
int thrRet = oc_thread_new(&thread, ca_thread_pool_pthreads_delegate, info);
if (thrRet != 0)
{
+ oc_mutex_unlock(thread_pool->details->list_lock);
OIC_LOG_V(ERROR, TAG, "Thread start failed with error %d", thrRet);
OICFree(info);
return CA_STATUS_FAILED;
}
- oc_mutex_lock(thread_pool->details->list_lock);
bool addResult = u_arraylist_add(thread_pool->details->threads_list, (void*)thread);
oc_mutex_unlock(thread_pool->details->list_lock);
if(!addResult)
{
- OIC_LOG_V(ERROR, TAG, "Arraylist Add failed, may not be properly joined: %d", addResult);
+ // Note that this is considered non-fatal.
+ OIC_LOG(ERROR, TAG, "Arraylist add failed");
oc_thread_free(thread);
return CA_STATUS_FAILED;
}
*list = NULL;
}
-void u_arraylist_reserve(u_arraylist_t *list, size_t count)
+bool u_arraylist_reserve(u_arraylist_t *list, size_t count)
{
if (list && (count > list->capacity))
{
if (!tmp)
{
OIC_LOG(DEBUG, TAG, "Memory reallocation failed.");
- // Note that this is considered non-fatal.
+ return false;
}
else
{
list->capacity = count;
}
}
+ return true;
}
void u_arraylist_shrink_to_fit(u_arraylist_t *list)
if (res != CA_STATUS_OK)
{
OIC_LOG(ERROR, TAG, "CAInitialize has failed");
+ CATerminateMessageHandler();
return res;
}
g_isInitialized = true;
if (CA_STATUS_OK != res)
{
OIC_LOG(ERROR, TAG, "Failed to Initialize send queue thread");
- ca_thread_pool_free(g_threadPoolHandle);
- g_threadPoolHandle = NULL;
return res;
}
if (CA_STATUS_OK != res)
{
OIC_LOG(ERROR, TAG, "thread start error(send thread).");
- ca_thread_pool_free(g_threadPoolHandle);
- g_threadPoolHandle = NULL;
- CAQueueingThreadDestroy(&g_sendThread);
return res;
}
if (CA_STATUS_OK != res)
{
OIC_LOG(ERROR, TAG, "Failed to Initialize receive queue thread");
- ca_thread_pool_free(g_threadPoolHandle);
- g_threadPoolHandle = NULL;
- CAQueueingThreadDestroy(&g_sendThread);
return res;
}
if (CA_STATUS_OK != res)
{
OIC_LOG(ERROR, TAG, "thread start error(receive thread).");
- ca_thread_pool_free(g_threadPoolHandle);
- g_threadPoolHandle = NULL;
- CAQueueingThreadDestroy(&g_sendThread);
- CAQueueingThreadDestroy(&g_receiveThread);
return res;
}
#endif // SINGLE_HANDLE
if (CA_STATUS_OK != res)
{
OIC_LOG(ERROR, TAG, "Failed to Initialize Retransmission.");
- ca_thread_pool_free(g_threadPoolHandle);
- g_threadPoolHandle = NULL;
- CAQueueingThreadDestroy(&g_sendThread);
- CAQueueingThreadDestroy(&g_receiveThread);
return res;
}
if (CA_STATUS_OK != res)
{
OIC_LOG(ERROR, TAG, "Failed to Initialize BlockWiseTransfer.");
- ca_thread_pool_free(g_threadPoolHandle);
- g_threadPoolHandle = NULL;
- CAQueueingThreadDestroy(&g_sendThread);
- CAQueueingThreadDestroy(&g_receiveThread);
- CARetransmissionDestroy(&g_retransmissionContext);
return res;
}
#endif
if (CA_STATUS_OK != res)
{
OIC_LOG(ERROR, TAG, "thread start error(retransmission thread).");
- ca_thread_pool_free(g_threadPoolHandle);
- g_threadPoolHandle = NULL;
- CAQueueingThreadDestroy(&g_sendThread);
- CAQueueingThreadDestroy(&g_receiveThread);
- CARetransmissionDestroy(&g_retransmissionContext);
return res;
}
oc_mutex_unlock(thread->threadMutex);
CAResult_t res = ca_thread_pool_add_task(thread->threadPool, CAQueueingThreadBaseRoutine,
- thread);
+ thread);
if (res != CA_STATUS_OK)
{
+ // update thread status.
+ oc_mutex_lock(thread->threadMutex);
+ thread->isStop = true;
+ oc_mutex_unlock(thread->threadMutex);
+
OIC_LOG(ERROR, TAG, "thread pool add task error(send thread).");
}
if (NULL == data || 0 == size)
{
OIC_LOG(ERROR, TAG, "data is empty..");
-
return CA_STATUS_INVALID_PARAM;
}