Revision: 55021
          http://brlcad.svn.sourceforge.net/brlcad/?rev=55021&view=rev
Author:   brlcad
Date:     2013-04-03 05:36:21 +0000 (Wed, 03 Apr 2013)
Log Message:
-----------
if we can rely on __declspec(thread), then the ThreadLocal template won't need 
to be conditionalized to anything else anytime soon

Modified Paths:
--------------
    brlcad/trunk/src/libbu/thread.cpp

Modified: brlcad/trunk/src/libbu/thread.cpp
===================================================================
--- brlcad/trunk/src/libbu/thread.cpp   2013-04-03 05:27:26 UTC (rev 55020)
+++ brlcad/trunk/src/libbu/thread.cpp   2013-04-03 05:36:21 UTC (rev 55021)
@@ -27,24 +27,20 @@
 #endif
 
 
+#ifdef HAVE_PTHREAD_H
+
 template<typename T>
 class ThreadLocal
 {
 private:
-#ifdef HAVE_PTHREAD_H
     pthread_key_t key;
-#endif
     std::vector<T*> vals;
 public:
     ThreadLocal() {
-#ifdef HAVE_PTHREAD_H
        pthread_key_create(&key, NULL);
-#endif
     }
     ~ThreadLocal() {
-#ifdef HAVE_PTHREAD_H
        pthread_key_delete(key);
-#endif
        while (!vals.empty()) {
            delete vals.back();
            vals.pop_back();
@@ -54,37 +50,38 @@
     ThreadLocal& operator=(T& val) {
        T* value = new T(val);
        vals.push_back(value);
-#ifdef HAVE_PTHREAD_H
        pthread_setspecific(key, value);
-#endif
        return *this;
     }
     bool operator!() {
-#ifdef HAVE_PTHREAD_H
        return (pthread_getspecific(key) == NULL);
-#endif
     }
     operator T() {
-#ifdef HAVE_PTHREAD_H
        return *static_cast<T*>(pthread_getspecific(key));
-#endif
     }
 };
+static ThreadLocal<int> thread_cpu;
 
+#elif defined(__cplusplus) && __cplusplus > 199711L
 
-#if defined(__cplusplus) && __cplusplus > 199711L
-// C++11 provides thread-local storage
-thread_local int thread_cpu = 0;
+static thread_local int thread_cpu = 0;
+
 #elif defined(HAVE___THREAD)
-__thread int thread_cpu = 0;
+
+static __thread int thread_cpu = 0;
+
 #elif defined(_MSC_VER)
-__declspec(thread) int thread_cpu;
+
+static __declspec(thread) int thread_cpu;
+
 #else
-ThreadLocal<int> thread_cpu;
+#  error "Unrecognized thread local storage method for this platform"
 #endif
 
+
 extern "C" {
 
+
 void
 thread_set_cpu(int cpu)
 {

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Minimize network downtime and maximize team effectiveness.
Reduce network management and security costs.Learn how to hire 
the most talented Cisco Certified professionals. Visit the 
Employer Resources Portal
http://www.cisco.com/web/learning/employer_resources/index.html
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to