Add possibility to wait several times on a semaphore
This commit is contained in:
@ -17,13 +17,14 @@
|
||||
namespace maxscale
|
||||
{
|
||||
|
||||
bool Semaphore::timedwait(time_t seconds,
|
||||
long nseconds,
|
||||
signal_approach_t signal_approach) const
|
||||
//static
|
||||
void Semaphore::get_current_timespec(time_t seconds,
|
||||
long nseconds,
|
||||
timespec* pTs)
|
||||
{
|
||||
ss_dassert(nseconds <= 999999999);
|
||||
|
||||
timespec ts;
|
||||
timespec& ts = *pTs;
|
||||
|
||||
ss_debug(int rc=) clock_gettime(CLOCK_REALTIME, &ts);
|
||||
ss_dassert(rc == 0);
|
||||
@ -39,8 +40,6 @@ bool Semaphore::timedwait(time_t seconds,
|
||||
}
|
||||
|
||||
ts.tv_nsec = nseconds_sum;
|
||||
|
||||
return timedwait(ts, signal_approach);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -65,6 +65,14 @@ void test_simple()
|
||||
ss_dassert(rv);
|
||||
cout << "Waited" << endl;
|
||||
|
||||
sem2.post();
|
||||
sem2.post();
|
||||
sem2.post();
|
||||
|
||||
cout << "Waiting 3 times for semaphore with a count of 3." << endl;
|
||||
rv = sem2.wait_n(3);
|
||||
cout << "Waited" << endl;
|
||||
|
||||
Semaphore sem3;
|
||||
|
||||
time_t started;
|
||||
@ -118,10 +126,7 @@ void test_threads()
|
||||
|
||||
cout << "Waiting for threads." << endl;
|
||||
|
||||
for (int i = 0; i < n_threads; ++i)
|
||||
{
|
||||
sem.wait();
|
||||
}
|
||||
sem.wait_n(n_threads);
|
||||
|
||||
cout << "Joining threads." << endl;
|
||||
|
||||
|
Reference in New Issue
Block a user