@ -38,8 +38,7 @@ struct Lock {
using Condition = std : : condition_variable ;
using Condition = std : : condition_variable ;
inline
inline int ThreadPoolMutexLock ( Lock & mutex ) {
int MutexLock ( Lock & mutex ) {
mutex . ul_ . lock ( ) ;
mutex . ul_ . lock ( ) ;
return 0 ;
return 0 ;
}
}
@ -84,8 +83,7 @@ int ThreadDetach(std::thread& thread) {
using Lock = pthread_mutex_t & ;
using Lock = pthread_mutex_t & ;
using Condition = pthread_cond_t & ;
using Condition = pthread_cond_t & ;
inline
inline int ThreadPoolMutexLock ( Lock mutex ) {
int MutexLock ( Lock mutex ) {
return pthread_mutex_lock ( & mutex ) ;
return pthread_mutex_lock ( & mutex ) ;
}
}
@ -140,7 +138,7 @@ ThreadPool::~ThreadPool() { assert(bgthreads_.size() == 0U); }
void ThreadPool : : JoinAllThreads ( ) {
void ThreadPool : : JoinAllThreads ( ) {
Lock lock ( mu_ ) ;
Lock lock ( mu_ ) ;
PthreadCall ( " lock " , MutexLock ( lock ) ) ;
PthreadCall ( " lock " , ThreadPool MutexLock( lock ) ) ;
assert ( ! exit_all_threads_ ) ;
assert ( ! exit_all_threads_ ) ;
exit_all_threads_ = true ;
exit_all_threads_ = true ;
PthreadCall ( " signalall " , ConditionSignalAll ( bgsignal_ ) ) ;
PthreadCall ( " signalall " , ConditionSignalAll ( bgsignal_ ) ) ;
@ -166,7 +164,7 @@ void ThreadPool::BGThread(size_t thread_id) {
while ( true ) {
while ( true ) {
// Wait until there is an item that is ready to run
// Wait until there is an item that is ready to run
Lock uniqueLock ( mu_ ) ;
Lock uniqueLock ( mu_ ) ;
PthreadCall ( " lock " , MutexLock ( uniqueLock ) ) ;
PthreadCall ( " lock " , ThreadPool MutexLock( uniqueLock ) ) ;
// Stop waiting if the thread needs to do work or needs to terminate.
// Stop waiting if the thread needs to do work or needs to terminate.
while ( ! exit_all_threads_ & & ! IsLastExcessiveThread ( thread_id ) & &
while ( ! exit_all_threads_ & & ! IsLastExcessiveThread ( thread_id ) & &
( queue_ . empty ( ) | | IsExcessiveThread ( thread_id ) ) ) {
( queue_ . empty ( ) | | IsExcessiveThread ( thread_id ) ) ) {
@ -261,7 +259,7 @@ void ThreadPool::WakeUpAllThreads() {
void ThreadPool : : SetBackgroundThreadsInternal ( int num , bool allow_reduce ) {
void ThreadPool : : SetBackgroundThreadsInternal ( int num , bool allow_reduce ) {
Lock lock ( mu_ ) ;
Lock lock ( mu_ ) ;
PthreadCall ( " lock " , MutexLock ( lock ) ) ;
PthreadCall ( " lock " , ThreadPool MutexLock( lock ) ) ;
if ( exit_all_threads_ ) {
if ( exit_all_threads_ ) {
PthreadCall ( " unlock " , MutexUnlock ( lock ) ) ;
PthreadCall ( " unlock " , MutexUnlock ( lock ) ) ;
return ;
return ;
@ -314,7 +312,7 @@ void ThreadPool::Schedule(void (*function)(void* arg1), void* arg, void* tag,
void ( * unschedFunction ) ( void * arg ) ) {
void ( * unschedFunction ) ( void * arg ) ) {
Lock lock ( mu_ ) ;
Lock lock ( mu_ ) ;
PthreadCall ( " lock " , MutexLock ( lock ) ) ;
PthreadCall ( " lock " , ThreadPool MutexLock( lock ) ) ;
if ( exit_all_threads_ ) {
if ( exit_all_threads_ ) {
PthreadCall ( " unlock " , MutexUnlock ( lock ) ) ;
PthreadCall ( " unlock " , MutexUnlock ( lock ) ) ;
@ -348,7 +346,7 @@ int ThreadPool::UnSchedule(void* arg) {
int count = 0 ;
int count = 0 ;
Lock lock ( mu_ ) ;
Lock lock ( mu_ ) ;
PthreadCall ( " lock " , MutexLock ( lock ) ) ;
PthreadCall ( " lock " , ThreadPool MutexLock( lock ) ) ;
// Remove from priority queue
// Remove from priority queue
BGQueue : : iterator it = queue_ . begin ( ) ;
BGQueue : : iterator it = queue_ . begin ( ) ;