MXS-2017 Move maxscale::Semaphore to maxbase::Semaphore
This commit is contained in:
@ -31,7 +31,7 @@ MXB_BEGIN_DECLS
|
||||
|
||||
#define mxb_assert_message(exp,message) do { if(!(exp)){ \
|
||||
const char *debug_expr = #exp; \
|
||||
MXS_ERROR("debug assert at %s:%d failed: %s (%s)\n", (char*)__FILE__, __LINE__, message, debug_expr); \
|
||||
MXB_ERROR("debug assert at %s:%d failed: %s (%s)\n", (char*)__FILE__, __LINE__, message, debug_expr); \
|
||||
fprintf(stderr, "debug assert at %s:%d failed: %s (%s)\n", (char*)__FILE__, __LINE__, message, debug_expr); \
|
||||
raise(SIGABRT);} } while (false)
|
||||
|
||||
|
||||
384
maxutils/maxbase/include/maxbase/semaphore.hh
Normal file
384
maxutils/maxbase/include/maxbase/semaphore.hh
Normal file
@ -0,0 +1,384 @@
|
||||
#pragma once
|
||||
/*
|
||||
* Copyright (c) 2016 MariaDB Corporation Ab
|
||||
*
|
||||
* Use of this software is governed by the Business Source License included
|
||||
* in the LICENSE.TXT file and at www.mariadb.com/bsl11.
|
||||
*
|
||||
* Change Date: 2022-01-01
|
||||
*
|
||||
* On the date above, in accordance with the Business Source License, use
|
||||
* of this software will be governed by version 2 or later of the General
|
||||
* Public License.
|
||||
*/
|
||||
|
||||
#include <maxbase/ccdefs.hh>
|
||||
#include <cerrno>
|
||||
#include <climits>
|
||||
#include <maxbase/assert.h>
|
||||
#include <maxbase/semaphore.h>
|
||||
|
||||
namespace maxbase
|
||||
{
|
||||
|
||||
class Semaphore
|
||||
{
|
||||
Semaphore(const Semaphore&) = delete;
|
||||
Semaphore& operator = (const Semaphore&) = delete;
|
||||
|
||||
public:
|
||||
enum signal_approach_t
|
||||
{
|
||||
HONOUR_SIGNALS, /* Honour signals and return when interrupted. */
|
||||
IGNORE_SIGNALS /* Ignore signals and re-issue the comment when signals occur. */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Constructor
|
||||
*
|
||||
* @param initial_count The initial count of the semaphore.
|
||||
*
|
||||
* @attention If the value `initial_count` is larger than `SEM_VALUE_MAX`,
|
||||
* the the value will be adjusted down to `SEM_VALUE_MAX`.
|
||||
*/
|
||||
Semaphore(uint32_t initial_count = 0)
|
||||
{
|
||||
if (initial_count > SEM_VALUE_MAX)
|
||||
{
|
||||
initial_count = SEM_VALUE_MAX;
|
||||
}
|
||||
|
||||
MXB_AT_DEBUG(int rc =) sem_init(&m_sem, 0, initial_count);
|
||||
mxb_assert(rc == 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Destructor
|
||||
*
|
||||
* When the semaphore is destructed, its count should be 0 and nobody
|
||||
* should be waiting on it.
|
||||
*/
|
||||
~Semaphore()
|
||||
{
|
||||
#ifdef SS_DEBUG
|
||||
int count;
|
||||
int rc = sem_getvalue(&m_sem, &count);
|
||||
mxb_assert(rc == 0);
|
||||
mxb_assert(count == 0);
|
||||
#endif
|
||||
MXB_AT_DEBUG(rc =) sem_destroy(&m_sem);
|
||||
mxb_assert(rc == 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Post the semaphore.
|
||||
*
|
||||
* Increments the semaphore. If others threads were blocked in `wait`
|
||||
* one of them will subsequently return.
|
||||
*
|
||||
* @return `True` if the semaphore could be posed, otherwise `false`.
|
||||
* If `false` is returned, then the maximum count of the sempahore
|
||||
* has been reached.
|
||||
*/
|
||||
bool post() const
|
||||
{
|
||||
int rc = sem_post(&m_sem);
|
||||
mxb_assert((rc == 0) || (errno == EOVERFLOW));
|
||||
#ifdef SS_DEBUG
|
||||
if ((rc != 0) && (errno == EOVERFLOW))
|
||||
{
|
||||
mxb_assert_message(!true, "Semaphore overflow; indicates endless loop.");
|
||||
}
|
||||
#endif
|
||||
return rc == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Waits on the semaphore.
|
||||
*
|
||||
* If the semaphore count is greater than zero, decrements the count and
|
||||
* returns immediately. Otherwise blocks the caller until someone posts
|
||||
* the semaphore.
|
||||
*
|
||||
* @param signal_approach Whether signals should be ignored or honoured.
|
||||
*
|
||||
* @return `True` if the semaphore was waited for, `false` otherwise.
|
||||
*
|
||||
* @attention The function can return `false` only if `signal_approach`
|
||||
* is `HONOUR_SIGNALS`.
|
||||
*/
|
||||
bool wait(signal_approach_t signal_approach = IGNORE_SIGNALS) const
|
||||
{
|
||||
int rc;
|
||||
do
|
||||
{
|
||||
rc = sem_wait(&m_sem);
|
||||
}
|
||||
while ((rc != 0) && ((errno == EINTR) && (signal_approach == IGNORE_SIGNALS)));
|
||||
|
||||
mxb_assert((rc == 0) || ((errno == EINTR) && (signal_approach == HONOUR_SIGNALS)));
|
||||
|
||||
return rc == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Waits multiple times on the semaphore.
|
||||
*
|
||||
* If the semaphore count is greater than or equal to the specified amount,
|
||||
* decrements the count and returns immediately. Otherwise blocks the caller
|
||||
* until the semaphore has been posted the required number of times.
|
||||
*
|
||||
* @param n_wait How many times should be waited.
|
||||
* @param signal_approach Whether signals should be ignored or honoured.
|
||||
*
|
||||
* @return How many times the semaphore has been waited on.
|
||||
*
|
||||
* @attention The function can return a different number than `n_wait` only
|
||||
* if `signal_approach` is `HONOUR_SIGNALS`.
|
||||
*/
|
||||
size_t wait_n(size_t n_wait,
|
||||
signal_approach_t signal_approach = IGNORE_SIGNALS) const
|
||||
{
|
||||
bool waited = true;
|
||||
size_t n_waited = 0;
|
||||
|
||||
while (waited && n_wait--)
|
||||
{
|
||||
waited = wait(signal_approach);
|
||||
if (waited)
|
||||
{
|
||||
++n_waited;
|
||||
}
|
||||
}
|
||||
|
||||
return n_waited;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Waits on the semaphore.
|
||||
*
|
||||
* If the semaphore count is greater that zero, decrements the count and
|
||||
* returns immediately.
|
||||
*
|
||||
* @param signal_approach Whether signals should be ignored or honoured.
|
||||
*
|
||||
* @return `True` if the semaphore was waited for, `false` otherwise.
|
||||
*
|
||||
* @attention If the function returns `false` and `signal_approch` is
|
||||
* `HONOUR_SIGNALS` then the caller must check the value of
|
||||
* `errno` to find out whether the call was timed out or
|
||||
* interrupted. In the former case the value will be `EAGAIN`
|
||||
* and in the latter `EINTR`.
|
||||
*/
|
||||
bool trywait(signal_approach_t signal_approach = IGNORE_SIGNALS) const
|
||||
{
|
||||
errno = 0;
|
||||
|
||||
int rc;
|
||||
do
|
||||
{
|
||||
rc = sem_trywait(&m_sem);
|
||||
}
|
||||
while ((rc != 0) && ((errno == EINTR) && (signal_approach == IGNORE_SIGNALS)));
|
||||
|
||||
mxb_assert((rc == 0) ||
|
||||
(errno == EAGAIN) ||
|
||||
((errno == EINTR) && (signal_approach == HONOUR_SIGNALS)));
|
||||
|
||||
return rc == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Waits on the semaphore.
|
||||
*
|
||||
* Waits on the sempahore at most until the specified time.
|
||||
*
|
||||
* @param ts The *absolute* time until which the waiting at
|
||||
* most is performed.
|
||||
* @param signal_approach Whether signals should be ignored or honoured.
|
||||
*
|
||||
* @return True if the waiting could be performed, false otherwise.
|
||||
*
|
||||
* @attention If the function returns `false` and `signal_approch` is
|
||||
* `HONOUR_SIGNALS` then the caller must check the value of
|
||||
* `errno` to find out whether the call was timed out or
|
||||
* interrupted. In the former case the value will be `ETIMEDOUT`
|
||||
* and in the latter `EINTR.
|
||||
*/
|
||||
bool timedwait(struct timespec& ts,
|
||||
signal_approach_t signal_approach = IGNORE_SIGNALS) const
|
||||
{
|
||||
errno = 0;
|
||||
|
||||
int rc;
|
||||
do
|
||||
{
|
||||
rc = sem_timedwait(&m_sem, &ts);
|
||||
}
|
||||
while ((rc != 0) && ((errno == EINTR) && (signal_approach == IGNORE_SIGNALS)));
|
||||
|
||||
mxb_assert((rc == 0) ||
|
||||
(errno == ETIMEDOUT) ||
|
||||
((errno == EINTR) && (signal_approach == HONOUR_SIGNALS)));
|
||||
|
||||
return rc == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Waits on the semaphore.
|
||||
*
|
||||
* Waits on the sempahore the specified number of times, at most until the
|
||||
* specified time.
|
||||
*
|
||||
* @param n_wait How many times should be waited.
|
||||
* @param ts The *absolute* time until which the waiting at
|
||||
* most is performed.
|
||||
* @param signal_approach Whether signals should be ignored or honoured.
|
||||
*
|
||||
* @return How many times the semaphore has been waited on. If the
|
||||
* function times out or is interrupted, then the returned
|
||||
* value will be less than `n_wait`.
|
||||
*
|
||||
* @attention If the function returns a value less than `n_count` and
|
||||
* `signal_approch` is `HONOUR_SIGNALS` then the caller must check
|
||||
* the value of `errno` to find out whether the call was timed out or
|
||||
* interrupted. In the former case the value will be `ETIMEDOUT`
|
||||
* and in the latter `EINTR.
|
||||
*/
|
||||
size_t timedwait_n(size_t n_wait,
|
||||
struct timespec& ts,
|
||||
signal_approach_t signal_approach = IGNORE_SIGNALS) const
|
||||
{
|
||||
bool waited = true;
|
||||
size_t n_waited = 0;
|
||||
|
||||
while (waited && n_wait--)
|
||||
{
|
||||
waited = timedwait(ts, signal_approach);
|
||||
if (waited)
|
||||
{
|
||||
++n_waited;
|
||||
}
|
||||
}
|
||||
|
||||
return n_waited;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Waits on the semaphore.
|
||||
*
|
||||
* Waits on the sempahore at most until the specified amount of time
|
||||
* has passed.
|
||||
*
|
||||
* @param seconds How many seconds to wait at most.
|
||||
* @param nseconds How many nanonseconds to wait at most.
|
||||
* @param signal_approach Whether signals should be ignored or honoured.
|
||||
*
|
||||
* @return True if the waiting could be performed, false otherwise.
|
||||
*
|
||||
* @attention `nseconds` must be less than 1000000000.
|
||||
*
|
||||
* @attention If the function returns `false` and `signal_approch` is
|
||||
* `HONOUR_SIGNALS` then the caller must check the value of
|
||||
* `errno` to find out whether the call was timed out or
|
||||
* interrupted. In the former case the value will be `ETIMEDOUT`
|
||||
* and in the latter `EINTR.
|
||||
*/
|
||||
bool timedwait(time_t seconds,
|
||||
long nseconds,
|
||||
signal_approach_t signal_approach = IGNORE_SIGNALS) const
|
||||
{
|
||||
timespec ts;
|
||||
get_current_timespec(seconds, nseconds, &ts);
|
||||
return timedwait(ts, signal_approach);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Waits on the semaphore.
|
||||
*
|
||||
* Waits on the sempahore the specified number of times at most until the
|
||||
* specified time.
|
||||
*
|
||||
* @param n_wait How many times should be waited.
|
||||
* @param seconds How many seconds to wait at most.
|
||||
* @param nseconds How many nanonseconds to wait at most.
|
||||
* @param signal_approach Whether signals should be ignored or honoured.
|
||||
*
|
||||
* @return How many times the semaphore has been waited on. If the
|
||||
* function times out or is interrupted, then the returned
|
||||
* value will be less than `n_wait`.
|
||||
*
|
||||
* @attention If the function returns a value less than `n_count` and
|
||||
* `signal_approch` is `HONOUR_SIGNALS` then the caller must check
|
||||
* the value of `errno` to find out whether the call was timed out or
|
||||
* interrupted. In the former case the value will be `ETIMEDOUT`
|
||||
* and in the latter `EINTR.
|
||||
*/
|
||||
size_t timedwait_n(size_t n_wait,
|
||||
time_t seconds,
|
||||
long nseconds,
|
||||
signal_approach_t signal_approach = IGNORE_SIGNALS) const
|
||||
{
|
||||
timespec ts;
|
||||
get_current_timespec(seconds, nseconds, &ts);
|
||||
return timedwait_n(n_wait, ts, signal_approach);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Waits on the semaphore.
|
||||
*
|
||||
* Waits on the sempahore at most until the specified amount of time
|
||||
* has passed.
|
||||
*
|
||||
* @param seconds How many seconds to wait at most.
|
||||
* @param signal_approach Whether signals should be ignored or honoured.
|
||||
*
|
||||
* @return True if the waiting could be performed, false otherwise.
|
||||
*
|
||||
* @attention If the function returns `false` and `signal_approch` is
|
||||
* `HONOUR_SIGNALS` then the caller must check the value of
|
||||
* `errno` to find out whether the call was timed out or
|
||||
* interrupted. In the former case the value will be `ETIMEDOUT`
|
||||
* and in the latter `EINTR.
|
||||
*/
|
||||
bool timedwait(time_t seconds,
|
||||
signal_approach_t signal_approach = IGNORE_SIGNALS) const
|
||||
{
|
||||
return timedwait(seconds, 0, signal_approach);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Waits on the semaphore.
|
||||
*
|
||||
* Waits on the sempahore the specified number of times at most until the
|
||||
* specified time.
|
||||
*
|
||||
* @param n_wait How many times should be waited.
|
||||
* @param seconds How many seconds to wait at most.
|
||||
* @param signal_approach Whether signals should be ignored or honoured.
|
||||
*
|
||||
* @return How many times the semaphore has been waited on. If the
|
||||
* function times out or is interrupted, then the returned
|
||||
* value will be less than `n_wait`.
|
||||
*
|
||||
* @attention If the function returns a value less than `n_count` and
|
||||
* `signal_approch` is `HONOUR_SIGNALS` then the caller must check
|
||||
* the value of `errno` to find out whether the call was timed out or
|
||||
* interrupted. In the former case the value will be `ETIMEDOUT`
|
||||
* and in the latter `EINTR.
|
||||
*/
|
||||
bool timedwait_n(size_t n_wait,
|
||||
time_t seconds,
|
||||
signal_approach_t signal_approach = IGNORE_SIGNALS) const
|
||||
{
|
||||
return timedwait_n(n_wait, seconds, 0, signal_approach);
|
||||
}
|
||||
|
||||
private:
|
||||
static void get_current_timespec(time_t seconds, long nseconds, timespec* pTs);
|
||||
|
||||
private:
|
||||
mutable sem_t m_sem;
|
||||
};
|
||||
|
||||
}
|
||||
@ -3,6 +3,7 @@ add_library(maxbase STATIC
|
||||
eventcount.cc
|
||||
log.cc
|
||||
logger.cc
|
||||
semaphore.cc
|
||||
stopwatch.cc
|
||||
string.cc
|
||||
stacktrace.cc
|
||||
|
||||
45
maxutils/maxbase/src/semaphore.cc
Normal file
45
maxutils/maxbase/src/semaphore.cc
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2016 MariaDB Corporation Ab
|
||||
*
|
||||
* Use of this software is governed by the Business Source License included
|
||||
* in the LICENSE.TXT file and at www.mariadb.com/bsl11.
|
||||
*
|
||||
* Change Date: 2022-01-01
|
||||
*
|
||||
* On the date above, in accordance with the Business Source License, use
|
||||
* of this software will be governed by version 2 or later of the General
|
||||
* Public License.
|
||||
*/
|
||||
|
||||
#include <maxbase/semaphore.hh>
|
||||
#include <time.h>
|
||||
|
||||
namespace maxbase
|
||||
{
|
||||
|
||||
//static
|
||||
void Semaphore::get_current_timespec(time_t seconds,
|
||||
long nseconds,
|
||||
timespec* pTs)
|
||||
{
|
||||
mxb_assert(nseconds <= 999999999);
|
||||
|
||||
timespec& ts = *pTs;
|
||||
|
||||
MXB_AT_DEBUG(int rc = ) clock_gettime(CLOCK_REALTIME, &ts);
|
||||
mxb_assert(rc == 0);
|
||||
|
||||
ts.tv_sec += seconds;
|
||||
|
||||
uint64_t nseconds_sum = ts.tv_nsec + nseconds;
|
||||
|
||||
if (nseconds_sum > 1000000000)
|
||||
{
|
||||
ts.tv_sec += 1;
|
||||
nseconds_sum -= 1000000000;
|
||||
}
|
||||
|
||||
ts.tv_nsec = nseconds_sum;
|
||||
}
|
||||
|
||||
}
|
||||
@ -2,3 +2,7 @@ add_executable(test_mxb_log test_log.cc)
|
||||
target_link_libraries(test_mxb_log maxbase)
|
||||
add_test(test_mxb_log test_mxb_log)
|
||||
|
||||
add_executable(test_semaphore test_semaphore.cc)
|
||||
target_link_libraries(test_semaphore maxbase pthread)
|
||||
add_test(test_semaphore test_semaphore)
|
||||
|
||||
|
||||
194
maxutils/maxbase/src/test/test_semaphore.cc
Normal file
194
maxutils/maxbase/src/test/test_semaphore.cc
Normal file
@ -0,0 +1,194 @@
|
||||
/*
|
||||
* Copyright (c) 2016 MariaDB Corporation Ab
|
||||
*
|
||||
* Use of this software is governed by the Business Source License included
|
||||
* in the LICENSE.TXT file and at www.mariadb.com/bsl11.
|
||||
*
|
||||
* Change Date: 2022-01-01
|
||||
*
|
||||
* On the date above, in accordance with the Business Source License, use
|
||||
* of this software will be governed by version 2 or later of the General
|
||||
* Public License.
|
||||
*/
|
||||
|
||||
#if !defined(SS_DEBUG)
|
||||
#define SS_DEBUG
|
||||
#endif
|
||||
#if defined(NDEBUG)
|
||||
#undef NDEBUG
|
||||
#endif
|
||||
|
||||
#include <maxbase/ccdefs.hh>
|
||||
#include <signal.h>
|
||||
#include <ctime>
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
#include <maxbase/semaphore.hh>
|
||||
|
||||
using namespace maxbase;
|
||||
using namespace std;
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
void test_simple()
|
||||
{
|
||||
bool rv;
|
||||
Semaphore sem1(1);
|
||||
|
||||
cout << "Waiting for semaphore with a count of 1." << endl;
|
||||
rv = sem1.wait();
|
||||
mxb_assert(rv);
|
||||
cout << "Waited" << endl;
|
||||
|
||||
Semaphore sem2(3);
|
||||
|
||||
cout << "Waiting 3 times for semaphore with a count of 3." << endl;
|
||||
rv = sem2.wait();
|
||||
mxb_assert(rv);
|
||||
rv = sem2.wait();
|
||||
mxb_assert(rv);
|
||||
rv = sem2.wait();
|
||||
mxb_assert(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();
|
||||
mxb_assert(rv);
|
||||
rv = sem2.wait();
|
||||
mxb_assert(rv);
|
||||
rv = sem2.wait();
|
||||
mxb_assert(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;
|
||||
time_t finished;
|
||||
time_t diff;
|
||||
|
||||
cout << "Waiting 3 seconds for semaphore with a count of 0..." << endl;
|
||||
started = time(NULL);
|
||||
rv = sem3.timedwait(4);
|
||||
finished = time(NULL);
|
||||
diff = finished - started;
|
||||
mxb_assert(!rv);
|
||||
mxb_assert((diff >= 2) && (diff <= 4));
|
||||
cout << "Waited." << endl;
|
||||
|
||||
cout << "Waiting 1 second for semaphore with a count of 0..." << endl;
|
||||
started = time(NULL);
|
||||
rv = sem3.timedwait(0, 999999999);
|
||||
finished = time(NULL);
|
||||
diff = finished - started;
|
||||
mxb_assert(!rv);
|
||||
mxb_assert((diff >= 0) && (diff <= 2));
|
||||
cout << "Waited." << endl;
|
||||
}
|
||||
|
||||
void* thread_main(void* pArg)
|
||||
{
|
||||
Semaphore* pSem = static_cast<Semaphore*>(pArg);
|
||||
|
||||
cout << "Hello from thread" << endl;
|
||||
sleep(1);
|
||||
|
||||
pSem->post();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void test_threads()
|
||||
{
|
||||
const int n_threads = 10;
|
||||
std::thread threads[n_threads];
|
||||
|
||||
Semaphore sem;
|
||||
|
||||
cout << "Starting threads." << endl;
|
||||
|
||||
for (int i = 0; i < n_threads; ++i)
|
||||
{
|
||||
threads[i] = std::thread(thread_main, &sem);
|
||||
}
|
||||
|
||||
cout << "Waiting for threads." << endl;
|
||||
|
||||
sem.wait_n(n_threads);
|
||||
|
||||
cout << "Joining threads." << endl;
|
||||
|
||||
for (int i = 0; i < n_threads; ++i)
|
||||
{
|
||||
threads[i].join();
|
||||
}
|
||||
|
||||
cout << "Joined." << endl;
|
||||
}
|
||||
|
||||
void send_signal()
|
||||
{
|
||||
cout << "Sleeping 2 seconds." << endl;
|
||||
sleep(2);
|
||||
|
||||
cout << "Sending signal" << endl;
|
||||
kill(getpid(), SIGTERM);
|
||||
cout << "Sent signal" << endl;
|
||||
}
|
||||
|
||||
void sighandler(int s)
|
||||
{
|
||||
}
|
||||
|
||||
void test_signal()
|
||||
{
|
||||
Semaphore sem;
|
||||
|
||||
signal(SIGTERM, sighandler);
|
||||
|
||||
std::thread thread(send_signal);
|
||||
|
||||
bool waited;
|
||||
|
||||
cout << "Waiting" << endl;
|
||||
waited = sem.timedwait(4, Semaphore::HONOUR_SIGNALS);
|
||||
cout << "Waited" << endl;
|
||||
|
||||
// Should return false and errno should be EINTR.
|
||||
mxb_assert(!waited && (errno == EINTR));
|
||||
|
||||
thread.join();
|
||||
|
||||
thread = std::thread(send_signal);
|
||||
|
||||
cout << "Waiting" << endl;
|
||||
waited = sem.timedwait(4, Semaphore::IGNORE_SIGNALS);
|
||||
cout << "Waited" << endl;
|
||||
|
||||
// Should return false and errno should be ETIMEDOUT.
|
||||
mxb_assert(!waited && (errno == ETIMEDOUT));
|
||||
|
||||
thread.join();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
test_simple();
|
||||
test_threads();
|
||||
test_signal();
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
Reference in New Issue
Block a user