Date: Thursday, November 30, 2006 @ 15:22:29
  Author: gilles
    Path: /cvsroot/carob/carob/src

Modified: ControllerPingSender.cpp (1.1 -> 1.2) ControllerPool.cpp (1.8 ->
          1.9) ControllerWatcher.cpp (1.2 -> 1.3)

Detached threads
Logging fixes


--------------------------+
 ControllerPingSender.cpp |   11 ++++++-----
 ControllerPool.cpp       |    7 +------
 ControllerWatcher.cpp    |   22 +++++++++++-----------
 3 files changed, 18 insertions(+), 22 deletions(-)


Index: carob/src/ControllerPingSender.cpp
diff -u carob/src/ControllerPingSender.cpp:1.1 
carob/src/ControllerPingSender.cpp:1.2
--- carob/src/ControllerPingSender.cpp:1.1      Tue Nov 28 17:07:55 2006
+++ carob/src/ControllerPingSender.cpp  Thu Nov 30 15:22:29 2006
@@ -37,9 +37,10 @@
 // extern C thread function that launches the ping
 void *PingSenderThread(void * thisPtr)
 {
-   ControllerPingSender* pt = (ControllerPingSender*)thisPtr;
-   pt->run();
-   return NULL;
+  ControllerPingSender* pt = (ControllerPingSender*)thisPtr;
+  pt->run();
+  pthread_exit(NULL);
+  return NULL;
 }
 
 ControllerPingSender::ControllerPingSender(WatchedControllers& controllerList,
@@ -53,6 +54,8 @@
 void ControllerPingSender::run()
 {
   std::wstring fctName(L"ControllerPingSender::run");
+  if (isDebugEnabled())
+    logDebug(fctName, L"Pinger started");
   java_byte packet[1];
   packet[0] = 0xB;
   while (!is_stopped)
@@ -63,8 +66,6 @@
       sendto(send_socket, static_cast<void*>(packet), sizeof(packet), 0,
           iter->getUDPAddrPtr(), iter->getUDPAddrLen());
       // This is really too much logs...
-//      if (isDebugEnabled())
-//        logDebug(fctName, L"Ping sent to " + 
static_cast<std::wstring>(*iter));
     }
     // detect violent clock changes (user hardly set new date/time)
     long before = getCurrentTimeInMs();
Index: carob/src/ControllerPool.cpp
diff -u carob/src/ControllerPool.cpp:1.8 carob/src/ControllerPool.cpp:1.9
--- carob/src/ControllerPool.cpp:1.8    Tue Nov 28 17:07:55 2006
+++ carob/src/ControllerPool.cpp        Thu Nov 30 15:22:29 2006
@@ -67,6 +67,7 @@
     watcher_ptr = new ControllerWatcher(controllerList, *callback_ptr,
         pingDelayInMs, controllerTimeoutInMs);
     pthread_create(&watcher_thread, NULL, ControllerWatcherThread, 
watcher_ptr);
+    pthread_detach(watcher_thread);
   }
   catch (ConnectionException cause)
   {
@@ -78,12 +79,6 @@
 AbstractControllerPool::~AbstractControllerPool()
 {
   watcher_ptr->stop();
-  int err = pthread_join(watcher_thread, NULL);
-  if (err && isErrorEnabled())
-  {
-    logError(L"AbstractControllerPool::~AbstractControllerPool",
-        L"Failed to join watcher thread");
-  }
   delete(watcher_ptr);
   delete(callback_ptr);
   alive_controllers.clear();
Index: carob/src/ControllerWatcher.cpp
diff -u carob/src/ControllerWatcher.cpp:1.2 carob/src/ControllerWatcher.cpp:1.3
--- carob/src/ControllerWatcher.cpp:1.2 Wed Nov 29 15:55:21 2006
+++ carob/src/ControllerWatcher.cpp     Thu Nov 30 15:22:29 2006
@@ -86,18 +86,13 @@
   
   pinger_ptr = new ControllerPingSender(*controllers_ptr, socket_fd, 
ping_delay_in_ms);
   pthread_create(&pinger_thread, NULL, PingSenderThread, pinger_ptr);
+  pthread_detach(pinger_thread);
 }
 
 ControllerWatcher::~ControllerWatcher()
 {
   // stop the pinger thread
   pinger_ptr->stop();
-  int err = pthread_join(pinger_thread, NULL);
-  if (err && isErrorEnabled())
-  {
-    logError(L"ControllerWatcher::~ControllerWatcher",
-        L"Failed to join pinger thread");
-  }
   close(socket_fd);
   delete(pinger_ptr);
   delete(controllers_ptr);
@@ -105,9 +100,10 @@
 
 void* ControllerWatcherThread(void * thisPtr)
 {
-   ControllerWatcher* pt = (ControllerWatcher*)thisPtr;
-   pt->run();
-   return NULL;
+  ControllerWatcher* pt = (ControllerWatcher*)thisPtr;
+  pt->run();
+  pthread_exit(NULL);
+  return NULL;
 }
 
 void ControllerWatcher::processAnswers()
@@ -148,6 +144,10 @@
 void ControllerWatcher::run()
 {
   wstring fctName(L"ControllerWatcher::run");
+  if (isDebugEnabled())
+  {
+    logDebug(fctName, L"Watcher started");
+  }
   while (!is_stopped)
   {
     // return of poll/select function
@@ -171,9 +171,9 @@
 #endif
     if (retVal == -1)
     {
-      if (isErrorEnabled())
+      if (isWarnEnabled())
       {
-        logError(fctName, wstring(POLL_FUNCTION) + L" returned error 
#"+toUserString(errno));
+        logWarn(fctName, wstring(POLL_FUNCTION) + L" returned error 
#"+toUserString(errno));
       }
       // clean-up will be done a the end of this function
     }

_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits

Reply via email to