Revision: 55029
          http://brlcad.svn.sourceforge.net/brlcad/?rev=55029&view=rev
Author:   brlcad
Date:     2013-04-03 15:20:29 +0000 (Wed, 03 Apr 2013)
Log Message:
-----------
need to be careful to not dereference the specific value for single-threaded 
contexts.  initialize to cpu 0 so we can always return  asane. valueue in 
bu_parallel_id().

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

Modified: brlcad/trunk/src/libbu/thread.cpp
===================================================================
--- brlcad/trunk/src/libbu/thread.cpp   2013-04-03 14:02:19 UTC (rev 55028)
+++ brlcad/trunk/src/libbu/thread.cpp   2013-04-03 15:20:29 UTC (rev 55029)
@@ -47,9 +47,21 @@
 private:
     pthread_key_t key;
     std::vector<T*> vals;
+protected:
+    void set(T& val) {
+       T* value = new T(val);
+       vals.push_back(value);
+       pthread_setspecific(key, value);
+    }
+    T* get() {
+       T* val = static_cast<T*>(pthread_getspecific(key));
+       return val;
+    }
 public:
     ThreadLocal() {
+       int cpu0 = 0;
        pthread_key_create(&key, NULL);
+       set(cpu0);
     }
     ~ThreadLocal() {
        pthread_key_delete(key);
@@ -60,16 +72,17 @@
        vals.clear();
     }
     ThreadLocal& operator=(T& val) {
-       T* value = new T(val);
-       vals.push_back(value);
-       pthread_setspecific(key, value);
+       set(val);
        return *this;
     }
     bool operator!() {
-       return (pthread_getspecific(key) == NULL);
+       return (get() == NULL);
     }
     operator T() {
-       return *static_cast<T*>(pthread_getspecific(key));
+       T* val = get();
+       if (!val)
+           return 0;
+       return *val;
     }
 };
 static ThreadLocal<int> thread_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