1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-05-01 09:13:08 +00:00

Small renaming in thread.cpp

To better self document the code.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba 2011-04-29 10:07:23 +02:00
parent 0bf475ec55
commit 92d70fb667

View file

@ -24,32 +24,32 @@
ThreadsManager Threads; // Global object definition ThreadsManager Threads; // Global object definition
namespace { namespace { extern "C" {
// init_thread() is the function which is called when a new thread is // start_routine() is the C function which is called when a new thread
// launched. It simply calls the idle_loop() function with the supplied // is launched. It simply calls idle_loop() with the supplied threadID.
// threadID. There are two versions of this function; one for POSIX // There are two versions of this function; one for POSIX threads and
// threads and one for Windows threads. // one for Windows threads.
#if !defined(_MSC_VER) #if defined(_MSC_VER)
void* init_thread(void* threadID) { DWORD WINAPI start_routine(LPVOID threadID) {
Threads.idle_loop(*(int*)threadID, NULL);
return NULL;
}
#else
DWORD WINAPI init_thread(LPVOID threadID) {
Threads.idle_loop(*(int*)threadID, NULL); Threads.idle_loop(*(int*)threadID, NULL);
return 0; return 0;
} }
#else
void* start_routine(void* threadID) {
Threads.idle_loop(*(int*)threadID, NULL);
return NULL;
}
#endif #endif
} } }
// wake_up() wakes up the thread, normally at the beginning of the search or, // wake_up() wakes up the thread, normally at the beginning of the search or,
@ -115,12 +115,12 @@ void ThreadsManager::read_uci_options() {
} }
// init_threads() is called during startup. Initializes locks and condition // init() is called during startup. Initializes locks and condition variables
// variables and launches all threads sending them immediately to sleep. // and launches all threads sending them immediately to sleep.
void ThreadsManager::init() { void ThreadsManager::init() {
int arg[MAX_THREADS]; int threadID[MAX_THREADS];
// This flag is needed to properly end the threads when program exits // This flag is needed to properly end the threads when program exits
allThreadsShouldExit = false; allThreadsShouldExit = false;
@ -148,14 +148,14 @@ void ThreadsManager::init() {
for (int i = 1; i < MAX_THREADS; i++) for (int i = 1; i < MAX_THREADS; i++)
{ {
threads[i].state = Thread::INITIALIZING; threads[i].state = Thread::INITIALIZING;
arg[i] = i; threadID[i] = i;
#if !defined(_MSC_VER) #if defined(_MSC_VER)
pthread_t pthread[1]; bool ok = (CreateThread(NULL, 0, start_routine, (LPVOID)&threadID[i], 0, NULL) != NULL);
bool ok = (pthread_create(pthread, NULL, init_thread, (void*)(&arg[i])) == 0);
pthread_detach(pthread[0]);
#else #else
bool ok = (CreateThread(NULL, 0, init_thread, (LPVOID)(&arg[i]), 0, NULL) != NULL); pthread_t pthreadID;
bool ok = (pthread_create(&pthreadID, NULL, start_routine, (void*)&threadID[i]) == 0);
pthread_detach(pthreadID);
#endif #endif
if (!ok) if (!ok)
{ {
@ -169,8 +169,7 @@ void ThreadsManager::init() {
} }
// exit_threads() is called when the program exits. It makes all the // exit() is called to cleanly exit the threads when the program finishes
// helper threads exit cleanly.
void ThreadsManager::exit() { void ThreadsManager::exit() {