Commit 59b0bb35 authored by Joseph Noir's avatar Joseph Noir

Fix clock namespace issue and remove unused code

parent 774b8f16
......@@ -104,7 +104,7 @@ inline bool operator>=(const time_point& lhs, const time_point& rhs) {
namespace caf {
using time_point = std::chrono::high_resolution_clock::time_point;
inline std::chrono::time_point<std::chrono::high_resolution_clock> now() {
inline time_point<std::chrono::high_resolution_clock> now() {
return std::chrono::high_resolution_clock::now();
}
......
......@@ -28,7 +28,6 @@
#include "vtimer.h"
#include "caf/mutex.hpp"
#include "caf/chrono.hpp"
......@@ -73,17 +72,6 @@ class condition_variable {
priority_queue_t m_queue;
};
template <class T, class Rep, class Period>
inline typename std::enable_if<std::chrono::__is_duration<T>::value,T>::type
ceil(std::chrono::duration<Rep, Period> duration) {
using namespace std::chrono;
T res = duration_cast<T>(duration);
if (res < duration) {
++res;
}
return res;
}
template <class Predicate>
void condition_variable::wait(unique_lock<mutex>& lock, Predicate pred) {
while(!pred()) {
......@@ -130,8 +118,7 @@ template <class Rep, class Period, class Predicate>
inline bool condition_variable::wait_for(unique_lock<mutex>& lock,
const std::chrono::duration<Rep, Period>& timeout_duration,
Predicate pred) {
return wait_until(lock, std::chrono::steady_clock::now() + timeout_duration,
std::move(pred));
return wait_until(lock, now() + timeout_duration, std::move(pred));
}
} // namespace caf
......
......@@ -126,14 +126,14 @@ namespace this_thread {
mutex mtx;
condition_variable cv;
unique_lock<mutex> lk(mtx);
while(Clock::now() < sleep_time) {
while(now() < sleep_time) {
cv.wait_until(lk,sleep_time);
}
}
template <class Period>
inline void sleep_until(const std::chrono::time_point<std::chrono::steady_clock,
Period>& sleep_time) {
sleep_for(sleep_time - std::chrono::steady_clock::now());
sleep_for(sleep_time - now());
}
} // namespace this_thread
......
......@@ -38,7 +38,7 @@ thread::~thread() {
void thread::join() {
if (this->get_id() == this_thread::get_id()) {
throw system_error(make_error_code(errc::resource_deadlock_would_occur),
"Joining this leads to a deadlock.");
"Joining this leads to a deadlock.");
}
if (joinable()) {
auto status = thread_getstatus(m_handle);
......@@ -49,21 +49,17 @@ void thread::join() {
m_handle = thread_uninitialized;
} else {
throw system_error(make_error_code(errc::invalid_argument),
"Can not join an unjoinable thread.");
"Can not join an unjoinable thread.");
}
// missing: no_such_process system error
}
void thread::join() {
// you can't join threads
}
void thread::detach() {
if (joinable()) {
m_handle = thread_uninitialized;
} else {
throw system_error(make_error_code(errc::invalid_argument),
"Can not detach an unjoinable thread.");
"Can not detach an unjoinable thread.");
}
}
......
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