Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use this_thread::sleep_for on Windows #32

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion include/realtime_tools/realtime_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
#define REALTIME_TOOLS__REALTIME_BUFFER_H_

#include <boost/thread/mutex.hpp>
#include <chrono>
#include <thread>

namespace realtime_tools
{
Expand Down Expand Up @@ -154,7 +156,9 @@ class RealtimeBuffer
mutex_.lock();
#else
while (!mutex_.try_lock())
usleep(500);
{
std::this_thread::sleep_for(std::chrono::microseconds(500));
}
#endif
}

Expand Down
18 changes: 12 additions & 6 deletions include/realtime_tools/realtime_publisher.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
#include <boost/thread/mutex.hpp>
#include <boost/thread/thread.hpp>
#include <boost/thread/condition.hpp>
#include <chrono>
#include <thread>

namespace realtime_tools {

Expand Down Expand Up @@ -78,7 +80,9 @@ class RealtimePublisher : boost::noncopyable
{
stop();
while (is_running())
usleep(100);
{
std::this_thread::sleep_for(std::chrono::microseconds(100));
}

publisher_.shutdown();
}
Expand Down Expand Up @@ -153,7 +157,9 @@ class RealtimePublisher : boost::noncopyable
#else
// never actually block on the lock
while (!msg_mutex_.try_lock())
usleep(200);
{
std::this_thread::sleep_for(std::chrono::microseconds(200));
}
#endif
}

Expand Down Expand Up @@ -190,11 +196,11 @@ class RealtimePublisher : boost::noncopyable
while (turn_ != NON_REALTIME && keep_running_)
{
#ifdef NON_POLLING
updated_cond_.wait(lock);
updated_cond_.wait(lock);
#else
unlock();
usleep(500);
lock();
unlock();
std::this_thread::sleep_for(std::chrono::microseconds(500));
lock();
#endif
}
outgoing = msg_;
Expand Down
6 changes: 5 additions & 1 deletion src/realtime_clock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
*/

#include <realtime_tools/realtime_clock.h>
#include <chrono>
#include <thread>

namespace realtime_tools
{
Expand Down Expand Up @@ -126,7 +128,9 @@ namespace realtime_tools
mutex_.lock();
#else
while (!mutex_.try_lock())
usleep(500);
{
std::this_thread::sleep_for(std::chrono::microseconds(500));
}
#endif
}

Expand Down