Alive thread implemented
This commit is contained in:
18
shmqueue.cpp
18
shmqueue.cpp
@@ -23,6 +23,11 @@ ShmQueue::ShmQueue(Shm *shm, ShmSlot slot, bool owner)
|
||||
_queue_sem = shm->sem(buf, owner);
|
||||
}
|
||||
|
||||
void ShmQueue::takeOwnership()
|
||||
{
|
||||
_queue_sem->takeOwnership();
|
||||
}
|
||||
|
||||
ShmQueue::~ShmQueue()
|
||||
{
|
||||
if (_owner) {
|
||||
@@ -83,15 +88,14 @@ void ShmQueue::enqueue(int cmd)
|
||||
enqueue(cmd, s);
|
||||
}
|
||||
|
||||
bool ShmQueue::dequeue(int &cmd, std::string &json_data, bool wait)
|
||||
|
||||
bool ShmQueue::dequeue(int &cmd, std::string &json_data, int wait_ms)
|
||||
{
|
||||
if (wait) {
|
||||
_queue_sem->wait();
|
||||
} else {
|
||||
if (!_queue_sem->trywait()) {
|
||||
return false;
|
||||
}
|
||||
bool something_came = _queue_sem->wait(wait_ms);
|
||||
if (!something_came) {
|
||||
return false;
|
||||
}
|
||||
|
||||
_shm->lock();
|
||||
|
||||
ShmPlace item_place = _queue->first;
|
||||
|
||||
Reference in New Issue
Block a user