mirror of
https://github.com/HChaZZY/Stockfish.git
synced 2025-12-18 16:16:23 +08:00
Introduce thread local storage
Use thread local storage to store a pointer to the thread we are running on. This will allow to remove thread info from Position class. No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
@@ -34,11 +34,15 @@ namespace { extern "C" {
|
||||
// start_routine() is the C function which is called when a new thread
|
||||
// is launched. It is a wrapper to member function pointed by start_fn.
|
||||
|
||||
long start_routine(Thread* th) { (th->*(th->start_fn))(); return 0; }
|
||||
long start_routine(Thread* th) {
|
||||
|
||||
Threads.set_this_thread(th); // Save pointer into thread local storage
|
||||
(th->*(th->start_fn))();
|
||||
return 0;
|
||||
}
|
||||
|
||||
} }
|
||||
|
||||
|
||||
// Thread c'tor starts a newly-created thread of execution that will call
|
||||
// the idle loop function pointed by start_fn going immediately to sleep.
|
||||
|
||||
@@ -201,6 +205,7 @@ bool Thread::is_available_to(const Thread& master) const {
|
||||
|
||||
void ThreadsManager::init() {
|
||||
|
||||
tls_init(tlsKey);
|
||||
cond_init(sleepCond);
|
||||
lock_init(splitLock);
|
||||
timer = new Thread(&Thread::timer_loop);
|
||||
@@ -219,6 +224,7 @@ ThreadsManager::~ThreadsManager() {
|
||||
delete timer;
|
||||
lock_destroy(splitLock);
|
||||
cond_destroy(sleepCond);
|
||||
tls_destroy(tlsKey);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user