#include <memory.h>
#include "oic_malloc.h"
-NSConsumerThread * NSThreadInit(NSThreadFunc func, void * data)
+static NSConsumerThread * NSThreadInitInternal(NSThreadFunc func, void * data, bool detach)
{
NS_VERIFY_NOT_NULL(func, NULL);
handle->isStarted = true;
- pthread_attr_t attrDetached = {};
- pthread_attr_init(& attrDetached);
- pthread_attr_setdetachstate(& attrDetached, PTHREAD_CREATE_DETACHED);
+ if (detach)
+ {
+ pthread_attr_t attrDetached = {};
+ pthread_attr_init(& attrDetached);
+ pthread_attr_setdetachstate(& attrDetached, PTHREAD_CREATE_DETACHED);
+
+ pthreadResult = pthread_create(&(handle->thread_id), & attrDetached, func,
+ (data == NULL) ? (void *) handle : (void *)data);
+
+ pthread_attr_destroy(& attrDetached);
+ }
+ else
+ {
+ pthreadResult = pthread_create(&(handle->thread_id), NULL, func,
+ (data == NULL) ? (void *) handle : (void *)data);
+ }
- pthreadResult = pthread_create(&(handle->thread_id), & attrDetached, func,
- (data == NULL) ? (void *) handle : (void *)data);
NS_VERIFY_NOT_NULL_WITH_POST_CLEANING(pthreadResult == 0 ? (void *)1 : NULL,
NULL, NSDestroyThreadHandle(handle));
- pthread_attr_destroy(& attrDetached);
-
return handle;
}
+NSConsumerThread * NSJoinableThreadInit(NSThreadFunc func, void * data)
+{
+ return NSThreadInitInternal(func, data, false);
+}
+
+NSConsumerThread * NSThreadInit(NSThreadFunc func, void * data)
+{
+ return NSThreadInitInternal(func, data, true);
+}
+
void NSThreadLock(NSConsumerThread * handle)
{
NS_VERIFY_NOT_NULL_V(handle);