/* queuePth1.c++ implementation of int queue $ g++ -Wall queuePth1.c++ -c */ #include "queuePth1.h" pthread_mutex_t makeAtomic = PTHREAD_MUTEX_INITIALIZER; queue::queue() { front = rear = count = 0; } int queue::isFullQ(){ return count == MAX; } int queue::isEmptyQ(){ return count == 0; } int queue::addQ(int n){ int temp, i; if(isFullQ()) return ERROR; rear = (rear + 1) % MAX; data[rear] = n; // count = count+1; pthread_mutex_lock(&makeAtomic); temp = count; for(i=1; i<= 100000; ++i); // Delay temp = temp+1; count = temp; pthread_mutex_unlock(&makeAtomic); return OK; } int queue::frontQ(int &v){ if(isEmptyQ()) return ERROR; v = data[(front+1)%MAX] ; return OK; } int queue::deleteQ(){ int temp, i; if(isEmptyQ()) return ERROR; front = (front+1)%MAX ; // count = count - 1; pthread_mutex_lock(&makeAtomic); temp = count; for(i=1; i<= 100000; ++i); // Delay temp = temp-1; count = temp; pthread_mutex_unlock(&makeAtomic); return OK; }