Convert from NULL macro to nullptr.
[shibboleth/cpp-xmltooling.git] / xmltooling / util / Threads.h
index e3eee29..aae15ed 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright 2001-2009 Internet2
+ *  Copyright 2001-2010 Internet2
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 /**
  * @file xmltooling/util/Threads.h
  *
- * Thread and locking wrappers
+ * Thread and locking wrappers.
  */
 
 #ifndef _xmltooling_threads_h
 #define _xmltooling_threads_h
 
-#include <xmltooling/base.h>
 #include <xmltooling/exceptions.h>
 
 #include <signal.h>
@@ -38,8 +37,9 @@ namespace xmltooling
     class XMLTOOL_API Thread
     {
         MAKE_NONCOPYABLE(Thread);
-    public:
+    protected:
         Thread() {}
+    public:
         virtual ~Thread() {}
 
         /**
@@ -70,9 +70,10 @@ namespace xmltooling
          *
          * @param start_routine the function to execute on the thread
          * @param arg           a parameter for the start routine
+         * @param stacksize     size of stack to use, or 0 for default
          * @return  the created and running thread object
          */
-        static Thread* create(void* (*start_routine)(void*), void* arg);
+        static Thread* create(void* (*start_routine)(void*), void* arg, size_t stacksize=0);
 
         /**
          * Exits a thread gracefully.
@@ -111,8 +112,9 @@ namespace xmltooling
     class XMLTOOL_API ThreadKey
     {
         MAKE_NONCOPYABLE(ThreadKey);
-    public:
+    protected:
         ThreadKey() {}
+    public:
         virtual ~ThreadKey() {}
 
         /**
@@ -126,7 +128,7 @@ namespace xmltooling
         /**
          * Returns the value for a TLS key.
          *
-         * @return the value or NULL
+         * @return the value or nullptr
          */
         virtual void* getData() const=0;
 
@@ -155,8 +157,9 @@ namespace xmltooling
     class XMLTOOL_API Mutex
     {
         MAKE_NONCOPYABLE(Mutex);
-    public:
+    protected:
         Mutex() {}
+    public:
         virtual ~Mutex() {}
 
         /**
@@ -187,8 +190,9 @@ namespace xmltooling
     class XMLTOOL_API RWLock
     {
         MAKE_NONCOPYABLE(RWLock);
-    public:
+    protected:
         RWLock() {}
+    public:
         virtual ~RWLock() {}
 
         /**
@@ -226,8 +230,9 @@ namespace xmltooling
     class XMLTOOL_API CondWait
     {
         MAKE_NONCOPYABLE(CondWait);
-    public:
+    protected:
         CondWait() {}
+    public:
         virtual ~CondWait() {}
 
         /**
@@ -282,14 +287,16 @@ namespace xmltooling
          * @param mtx mutex to lock
          */
         Lock(Mutex* mtx) : mutex(mtx) {
-            mutex->lock();
+            if (mutex)
+                mutex->lock();
         }
 
         /**
          * Unlocks the wrapped mutex.
          */
         ~Lock() {
-            mutex->unlock();
+            if (mutex)
+                mutex->unlock();
         }
 
     private:
@@ -309,7 +316,7 @@ namespace xmltooling
          * @param lockit    true if the lock should be acquired here, false if already acquired
          */
         SharedLock(RWLock* lock, bool lockit=true) : rwlock(lock) {
-            if (lockit)
+            if (rwlock && lockit)
                 rwlock->rdlock();
         }
 
@@ -317,7 +324,8 @@ namespace xmltooling
          * Unlocks the wrapped shared lock.
          */
         ~SharedLock() {
-            rwlock->unlock();
+            if (rwlock)
+                rwlock->unlock();
         }
 
     private: