Add logging of result codes.
authorScott Cantor <cantor.2@osu.edu>
Thu, 13 May 2004 20:47:54 +0000 (20:47 +0000)
committerScott Cantor <cantor.2@osu.edu>
Thu, 13 May 2004 20:47:54 +0000 (20:47 +0000)
shib/shib-threads.cpp

index 3a20ed4..c9c0e13 100644 (file)
@@ -114,36 +114,86 @@ public:
 
 ThreadImpl::ThreadImpl(void* (*start_routine)(void*), void* arg)
 {
-  if (pthread_create (&thread_id, NULL, start_routine, arg) != 0)
-    throw runtime_error("pthread_create failed");
+    int rc=pthread_create(&thread_id, NULL, start_routine, arg);
+    if (rc) {
+#ifdef HAVE_STRERROR_R
+        char buf[256];
+        strerror_r(rc,buf,sizeof(buf));
+        buf[255]=0;
+        Category::getInstance(SHIB_LOGCAT".threads").error("pthread_create error (%d): %s",rc,buf);
+#else
+        Category::getInstance(SHIB_LOGCAT".threads").error("pthread_create error (%d): %s",rc,strerror(rc));
+#endif
+        throw rc;
+    }
 }
 
 MutexImpl::MutexImpl()
 {
-  if (pthread_mutex_init (&mutex, NULL) != 0)
-    throw runtime_error("pthread_mutex_init failed");
+    int rc=pthread_mutex_init(&mutex, NULL);
+    if (rc) {
+#ifdef HAVE_STRERROR_R
+        char buf[256];
+        strerror_r(rc,buf,sizeof(buf));
+        buf[255]=0;
+        Category::getInstance(SHIB_LOGCAT".threads").error("pthread_mutex_init error (%d): %s",rc,buf);
+#else
+        Category::getInstance(SHIB_LOGCAT".threads").error("pthread_mutex_init error (%d): %s",rc,strerror(rc));
+#endif
+        throw rc;
+    }
 }
 
 CondWaitImpl::CondWaitImpl()
 {
-  if (pthread_cond_init (&cond, NULL) != 0)
-    throw runtime_error("pthread_cond_init failed");
+    int rc=pthread_cond_init(&cond, NULL);
+    if (rc) {
+#ifdef HAVE_STRERROR_R
+        char buf[256];
+        strerror_r(rc,buf,sizeof(buf));
+        buf[255]=0;
+        Category::getInstance(SHIB_LOGCAT".threads").error("pthread_cond_init error (%d): %s",rc,buf);
+#else
+        Category::getInstance(SHIB_LOGCAT".threads").error("pthread_cond_init error (%d): %s",rc,strerror(rc));
+#endif
+        throw rc;
+    }
 }
 
 RWLockImpl::RWLockImpl()
 {
 #ifdef HAVE_PTHREAD_RWLOCK_INIT
-  if (pthread_rwlock_init(&lock, NULL) != 0)
+    int rc=pthread_rwlock_init(&lock, NULL);
+#else
+    int rc=rwlock_init(&lock, USYNC_THREAD, NULL);
+#endif
+    if (rc) {
+#ifdef HAVE_STRERROR_R
+        char buf[256];
+        strerror_r(rc,buf,sizeof(buf));
+        buf[255]=0;
+        Category::getInstance(SHIB_LOGCAT".threads").error("pthread_rwlock_init error (%d): %s",rc,buf);
 #else
-  if (rwlock_init (&lock, USYNC_THREAD, NULL) != 0)
+        Category::getInstance(SHIB_LOGCAT".threads").error("pthread_rwlock_init error (%d): %s",rc,strerror(rc));
 #endif
-    throw runtime_error("pthread_rwlock_init failed");
+        throw rc;
+    }
 }
 
 ThreadKeyImpl::ThreadKeyImpl(void (*destroy_fcn)(void*))
 {
-  if (pthread_key_create (&key, destroy_fcn) != 0)
-    throw runtime_error("pthread_key_create failed");
+    int rc=pthread_key_create(&key, destroy_fcn);
+    if (rc) {
+#ifdef HAVE_STRERROR_R
+        char buf[256];
+        strerror_r(rc,buf,sizeof(buf));
+        buf[255]=0;
+        Category::getInstance(SHIB_LOGCAT".threads").error("pthread_key_create error (%d): %s",rc,buf);
+#else
+        Category::getInstance(SHIB_LOGCAT".threads").error("pthread_key_create error (%d): %s",rc,strerror(rc));
+#endif
+        throw rc;
+    }
 }
 
 //