DPL: work around for dependency on DPL::Thread 63/23163/4
authorRafal Krypa <r.krypa@samsung.com>
Mon, 2 Jun 2014 17:10:59 +0000 (19:10 +0200)
committerRafal Krypa <r.krypa@samsung.com>
Mon, 23 Jun 2014 18:03:48 +0000 (20:03 +0200)
Patch based on work by similar work by Zofia Abramowska.
Include needed parts from DPL::Thread into code of
NaiveSynchronizationObject.
Only NanoSleep() and MiliSleep() methods are needed and the original
DPL::Thread() triggers a large chain of dependencies, including EFL.

Change-Id: Icf8257ca8eeaa5cdbc4d80ceb98d88aceeec7821
Signed-off-by: Rafal Krypa <r.krypa@samsung.com>
src/server/dpl/db/src/naive_synchronization_object.cpp

index 1ac71ca..63f1dd7 100644 (file)
  */
 #include <stddef.h>
 #include <dpl/db/naive_synchronization_object.h>
-#include <dpl/thread.h>
+#include <dpl/assert.h>
+#include <time.h>
 
 namespace {
     unsigned int seed = time(NULL);
 }
 
+//Taken from Thread class, so we don't have to pull whole definition
+//(only this part is needed)
+namespace Thread {
+
+static const size_t NANOSECONDS_PER_SECOND =
+    static_cast<uint64_t>(1000 * 1000 * 1000);
+
+static const size_t NANOSECONDS_PER_MILISECOND =
+    static_cast<uint64_t>(1000 * 1000);
+
+void NanoSleep(uint64_t nanoseconds)
+{
+    timespec requestedTime = {
+        static_cast<time_t>(
+            nanoseconds / NANOSECONDS_PER_SECOND),
+
+        static_cast<long>(
+            nanoseconds % NANOSECONDS_PER_SECOND)
+    };
+
+    timespec remainingTime;
+
+    for (;;) {
+        if (nanosleep(&requestedTime, &remainingTime) == 0) {
+            break;
+        }
+
+        int error = errno;
+        Assert(error == EINTR);
+
+        requestedTime = remainingTime;
+    }
+}
+
+void MiliSleep(uint64_t miliseconds)
+{
+    NanoSleep(miliseconds * NANOSECONDS_PER_MILISECOND);
+}
+}
+
 namespace DPL {
 namespace DB {
 void NaiveSynchronizationObject::Synchronize()