This repository has been archived on 2025-04-11. You can view files and clone it, but cannot push or open issues or pull requests.
csce313-mp4pinie64backup/BoundedBuffer.h

47 lines
948 B
C
Raw Normal View History

2015-11-10 15:56:32 -06:00
#ifndef _BoundedBuffer_H_
#define _BoundedBuffer_H_
#include <vector>
#include <string>
//#include <semaphore.h>
using namespace std;
//extern unsigned int n, b, w;
class BoundedBuffer{
Semaphore *full = new Semaphore(0); //initialized to 0, Since there are 0 full slots
Semaphore *empty;// = new Semaphore(b); //initialized to b, Since all the slots are empty
Semaphore *mutex = new Semaphore(1);
vector<string> data;
public:
2015-11-11 17:15:35 -06:00
BoundedBuffer(){empty = new Semaphore(200);}//default b value
2015-11-10 15:56:32 -06:00
BoundedBuffer(int b){
2015-11-11 17:15:35 -06:00
empty = new Semaphore(b);
2015-11-10 15:56:32 -06:00
}
2015-11-13 10:02:10 -06:00
void set_empty(int e){
delete empty;
empty = new Semaphore(e);
}
bool is_empty() {
return (data.size() == 0);
}
2015-11-10 15:56:32 -06:00
void push(string item);
string pop();
//can't be larger than b strings
//b = user input
};
2015-11-13 10:02:10 -06:00
#endif