Skip to content

Commit

Permalink
Replace NOTHREADS macro with _POSIX_THREADS
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris-F5 committed Oct 3, 2024
1 parent 5d2dea8 commit ff1d9c3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
8 changes: 4 additions & 4 deletions common/pthreads_cross.c
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -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 <unistd.h>
unsigned int pcthread_get_num_procs()
{
return (unsigned int)sysconf(_SC_NPROCESSORS_ONLN);
}
#endif

#endif
28 changes: 25 additions & 3 deletions common/pthreads_cross.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@ SOFTWARE.
#ifndef __CPTHREAD_H__
#define __CPTHREAD_H__

#ifndef NOTHREADS
#ifdef _WIN32
#include <stdbool.h>
#include <windows.h>
#else
#include <unistd.h>
#include <pthread.h>
#include <sched.h>
#endif
#endif

#include <time.h>

Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand Down

0 comments on commit ff1d9c3

Please sign in to comment.