*
******************************************************************/
+#include "iotivity_config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#ifdef HAVE_UNISTD_H
#include <unistd.h>
-#include <sys/syscall.h>
+#endif
+#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
+#endif
#include "caqueueingthread.h"
#include "oic_malloc.h"
#include "logger.h"
-#define TAG PCF("CA")
+#define TAG PCF("OIC_CA_QING")
static void CAQueueingThreadBaseRoutine(void *threadValue)
{
if (NULL == thread)
{
OIC_LOG(ERROR, TAG, "thread data passing error!!");
-
return;
}
OIC_LOG(DEBUG, TAG, "wake up..");
}
- // mutex unlock
- ca_mutex_unlock(thread->threadMutex);
-
// check stop flag
if (thread->isStop)
{
+ // mutex unlock
+ ca_mutex_unlock(thread->threadMutex);
continue;
}
// get data
u_queue_message_t *message = u_queue_get_element(thread->dataQueue);
+ // mutex unlock
+ ca_mutex_unlock(thread->threadMutex);
if (NULL == message)
{
continue;
OICFree(message);
}
- // remove all remained list data.
- while (u_queue_get_size(thread->dataQueue) > 0)
- {
- // get data
- u_queue_message_t *message = u_queue_get_element(thread->dataQueue);
-
- // free
- if(NULL != message)
- {
- if (NULL != thread->destroy)
- {
- thread->destroy(message->msg, message->size);
- }
- else
- {
- OICFree(message->msg);
- }
-
- OICFree(message);
- }
- }
-
ca_mutex_lock(thread->threadMutex);
ca_cond_signal(thread->threadCond);
ca_mutex_unlock(thread->threadMutex);
thread->isStop = true;
thread->threadTask = task;
thread->destroy = destroy;
+ if (NULL == thread->dataQueue || NULL == thread->threadMutex || NULL == thread->threadCond)
+ {
+ goto ERROR_MEM_FAILURE;
+ }
return CA_STATUS_OK;
+
+ERROR_MEM_FAILURE:
+ if (thread->dataQueue)
+ {
+ u_queue_delete(thread->dataQueue);
+ thread->dataQueue = NULL;
+ }
+ if (thread->threadMutex)
+ {
+ ca_mutex_free(thread->threadMutex);
+ thread->threadMutex = NULL;
+ }
+ if (thread->threadCond)
+ {
+ ca_cond_free(thread->threadCond);
+ thread->threadCond = NULL;
+ }
+ return CA_MEMORY_ALLOC_FAILED;
}
CAResult_t CAQueueingThreadStart(CAQueueingThread_t *thread)
ca_mutex_free(thread->threadMutex);
thread->threadMutex = NULL;
ca_cond_free(thread->threadCond);
+
+ // remove all remained list data.
+ while (u_queue_get_size(thread->dataQueue) > 0)
+ {
+ // get data
+ u_queue_message_t *message = u_queue_get_element(thread->dataQueue);
+
+ // free
+ if (NULL != message)
+ {
+ if (NULL != thread->destroy)
+ {
+ thread->destroy(message->msg, message->size);
+ }
+ else
+ {
+ OICFree(message->msg);
+ }
+
+ OICFree(message);
+ }
+ }
+
u_queue_delete(thread->dataQueue);
+ thread->dataQueue = NULL;
return CA_STATUS_OK;
}