| 969 | } |
| 970 | |
| 971 | cl_uint GetThreadCount(void) |
| 972 | { |
| 973 | // Lazily set up our threads |
| 974 | #if defined(_MSC_VER) && (_WIN32_WINNT >= 0x600) |
| 975 | cl_int err = !_InitOnceExecuteOnce(&threadpool_init_control, |
| 976 | _ThreadPool_Init, NULL, NULL); |
| 977 | #elif defined(_WIN32) |
| 978 | if (threadpool_init_control == 0) |
| 979 | { |
| 980 | #warning This is buggy and race prone. Find a better way. |
| 981 | ThreadPool_Init(); |
| 982 | threadpool_init_control = 1; |
| 983 | } |
| 984 | #else |
| 985 | cl_int err = pthread_once(&threadpool_init_control, ThreadPool_Init); |
| 986 | if (err) |
| 987 | { |
| 988 | log_error("Error %d from pthread_once. Unable to init threads. " |
| 989 | "ThreadPool_Do failed.\n", |
| 990 | err); |
| 991 | return err; |
| 992 | } |
| 993 | #endif // !_WIN32 |
| 994 | |
| 995 | if (gThreadCount < 1) return 1; |
| 996 | |
| 997 | return gThreadCount; |
| 998 | } |
| 999 | |
| 1000 | #else |
| 1001 | |