30#define _RWSTD_TEST_SRC
45#ifndef _RWSTD_NO_PURE_C_HEADERS
55static long maxthreads;
60_rw_timeout_expired = 0;
67 return _rw_timeout_expired != 0;
75_rw_timeout_handler (
int)
77 _rw_timeout_expired = 1;
85#if defined (_RWSTD_POSIX_THREADS)
87# ifdef _RWSTD_EDG_ECCP
91# pragma diag_suppress 450
102#ifdef _RWSTD_OS_SUNOS
104 static int concurrency_set;
106 if (0 == concurrency_set) {
107 pthread_setconcurrency (4);
127 const int result = pthread_create (&tid, 0, thr_proc, thr_arg);
130 thr_id->
id = (long)tid;
142 const int result = pthread_join ((pthread_t)thr_id.
id, parg);
149#elif defined (_RWSTD_SOLARIS_THREADS)
158 static int concurrency_set;
160 if (0 == concurrency_set) {
161 thr_setconcurrency (4);
187 thr_id->
id = (long)tid;
199 const int result = thr_join ((thread_t)thr_id.
id, 0, parg);
206#elif defined (_RWSTD_DEC_THREADS)
234 cma_thread_create (&tid,
239 thr_id->
id = tid.field1;
240 thr_id->
handle = (
void*)tid.field2;
263 cma_thread_join (&tid, 0, parg);
275#elif defined (_WIN32) && defined (_MT)
296 typedef unsigned int (__stdcall *win32_thr_proc_t)(
void *);
297 win32_thr_proc_t win32_thr_proc =
305 const uintptr_t hthread =
333 const DWORD retcode = WaitForSingleObject (thr_id.
handle, INFINITE);
335 if (WAIT_OBJECT_0 == retcode) {
339 if (GetExitCodeThread (thr_id.
handle, &exit_code))
340 *parg = (
void*)exit_code;
359# if defined (_RWSTD_OS_AIX)
361# elif defined (_RWSTD_OS_HP_UX)
363# elif defined (_RWSTD_OS_IRIX64)
365# elif defined (_RWSTD_OS_LINUX)
367# elif defined (_RWSTD_OS_OSF1)
369# elif defined (_RWSTD_OS_SUNOS)
371# elif defined (_WIN32)
372# define ENOTSUP ENOSYS
406 const char*
const cmd = {
411 "/etc/lsdev -Cc processor | /usr/bin/wc -l"
412# elif defined (_RWSTD_OS_LINUX)
417# elif defined (_RWSTD_OS_FREEBSD)
419 "/sbin/sysctl -n hw.ncpu"
420# elif defined (_RWSTD_OS_HP_UX)
422 "/etc/ioscan -k -C processor "
423 " | /usr/bin/grep processor "
425# elif defined (_RWSTD_OS_IRIX64)
428 " | /usr/bin/grep \"^[1-9][0-9]* .* Processor\""
429# elif defined (_RWSTD_OS_OSF1)
432 " | /usr/bin/grep on[-]*line "
434# elif defined (_RWSTD_OS_SUNOS)
437 " | /usr/bin/grep -v \"^CPU\" "
447# ifdef _SC_NPROCESSORS_ONLN
451 ncpus = int (sysconf (_SC_NPROCESSORS_ONLN));
453# elif defined (_SC_NPROCESSORS_CONF)
458 ncpus = int (sysconf (_SC_NPROCESSORS_CONF));
462 if (ncpus < 1 && cmd) {
471 int n = fscanf (fp,
"%d", &
tmp);
485 GetSystemInfo (&info);
486 return int (info.dwNumberOfProcessors);
503 _rw_timeout_expired = 0;
504 rw_alarm (
unsigned (timeout), _rw_timeout_handler);
510 const bool join = 0 == thr_id;
512#ifdef _RWSTD_REENTRANT
514 if (_RWSTD_SIZE_MAX == nthrs) {
522 nthrs = size_t (ncpus) + 1;
533 if (1 == nthrs && join) {
537 memset (thr_id, 0,
sizeof *thr_id);
542 void*
const arg = thr_arg ? thr_arg [0] : (
void*)(thr_id);
544 void*
const thr_result = thr_proc (
arg);
547 thr_arg [0] = thr_result;
553 bool delete_ids =
false;
558 if (
sizeof id_buf /
sizeof *id_buf < nthrs) {
568 for (
size_t i = 0;
i != nthrs; ++
i) {
572 void*
const next_arg = thr_arg ? thr_arg [
i] : (
void*)(thr_id +
i);
585 for (
size_t i = 0;
i != nthrs; ++
i) {
590 void** next_arg = thr_arg ? thr_arg +
i : 0;
#define _RWSTD_REINTERPRET_CAST(T, x)
#define _RWSTD_UNUSED(arg)
_TEST_EXPORT unsigned rw_alarm(unsigned int, rw_signal_handler_t *=0)
void * rw_thread_proc(void *)
_TEST_EXPORT int rw_thread_pool(rw_thread_t *thr_id, size_t nthrs, rw_thread_attr_t *, rw_thread_proc *thr_proc, void **thr_arg, size_t timeout)
_TEST_EXPORT int rw_thread_create(rw_thread_t *, rw_thread_attr_t *, rw_thread_proc *, void *)
_TEST_EXPORT int rw_thread_join(rw_thread_t, void **)
_TEST_EXPORT int rw_get_cpus()
_TEST_EXPORT int rw_thread_pool_timeout_expired()
FILE * popen(const char *, const char *)