diff --git a/common/pthreads_cross.c b/common/pthreads_cross.c index a5eaed25..6c646e02 100644 --- a/common/pthreads_cross.c +++ b/common/pthreads_cross.c @@ -246,9 +246,8 @@ unsigned int pcthread_get_num_procs() return sysinfo.dwNumberOfProcessors; } -#else +#elif !defined(_POSIX_THREADS) /* Not _WIN32. */ -#ifdef NOTHREADS int pthread_create(pthread_t *thread, pthread_attr_t *attr, void *(*start_routine)(void *), void *arg) { return 0; } int pthread_join(pthread_t thread, void **value_ptr) { return 0; } int pthread_detach(pthread_t thread) { return 0; } @@ -267,12 +266,13 @@ int pthread_cond_broadcast(pthread_cond_t *cond) { return 0; } int sched_yield(void) { return 0; } unsigned int pcthread_get_num_procs() { return 1; } -#else + +#else /* Not _WIN32 and _POSIX_THREADS is defined. */ + #include unsigned int pcthread_get_num_procs() { return (unsigned int)sysconf(_SC_NPROCESSORS_ONLN); } -#endif #endif diff --git a/common/pthreads_cross.h b/common/pthreads_cross.h index d0b77baf..3e0fe029 100644 --- a/common/pthreads_cross.h +++ b/common/pthreads_cross.h @@ -23,15 +23,14 @@ SOFTWARE. #ifndef __CPTHREAD_H__ #define __CPTHREAD_H__ -#ifndef NOTHREADS #ifdef _WIN32 #include #include #else +#include #include #include #endif -#endif #include @@ -68,9 +67,28 @@ int sched_yield(void); #ifdef __cplusplus } #endif + +#elif !defined(_POSIX_THREADS) /* _WIN32 not defined */ +/* + * If _WIN32 and _POSIX_THREADS are not defined then we dont support threads of + * any other kind. So in this case we define 'noop' pthread_* functions and + * types to resolve the symbols and in workerpool.c we make sure these noop + * functions arent expected to do thread related operations. + */ + +#if __POSIX_VISIBLE < 199506 +typedef int pthread_mutex_t; +typedef int pthread_mutexattr_t; +typedef int pthread_attr_t; +typedef int pthread_condattr_t; +typedef int pthread_rwlockattr_t; +typedef int pthread_t; +typedef int pthread_cond_t; #endif -#ifdef NOTHREADS +#ifdef __cplusplus +extern "C" { +#endif int pthread_create(pthread_t *thread, pthread_attr_t *attr, void *(*start_routine)(void *), void *arg); int pthread_join(pthread_t thread, void **value_ptr); int pthread_detach(pthread_t thread); @@ -88,8 +106,12 @@ int pthread_cond_signal(pthread_cond_t *cond); int pthread_cond_broadcast(pthread_cond_t *cond); int sched_yield(void); +#ifdef __cplusplus +} #endif +#endif /* !defined(_POSIX_THREADS) */ + #ifdef __cplusplus extern "C" { #endif