2121
2222using namespace std ;
2323
24- pthread_mutex_t ThreadPool::mutexSync = PTHREAD_MUTEX_INITIALIZER;
24+ pthread_mutex_t ThreadPool::_mutex_sync = PTHREAD_MUTEX_INITIALIZER;
2525pthread_mutex_t ThreadPool::mutexWorkCompletion = PTHREAD_MUTEX_INITIALIZER;
2626
2727
@@ -30,13 +30,13 @@ ThreadPool::ThreadPool(unsigned int num_thread)
3030,_worker_queue(num_thread, NULL )
3131,_queue_size(num_thread)
3232{
33- pthread_mutex_lock (&mutexSync );
33+ pthread_mutex_lock (&_mutex_sync );
3434 _top_index = 0 ;
3535 _bottom_index = 0 ;
3636 _incomplete_work = 0 ;
3737 sem_init (&_available_work, 0 , 0 );
3838 sem_init (&_available_thread, 0 , _queue_size);
39- pthread_mutex_unlock (&mutexSync );
39+ pthread_mutex_unlock (&_mutex_sync );
4040}
4141
4242void ThreadPool::initialize_thread ()
@@ -67,7 +67,7 @@ void ThreadPool::destroy_pool(int maxPollSecs = 2)
6767 cout << " All Done!! Wow! That was a lot of work!" << endl;
6868 sem_destroy (&_available_work);
6969 sem_destroy (&_available_thread);
70- pthread_mutex_destroy (&mutexSync );
70+ pthread_mutex_destroy (&_mutex_sync );
7171 pthread_mutex_destroy (&mutexWorkCompletion);
7272
7373}
@@ -82,29 +82,29 @@ bool ThreadPool::assign_work(WorkerThread *workerThread)
8282
8383 sem_wait (&_available_thread);
8484
85- pthread_mutex_lock (&mutexSync );
85+ pthread_mutex_lock (&_mutex_sync );
8686 // workerVec[_top_index] = workerThread;
8787 _worker_queue[_top_index] = workerThread;
8888 // cout << "Assigning Worker[" << workerThread->id << "] Address:[" << workerThread << "] to Queue index [" << _top_index << "]" << endl;
8989 if (_queue_size !=1 )
9090 _top_index = (_top_index+1 ) % (_queue_size-1 );
9191 sem_post (&_available_work);
92- pthread_mutex_unlock (&mutexSync );
92+ pthread_mutex_unlock (&_mutex_sync );
9393 return true ;
9494}
9595
9696bool ThreadPool::fetch_work (WorkerThread **workerArg)
9797{
9898 sem_wait (&_available_work);
9999
100- pthread_mutex_lock (&mutexSync );
100+ pthread_mutex_lock (&_mutex_sync );
101101 WorkerThread * workerThread = _worker_queue[_bottom_index];
102102 _worker_queue[_bottom_index] = NULL ;
103103 *workerArg = workerThread;
104104 if (_queue_size !=1 )
105105 _bottom_index = (_bottom_index+1 ) % (_queue_size-1 );
106106 sem_post (&_available_thread);
107- pthread_mutex_unlock (&mutexSync );
107+ pthread_mutex_unlock (&_mutex_sync );
108108 return true ;
109109}
110110
0 commit comments