Skip to content

Commit 5e735a1

Browse files
committed
Refactoring
1 parent b7ce2de commit 5e735a1

2 files changed

Lines changed: 9 additions & 9 deletions

File tree

threadpool.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
using namespace std;
2323

24-
pthread_mutex_t ThreadPool::mutexSync = PTHREAD_MUTEX_INITIALIZER;
24+
pthread_mutex_t ThreadPool::_mutex_sync = PTHREAD_MUTEX_INITIALIZER;
2525
pthread_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

4242
void 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

9696
bool 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

threadpool.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class ThreadPool{
5555

5656
static void *thread_execute(void *param);
5757

58-
static pthread_mutex_t mutexSync;
58+
static pthread_mutex_t _mutex_sync;
5959
static pthread_mutex_t mutexWorkCompletion;
6060

6161

0 commit comments

Comments
 (0)