Fix shit.

This commit is contained in:
shadow8t4 2015-11-11 17:15:35 -06:00
parent 79337b06bd
commit 98ddf2063f
7 changed files with 18 additions and 21 deletions

View file

@ -5,7 +5,6 @@
#include <vector> #include <vector>
void BoundedBuffer::push(string item){ void BoundedBuffer::push(string item){
empty->P(); empty->P();
mutex->P(); mutex->P();
data.push_back(item); data.push_back(item);
@ -14,12 +13,17 @@ void BoundedBuffer::push(string item){
} }
string BoundedBuffer::pop(){ string BoundedBuffer::pop(){
string item = data.back(); if(data.size() > 0){
full->P(); full->P();
mutex->P(); mutex->P();
data.pop_back(); string item = data.back();
mutex->V(); data.pop_back();
empty->V(); mutex->V();
return item; empty->V();
return item;
}else{
return "quit";
}
} }

View file

@ -12,8 +12,6 @@ using namespace std;
//extern unsigned int n, b, w; //extern unsigned int n, b, w;
class BoundedBuffer{ class BoundedBuffer{
int b_val;
Semaphore *full = new Semaphore(0); //initialized to 0, Since there are 0 full slots 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 *empty;// = new Semaphore(b); //initialized to b, Since all the slots are empty
@ -21,18 +19,14 @@ class BoundedBuffer{
vector<string> data; vector<string> data;
public: public:
BoundedBuffer(){empty = new Semaphore(100);}//default b value BoundedBuffer(){empty = new Semaphore(200);}//default b value
BoundedBuffer(int b){ BoundedBuffer(int b){
b_val = b; empty = new Semaphore(b);
empty = new Semaphore(b_val);
} }
int get_val(){return b_val;} void set_empty(int e){empty = new Semaphore(e);}
void set_b(int b){ b_val = b;}
void push(string item); void push(string item);

1
dataserver.cpp Executable file → Normal file
View file

@ -158,7 +158,6 @@ void handle_process_loop(RequestChannel & _channel) {
cout << "New request is " << request << endl; cout << "New request is " << request << endl;
if (request.compare("quit") == 0) { if (request.compare("quit") == 0) {
cout << "\nquit\n";
_channel.cwrite("bye"); _channel.cwrite("bye");
usleep(10000); // give the other end a bit of time. usleep(10000); // give the other end a bit of time.
break; // break out of the loop; break; // break out of the loop;

6
makefile Executable file → Normal file
View file

@ -3,13 +3,13 @@
all: dataserver simpleclient all: dataserver simpleclient
reqchannel.o: reqchannel.h reqchannel.cpp reqchannel.o: reqchannel.h reqchannel.cpp
g++ -std=c++11 -c -g reqchannel.cpp g++ -std=c++11 -lpthread -c -g reqchannel.cpp
dataserver: dataserver.cpp reqchannel.o dataserver: dataserver.cpp reqchannel.o
g++ -std=c++11 -g -o dataserver dataserver.cpp reqchannel.o -lpthread g++ -std=c++11 -lpthread -g -o dataserver dataserver.cpp reqchannel.o
simpleclient: simpleclient.cpp reqchannel.o BoundedBuffer.cpp simpleclient: simpleclient.cpp reqchannel.o BoundedBuffer.cpp
g++ -std=c++11 -g -o simpleclient simpleclient.cpp reqchannel.o BoundedBuffer.cpp g++ -std=c++11 -lpthread -g -o simpleclient simpleclient.cpp reqchannel.o BoundedBuffer.cpp
clean: clean:
$(RM) *.o $(RM) *.o

0
reqchannel.cpp Executable file → Normal file
View file

0
reqchannel.h Executable file → Normal file
View file

0
semaphore.h Executable file → Normal file
View file