From: Pascal J. B. <pj...@in...> - 2014-05-04 07:23:06
|
shashank <sha...@gm...> writes: >>> 5. In [xthread.d, line 99,152] what does #define > THREADPROC_SIGNATURE do? >> This is just a syntax sugar to hide win32/posix thread function > return type. > Can you elaborate more? Use: M-x grep RET C-a C-k grep -nH THREADPROC_SIGNATURE *.d RET It is defined in two #ifdef: #if defined(POSIX_THREADS) // ... #define THREADPROC_SIGNATURE void * // ... #endif /* POSIX*_THREADS */ #if defined(WIN32_THREADS) // ... #define THREADPROC_SIGNATURE unsigned WINAPI // ... #endif /* WIN32_THREADS */ It is used in two functions: local THREADPROC_SIGNATURE thread_stub(void *arg) local THREADPROC_SIGNATURE mt_main_actions (void *param) So when we use POSIX_THREADS, those two functions will have the signature: local void * thread_stub(void *arg) local void * mt_main_actions (void *param) returning a pointer, but when we use WIN32_THREADS, they will have the signature: local unsigned WINAPI thread_stub(void *arg) local unsigned WINAPI mt_main_actions (void *param) returning a unsigned. This is the basic substitution mechanism of C pre-processor macros. What we've done here, is to conditionnalize the return type depending on the kind of threads we use. Similarly, the other xthread_* macros are defined differently depending on the kind of thread we use, so that we can write a single source text, that will be processed and produce a different source program depending on the kind of thread we use. -- __Pascal Bourguignon__ http://www.informatimago.com/ "Le mercure monte ? C'est le moment d'acheter !" |