#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
-#ifdef HAVE_PTHREAD_H
-#include <pthread.h>
+#ifdef HAVE_TIME_H
+#include <time.h>
#endif
#include <signal.h>
#include "ocstack.h"
#define TAG "SAMPLE_RANDOMPIN"
int gQuitFlag = 0;
-#ifdef _ENABLE_MULTIPLE_OWNER_
-static bool g_LoopFlag = true;
-#endif //_ENABLE_MULTIPLE_OWNER_
/* Structure to represent a LED resource */
typedef struct LEDRESOURCE{
}
#ifdef _ENABLE_MULTIPLE_OWNER_
-static pthread_t oc_process_thread;
-static void* oc_process_loop(void* ptr)
-{
- struct timespec timeout;
- timeout.tv_sec = 0;
- timeout.tv_nsec = 100000000L;
+#include <assert.h>
+#include <thread>
+#include <chrono>
+
+static bool volatile g_LoopFlag;
+static std::thread* oc_process_thread;
+static void oc_process_loop()
+{
while(g_LoopFlag)
{
if (OCProcess() != OC_STACK_OK)
g_LoopFlag = false;
break;
}
- nanosleep(&timeout, NULL);
+ std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
- pthread_join(&oc_process_thread, NULL);
- return NULL;
}
static void StartOCProcessThread()
{
- pthread_create(&oc_process_thread, NULL, oc_process_loop, NULL);
+ g_LoopFlag = true;
+ oc_process_thread = new std::thread(oc_process_loop);
}
static void StopOCProcessThread()
{
+ assert(oc_process_thread->joinable() == true);
g_LoopFlag = false;
+ oc_process_thread->join();
}
#endif //_ENABLE_MULTIPLE_OWNER_