Skip to content

Commit

Permalink
[fix]srqueue: get(ms) no longer return Q_NOTIME for supporting system…
Browse files Browse the repository at this point in the history
… without clock_gettime.
  • Loading branch information
Tiensbakung committed Aug 30, 2016
1 parent 81221fe commit a756ebe
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions include/srqueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <time.h>
#include <pthread.h>
#include <semaphore.h>
#include <iostream>

/**
* \class SrQueue
Expand All @@ -30,10 +29,8 @@ template<typename T> class SrQueue
*/
typedef std::pair<T, ErrCode> Event;
SrQueue(): q() {
if (pthread_mutex_init(&mutex, NULL))
std::cerr << "Mutex init failed.\n";
if (sem_init(&sem, 0, 0))
std::cerr << "Semaphore init failed.\n";
mutex = PTHREAD_MUTEX_INITIALIZER;
sem_init(&sem, 0, 0);
}
virtual ~SrQueue() {
sem_destroy(&sem);
Expand Down Expand Up @@ -77,13 +74,9 @@ template<typename T> class SrQueue
* \return the element T with error code.
*/
Event get(int millisec) {
timespec t;
timespec t = {0, 0};
Event e;
if (clock_gettime(CLOCK_REALTIME_COARSE, &t) == -1) {
e.second = Q_NOTIME;
return e;
}

clock_gettime(CLOCK_REALTIME_COARSE, &t);
t.tv_sec += millisec / 1000;
t.tv_nsec += (millisec % 1000) * 1000000;
t.tv_sec += t.tv_nsec / 1000000000;
Expand Down

0 comments on commit a756ebe

Please sign in to comment.