26#ifdef ABC_USE_PTHREADS
29#include "../lib/pthread.h"
68#ifndef ABC_USE_PTHREADS
70void Util_ProcessThreads(
int (*pUserFunc)(
void *),
void * vData,
int nProcs,
int TimeOut,
int fVerbose )
79#define PAR_THR_MAX 100
80typedef struct Util_ThData_t_
83 int (*pUserFunc)(
void *);
89void * Util_Thread(
void * pArg )
91 struct timespec pause_duration;
92 pause_duration.tv_sec = 0;
93 pause_duration.tv_nsec = 10000000L;
95 Util_ThData_t * pThData = (Util_ThData_t *)pArg;
98 while ( !atomic_load_explicit((atomic_bool *)&pThData->fWorking, memory_order_acquire) )
99 nanosleep(&pause_duration, NULL);
100 if ( pThData->pUserData == NULL )
102 pthread_exit( NULL );
106 pThData->pUserFunc( pThData->pUserData );
107 atomic_store_explicit(&pThData->fWorking,
false, memory_order_release);
113void Util_ProcessThreads(
int (*pUserFunc)(
void *),
void * vData,
int nProcs,
int TimeOut,
int fVerbose )
131 for ( i = 0; i < nProcs; i++ )
133 ThData[i].pUserData = NULL;
134 ThData[i].pUserFunc = pUserFunc;
135 ThData[i].iThread = i;
136 ThData[i].nTimeOut = TimeOut;
137 atomic_store_explicit(&ThData[i].fWorking,
false, memory_order_release);
138 status = pthread_create( WorkerThread + i, NULL, Util_Thread, (
void *)(ThData + i) );
assert( status == 0 );
141 struct timespec pause_duration;
142 pause_duration.tv_sec = 0;
143 pause_duration.tv_nsec = 10000000L;
146 vStack = Vec_PtrDup( (
Vec_Ptr_t *)vData );
147 while ( Vec_PtrSize(vStack) > 0 )
149 for ( i = 0; i < nProcs; i++ )
151 if ( atomic_load_explicit(&ThData[i].fWorking, memory_order_acquire) )
153 ThData[i].pUserData = Vec_PtrPop( vStack );
154 atomic_store_explicit(&ThData[i].fWorking,
true, memory_order_release);
158 Vec_PtrFree( vStack );
161 for ( i = 0; i < nProcs; i++ )
163 if ( atomic_load_explicit(&ThData[i].fWorking, memory_order_acquire) )
165 nanosleep(&pause_duration, NULL);
169 for ( i = 0; i < nProcs; i++ )
171 ThData[i].pUserData = NULL;
172 atomic_store_explicit(&ThData[i].fWorking,
true, memory_order_release);
176 for ( i = 0; i < nProcs; i++ )
177 pthread_join( WorkerThread[i], NULL );
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
#define PAR_THR_MAX
DECLARATIONS ///.
ABC_NAMESPACE_IMPL_START void Util_ProcessThreads(int(*pUserFunc)(void *), void *vData, int nProcs, int TimeOut, int fVerbose)
DECLARATIONS ///.
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.