]> git.sesse.net Git - stockfish/blobdiff - src/thread.h
Introduce thread local storage
[stockfish] / src / thread.h
index 12fc4f23a70e1c21d596f092b9b0a35932c0e9b8..3f3c8c4c0a1614aee6735de0551073ee4c7a358c 100644 (file)
@@ -119,7 +119,9 @@ public:
   bool use_sleeping_threads() const { return useSleepingThreads; }
   int min_split_depth() const { return minimumSplitDepth; }
   int size() const { return (int)threads.size(); }
   bool use_sleeping_threads() const { return useSleepingThreads; }
   int min_split_depth() const { return minimumSplitDepth; }
   int size() const { return (int)threads.size(); }
-  Thread* main_thread() { return threads[0]; }
+  Thread* main_thread() const { return threads[0]; }
+  Thread* this_thread() const { return (Thread*)tls_get(tlsKey); }
+  void set_this_thread(Thread* th) const { tls_set(tlsKey, th); }
 
   void wake_up() const;
   void sleep() const;
 
   void wake_up() const;
   void sleep() const;
@@ -138,6 +140,7 @@ private:
 
   std::vector<Thread*> threads;
   Thread* timer;
 
   std::vector<Thread*> threads;
   Thread* timer;
+  ThreadLocalStorageKey tlsKey;
   Lock splitLock;
   WaitCondition sleepCond;
   Depth minimumSplitDepth;
   Lock splitLock;
   WaitCondition sleepCond;
   Depth minimumSplitDepth;