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.cpp
Eric Buxkemper b9476e9db1 s
2015-11-13 10:05:10 -06:00

39 lines
No EOL
762 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(){
<<<<<<< HEAD
if(data.size() > 0){
full->P();
mutex->P();
string item = data.back();
data.pop_back();
mutex->V();
empty->V();
return item;
}else{
return "quit";
}
=======
full->P();
mutex->P();
string item = data.back();
data.pop_back();
mutex->V();
empty->V();
return item;
>>>>>>> 05aaecdb17812b161db2168b80a19fc2c783800b
}