]> git.saurik.com Git - cycript.git/commitdiff
Switch from __thread to pthread_[gs]etspecific().
authorJay Freeman (saurik) <saurik@saurik.com>
Thu, 8 Jul 2010 02:29:29 +0000 (02:29 +0000)
committerJay Freeman (saurik) <saurik@saurik.com>
Thu, 8 Jul 2010 02:29:29 +0000 (02:29 +0000)
Local.hpp
Pooling.hpp

index c2237927fb6852283c4ce505ab97e5e75299c4de..1b97267d41f475759bbaf03061644ea7d8eb3ceb 100644 (file)
--- a/Local.hpp
+++ b/Local.hpp
 #ifndef CYLOCAL_HPP
 #define CYLOCAL_HPP
 
+#include <pthread.h>
+
 template <typename Type_>
-struct CYLocal {
-    Type_ last_;
+class CYLocal {
+  private:
+    static ::pthread_key_t key_;
+
+    Type_ *last_;
+
+  protected:
+    static _finline void Set(Type_ *value) {
+        _assert(::pthread_setspecific(key_, value) == 0);
+    }
 
-    CYLocal(Type_ next) {
-        Type_ &top(Top());
-        last_ = top;
-        top = next;
+    static ::pthread_key_t Key_() {
+        ::pthread_key_t key;
+        ::pthread_key_create(&key, NULL);
+        return key;
     }
 
-    ~CYLocal() {
-        Top() = last_;
+  public:
+    CYLocal(Type_ *next) {
+        last_ = Get();
+        Set(next);
     }
 
-    static Type_ &Top() {
-        static __thread Type_ top;
-        return top;
+    _finline ~CYLocal() {
+        Set(last_);
+    }
+
+    static _finline Type_ *Get() {
+        return reinterpret_cast<Type_ *>(::pthread_getspecific(key_));
     }
 };
 
+template <typename Type_>
+::pthread_key_t CYLocal<Type_>::key_ = Key_();
+
 #endif/*CYLOCAL_HPP*/
index 96b49326701e766e51834b457aa4e5b9ac718d55..c416b904319a07b893259b218f4706e205cd275e 100644 (file)
@@ -174,7 +174,7 @@ class CYLocalPool :
     public CYPool
 {
   private:
-    CYLocal<apr_pool_t *> local_;
+    CYLocal<apr_pool_t> local_;
 
   public:
     CYLocalPool() :
@@ -185,6 +185,6 @@ class CYLocalPool :
 };
 
 #define $pool \
-    CYLocal<apr_pool_t *>::Top()
+    CYLocal<apr_pool_t>::Get()
 
 #endif/*CYPOOLING_HPP*/