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

View file

@ -12,8 +12,6 @@ using namespace std;
//extern unsigned int n, b, w;
class BoundedBuffer{
int b_val;
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
@ -21,18 +19,14 @@ class BoundedBuffer{
vector<string> data;
public:
BoundedBuffer(){empty = new Semaphore(100);}//default b value
BoundedBuffer(){empty = new Semaphore(200);}//default b value
BoundedBuffer(int b){
b_val = b;
empty = new Semaphore(b_val);
empty = new Semaphore(b);
}
int get_val(){return b_val;}
void set_b(int b){ b_val = b;}
void set_empty(int e){empty = new Semaphore(e);}
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;
if (request.compare("quit") == 0) {
cout << "\nquit\n";
_channel.cwrite("bye");
usleep(10000); // give the other end a bit of time.
break; // break out of the loop;

6
makefile Executable file → Normal file
View file

@ -3,13 +3,13 @@
all: dataserver simpleclient
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
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
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:
$(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