29 lines
No EOL
553 B
C++
29 lines
No EOL
553 B
C++
|
|
#include "semaphore.h"
|
|
#include "BoundedBuffer.h"
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
void BoundedBuffer::push(string item){
|
|
empty->P();
|
|
mutex->P();
|
|
data.push_back(item);
|
|
mutex->V();
|
|
full->V();//increment the number of full slots now.
|
|
}
|
|
|
|
string BoundedBuffer::pop(){
|
|
if(data.size() > 0){
|
|
full->P();
|
|
mutex->P();
|
|
string item = data.back();
|
|
data.pop_back();
|
|
mutex->V();
|
|
empty->V();
|
|
return item;
|
|
}else{
|
|
return "quit";
|
|
}
|
|
|
|
}
|
|
|