Commit 0ed394ab authored by Joseph Noir's avatar Joseph Noir

Fix bug in join and sleep_for

parent 5ac04156
#include <time.h>
extern "C" {
#include "vtimer.h"
}
#include <cerrno>
#include <system_error>
......@@ -22,12 +24,12 @@ void thread::join() {
"Joining this leads to a deadlock.");
}
if (joinable()) {
m_handle = thread_uninitialized;
auto status = thread_getstatus(m_handle);
if (status != STATUS_NOT_FOUND && status != STATUS_STOPPED) {
m_data->joining_thread = sched_active_pid;
thread_sleep();
}
m_handle = thread_uninitialized;
} else {
throw system_error(make_error_code(errc::invalid_argument),
"Can not join an unjoinable thread.");
......@@ -60,7 +62,6 @@ void sleep_for(const chrono::nanoseconds& ns) {
seconds s = duration_cast<seconds>(ns);
timespec ts;
using ts_sec = decltype(ts.tv_sec);
// typedef decltype(ts.tv_sec) ts_sec;
constexpr ts_sec ts_sec_max = numeric_limits<ts_sec>::max();
if (s.count() < ts_sec_max) {
ts.tv_sec = static_cast<ts_sec>(s.count());
......@@ -69,7 +70,12 @@ void sleep_for(const chrono::nanoseconds& ns) {
ts.tv_sec = ts_sec_max;
ts.tv_nsec = giga::num - 1;
}
while (nanosleep(&ts, &ts) == -1 && errno == EINTR) { ; }
timex_t reltime;
reltime.seconds = ts.tv_sec;
reltime.microseconds = ts.tv_nsec / 1000u;
vtimer_t timer;
vtimer_set_wakeup(&timer, reltime, sched_active_pid);
thread_sleep();
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment