From 2b113344a39b6b446123656bf819bd652831aece Mon Sep 17 00:00:00 2001 From: shadow8t4 Date: Fri, 6 Nov 2015 12:15:31 -0600 Subject: [PATCH 1/2] makefile updates --- BoundedBuffer.cpp | 5 +++++ BoundedBuffer.h | 5 +++-- makefile | 8 ++++++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/BoundedBuffer.cpp b/BoundedBuffer.cpp index 0447048..0aabdff 100755 --- a/BoundedBuffer.cpp +++ b/BoundedBuffer.cpp @@ -1,4 +1,9 @@ +#include "BoundedBuffer.h" +//#include +#include +#include + void BoundedBuffer::push(string item){ /* if(there is some empty slot){//data.size < b data.push_back(item); diff --git a/BoundedBuffer.h b/BoundedBuffer.h index 5d18136..93086eb 100755 --- a/BoundedBuffer.h +++ b/BoundedBuffer.h @@ -1,5 +1,7 @@ #include +#include +#include using namespace std; @@ -7,7 +9,7 @@ unsigned int n = 20, b = 100, w = 5; class BoundedBuffer{ //int b; - Semaphore *full = new Semaphore(0); //initialized to 0, Since there are 0 full slots + Semaphore full(); //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); @@ -22,7 +24,6 @@ class BoundedBuffer{ void push(string item); void pop(); - //can't be larger than b strings //b = user input diff --git a/makefile b/makefile index 13e1369..106521b 100755 --- a/makefile +++ b/makefile @@ -8,5 +8,9 @@ reqchannel.o: reqchannel.h reqchannel.cpp dataserver: dataserver.cpp reqchannel.o g++ -std=c++11 -g -o dataserver dataserver.cpp reqchannel.o -lpthread -simpleclient: simpleclient.cpp reqchannel.o - g++ -std=c++11 -g -o simpleclient simpleclient.cpp reqchannel.o +simpleclient: simpleclient.cpp reqchannel.o BoundedBuffer.cpp + g++ -std=c++11 -g -o simpleclient simpleclient.cpp reqchannel.o BoundedBuffer.cpp + +clean: + $(RM) *.o + From b2e95401bea475aec07a618aed0afbb47a003a1d Mon Sep 17 00:00:00 2001 From: shadow8t4 Date: Fri, 6 Nov 2015 12:48:11 -0600 Subject: [PATCH 2/2] Fixed compilation errors. --- BoundedBuffer.cpp | 6 ++++-- BoundedBuffer.h | 11 ++++++++--- simpleclient.cpp | 5 +++-- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/BoundedBuffer.cpp b/BoundedBuffer.cpp index 0aabdff..5d00e4c 100755 --- a/BoundedBuffer.cpp +++ b/BoundedBuffer.cpp @@ -1,5 +1,7 @@ +#include "semaphore.h" #include "BoundedBuffer.h" +//#include "semaphore.h" //#include #include #include @@ -14,10 +16,10 @@ void BoundedBuffer::push(string item){ - empty.P(); + empty->P(); data.push_back(item); - full.V();//increment the number of full slots now. + full->V();//increment the number of full slots now. } void BoundedBuffer::pop(){ diff --git a/BoundedBuffer.h b/BoundedBuffer.h index 93086eb..28ef878 100755 --- a/BoundedBuffer.h +++ b/BoundedBuffer.h @@ -1,15 +1,19 @@ + +#ifndef _BoundedBuffer_H_ +#define _BoundedBuffer_H_ + #include #include -#include +//#include using namespace std; -unsigned int n = 20, b = 100, w = 5; +extern unsigned int n, b, w; class BoundedBuffer{ //int b; - Semaphore full(); //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 *mutex = new Semaphore(1); @@ -29,3 +33,4 @@ class BoundedBuffer{ //b = user input }; +#endif \ No newline at end of file diff --git a/simpleclient.cpp b/simpleclient.cpp index 04d9e35..1700955 100755 --- a/simpleclient.cpp +++ b/simpleclient.cpp @@ -44,8 +44,6 @@ using namespace std; /* CONSTANTS */ /*--------------------------------------------------------------------------*/ -// unsigned int n = 20, b = 100, w = 5; - /* -- (none) -- */ /*--------------------------------------------------------------------------*/ @@ -62,6 +60,9 @@ int main(int argc, char * argv[]) { int option = -1; + unsigned int n; + unsigned int b; + unsigned int w; while ((option = getopt(argc, argv, "n:b:w:")) != -1){ switch (option){ case 'n' :