From: David Antler Date: Wed, 26 Oct 2016 18:18:11 +0000 (-0700) Subject: IOT-1476 Remove pthread from sampleserver_randompin X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4f8d3fd0bc552f18f13df11ea1347d9c452ebbac;p=contrib%2Fiotivity.git IOT-1476 Remove pthread from sampleserver_randompin - Using C++ threads as a cross-platform approach - Added .gitattributes file to ensure *.dat files are binary Change-Id: I602649d55ee5a8e24a2215d5f68ca5897c9cc6c7 Signed-off-by: David Antler Reviewed-on: https://gerrit.iotivity.org/gerrit/13727 Reviewed-by: Kevin Kane Reviewed-by: Alex Kelley Tested-by: jenkins-iotivity Reviewed-by: Dan Mihai Reviewed-by: Dave Thaler Reviewed-by: Randeep Singh --- diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..6935b1e --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ + +*.dat binary diff --git a/resource/csdk/security/provisioning/sample/sampleserver_randompin.cpp b/resource/csdk/security/provisioning/sample/sampleserver_randompin.cpp index 8837e38..dc10ede 100644 --- a/resource/csdk/security/provisioning/sample/sampleserver_randompin.cpp +++ b/resource/csdk/security/provisioning/sample/sampleserver_randompin.cpp @@ -27,8 +27,8 @@ #ifdef HAVE_UNISTD_H #include #endif -#ifdef HAVE_PTHREAD_H -#include +#ifdef HAVE_TIME_H +#include #endif #include #include "ocstack.h" @@ -48,9 +48,6 @@ #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{ @@ -146,14 +143,16 @@ const char *getResult(OCStackResult result) { } #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 +#include +#include + +static bool volatile g_LoopFlag; +static std::thread* oc_process_thread; +static void oc_process_loop() +{ while(g_LoopFlag) { if (OCProcess() != OC_STACK_OK) @@ -162,20 +161,21 @@ static void* oc_process_loop(void* ptr) 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_