+} oc_cond_internal;
+
+typedef struct _tagThreadInfo_t
+{
+ pthread_t thread;
+ pthread_attr_t threadattr;
+} oc_thread_internal;
+
+#ifndef __TIZENRT__
+OCThreadResult_t oc_thread_new(oc_thread *t, void *(*start_routine)(void *), void *arg)
+#else
+OCThreadResult_t oc_thread_new(oc_thread *t, void *(*start_routine)(void *), void *arg,
+ const char *task_name, int stack_size)
+#endif
+{
+ OCThreadResult_t res = OC_THREAD_SUCCESS;
+ oc_thread_internal *threadInfo = (oc_thread_internal*)OICMalloc(sizeof(oc_thread_internal));
+ if (NULL != threadInfo)
+ {
+#ifdef __TIZENRT__
+ pthread_attr_t attr;
+ pthread_attr_init(&attr);
+ struct sched_param prio;
+ prio.sched_priority = 90;
+ (void)pthread_attr_setschedparam(&attr, &prio);
+ (void)pthread_attr_setstacksize(&attr, stack_size);
+ int result = pthread_create(&threadInfo->thread, &attr, start_routine, arg);
+ pthread_setname_np(threadInfo->thread, task_name);
+#else
+ int result = pthread_create(&threadInfo->thread, NULL, start_routine, arg);
+#endif
+ if (result != 0)
+ {
+ res = OC_THREAD_CREATE_FAILURE;
+ *t = NULL;
+ OICFree(threadInfo);
+ OIC_LOG_V(ERROR, TAG, "%s: pthread_create failed", __func__);
+ }
+ else
+ {
+ *t = (oc_thread)threadInfo;
+ }
+ }
+ else
+ {
+ OIC_LOG_V(ERROR, TAG, "%s Failed to allocate thread!", __func__);
+ *t = NULL;
+ res = OC_THREAD_ALLOCATION_FAILURE;
+ }
+ return res;
+}
+
+OCThreadResult_t oc_thread_free(oc_thread t)
+{
+ OCThreadResult_t res = OC_THREAD_SUCCESS;
+ oc_thread_internal *threadInfo = (oc_thread_internal*) t;
+ if (threadInfo)
+ {
+ OICFree(threadInfo);
+ }
+ else
+ {
+ OIC_LOG_V(ERROR, TAG, "%s Invalid thread !", __func__);
+ res = OC_THREAD_INVALID;
+ }
+ return res;
+}
+
+OCThreadResult_t oc_thread_wait(oc_thread t)
+{
+ OCThreadResult_t res = OC_THREAD_SUCCESS;
+ oc_thread_internal *threadInfo = (oc_thread_internal*) t;
+ int joinres = pthread_join(threadInfo->thread, NULL);
+ if (0 != joinres)
+ {
+ OIC_LOG_V(ERROR, TAG, "Failed to join thread with error %d", joinres);
+ res = OC_THREAD_WAIT_FAILURE;
+ }
+
+ return res;
+}
+
+#ifdef __TIZEN__
+OCThreadResult_t oc_thread_cancel(oc_thread t)
+{
+ OCThreadResult_t res = OC_THREAD_SUCCESS;
+ oc_thread_internal *threadInfo = (oc_thread_internal*) t;
+ int ret = pthread_cancel(threadInfo->thread);
+ if (0 != ret)
+ {
+ OIC_LOG_V(ERROR, TAG, "Failed to cancel thread with error %d", ret);
+ res = OC_THREAD_CANCEL_FAILURE;
+ }
+
+ return res;
+}