[Groonga-commit] groonga/grnxx at 9127dde [master] Update grnxx::PeriodicClock to use grnxx::Thread.

Back to archive index

susumu.yata null+****@clear*****
Tue Apr 30 22:31:53 JST 2013


susumu.yata	2013-04-30 22:31:53 +0900 (Tue, 30 Apr 2013)

  New Revision: 9127ddea97f44991e2ec7568ce95923edf3b0f1b
  https://github.com/groonga/grnxx/commit/9127ddea97f44991e2ec7568ce95923edf3b0f1b

  Message:
    Update grnxx::PeriodicClock to use grnxx::Thread.

  Modified files:
    lib/grnxx/time/periodic_clock.cpp

  Modified: lib/grnxx/time/periodic_clock.cpp (+7 -9)
===================================================================
--- lib/grnxx/time/periodic_clock.cpp    2013-04-30 22:28:13 +0900 (744ad32)
+++ lib/grnxx/time/periodic_clock.cpp    2013-04-30 22:31:53 +0900 (8484a79)
@@ -17,8 +17,6 @@
 */
 #include "grnxx/time/periodic_clock.hpp"
 
-#include <thread>
-
 #include "grnxx/intrinsic.hpp"
 #include "grnxx/thread.hpp"
 
@@ -30,7 +28,7 @@ namespace {
 constexpr Duration UPDATE_INTERVAL = Duration::milliseconds(100);
 
 volatile uint32_t ref_count = 0;
-std::thread thread;
+grnxx::Thread *thread = nullptr;
 
 }  // namespace
 
@@ -42,11 +40,9 @@ PeriodicClock::PeriodicClock() {
     if (atomic_compare_and_swap(count, count + 1, &ref_count)) {
       if (count == 0) {
         // Start the internal thread.
-        try {
-          thread = std::thread(routine);
+        thread = grnxx::Thread::create(routine);
+        if (thread) {
           now_ = SystemClock::now();
-        } catch (...) {
-          // Do nothing on failure.
         }
       }
       break;
@@ -59,8 +55,10 @@ PeriodicClock::~PeriodicClock() {
     const uint32_t count = ref_count;
     if (atomic_compare_and_swap(count, count - 1, &ref_count)) {
       if (count == 1) {
-        // Stop the internal thread.
-        thread.join();
+        // Stop the running thread.
+        thread->join();
+        delete thread;
+        thread = nullptr;
         now_ = Time::min();
       }
       break;
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index