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

46 lines
926 B
C
Raw Normal View History

2015-11-06 11:01:19 -06:00
2015-11-06 12:48:11 -06:00
#ifndef _BoundedBuffer_H_
#define _BoundedBuffer_H_
2015-11-06 11:56:25 -06:00
#include <vector>
2015-11-06 12:15:31 -06:00
#include <string>
2015-11-06 12:48:11 -06:00
//#include <semaphore.h>
2015-11-06 11:56:25 -06:00
using namespace std;
2015-11-09 16:44:58 -06:00
//extern unsigned int n, b, w;
2015-11-06 11:01:19 -06:00
2015-11-06 11:30:46 -06:00
class BoundedBuffer{
2015-11-06 12:53:10 -06:00
2015-11-09 16:44:58 -06:00
int b_val;
2015-11-06 11:56:25 -06:00
Semaphore *full = new Semaphore(0); //initialized to 0, Since there are 0 full slots
2015-11-09 16:44:58 -06:00
Semaphore *empty;// = new Semaphore(b); //initialized to b, Since all the slots are empty
2015-11-06 11:56:25 -06:00
Semaphore *mutex = new Semaphore(1);
2015-11-06 11:30:46 -06:00
vector<string> data;
2015-11-06 11:56:25 -06:00
//BoundedBuffer(
2015-11-09 16:44:58 -06:00
public:
BoundedBuffer(){empty = new Semaphore(100);}//default b value
BoundedBuffer(int b){
b_val = b;
empty = new Semaphore(b_val);
}
2015-11-06 11:30:46 -06:00
2015-11-09 16:44:58 -06:00
void set_b(int b){ b_val = b;}
2015-11-09 17:18:35 -06:00
int get_val(){ return b_val; }
2015-11-06 11:30:46 -06:00
void push(string item);
2015-11-09 16:44:58 -06:00
string pop();
2015-11-06 11:30:46 -06:00
//can't be larger than b strings
//b = user input
2015-11-06 11:56:25 -06:00
};
2015-11-06 11:01:19 -06:00
2015-11-09 17:18:35 -06:00
#endif