本文整理汇总了C++中std::atomic_bool::load方法的典型用法代码示例。如果您正苦于以下问题:C++ atomic_bool::load方法的具体用法?C++ atomic_bool::load怎么用?C++ atomic_bool::load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::atomic_bool
的用法示例。
在下文中一共展示了atomic_bool::load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: cmdVelReceived
void cmdVelReceived(const geometry_msgs::Twist::ConstPtr& cmd_vel)
{
std::cout << "cmdVel Received: speed = " << cmd_vel->linear.x << " angular = " << cmd_vel->angular.z << std::endl;
if(bumper_warning.load()) roomba->drive(-0.2, 0);
else if(ir_warning.load()) roomba->drive(0, cmd_vel->angular.z);
else roomba->drive(cmd_vel->linear.x,cmd_vel->angular.z);
}
示例2: thread_func
void thread_pool::thread_func(std::atomic_bool & stop_request)
{
std::unique_lock<std::mutex> lk(m_mutex, std::defer_lock);
for (;;)
{
ext::intrusive_ptr<task_base> task_ptr;
lk.lock();
if (stop_request.load(std::memory_order_relaxed)) return;
if (!m_tasks.empty()) goto avail;
again:
m_event.wait(lk);
if (stop_request.load(std::memory_order_relaxed)) return;
if (m_tasks.empty()) goto again;
avail:
task_ptr.reset(&m_tasks.front(), ext::noaddref);
m_tasks.pop_front();
lk.unlock();
task_ptr->execute();
}
}
示例3: addAndSetTime
// ------------------------------------------------------------------------
void addAndSetTime(uint32_t ping, uint64_t server_time)
{
if (m_synchronised.load() == true)
return;
if (m_force_set_timer.load() == true)
{
m_force_set_timer.store(false);
m_synchronised.store(true);
STKHost::get()->setNetworkTimer(server_time + (uint64_t)(ping / 2));
return;
}
const uint64_t cur_time = StkTime::getMonoTimeMs();
// Discard too close time compared to last ping
// (due to resend when packet loss)
// 10 packets per second as seen in STKHost
const uint64_t frequency = (uint64_t)((1.0f / 10.0f) * 1000.0f) / 2;
if (!m_times.empty() &&
cur_time - std::get<2>(m_times.back()) < frequency)
return;
// Take max 20 averaged samples from m_times, the next addAndGetTime
// is used to determine that server_time if it's correct, if not
// clear half in m_times until it's correct
if (m_times.size() >= 20)
{
uint64_t sum = std::accumulate(m_times.begin(), m_times.end(),
(uint64_t)0, [cur_time](const uint64_t previous,
const std::tuple<uint32_t, uint64_t, uint64_t>& b)->uint64_t
{
return previous + (uint64_t)(std::get<0>(b) / 2) +
std::get<1>(b) + cur_time - std::get<2>(b);
});
const int64_t averaged_time = sum / 20;
const int64_t server_time_now = server_time + (uint64_t)(ping / 2);
int difference = (int)std::abs(averaged_time - server_time_now);
if (std::abs(averaged_time - server_time_now) <
UserConfigParams::m_timer_sync_difference_tolerance)
{
STKHost::get()->setNetworkTimer(averaged_time);
m_times.clear();
m_force_set_timer.store(false);
m_synchronised.store(true);
Log::info("NetworkTimerSynchronizer", "Network "
"timer synchronized, difference: %dms", difference);
return;
}
m_times.erase(m_times.begin(), m_times.begin() + 10);
}
m_times.emplace_back(ping, server_time, cur_time);
}
示例4: wait_ready
bool fiber_waiter::wait_ready(std::chrono::steady_clock::duration timeout_duration) noexcept
{
if (gth_thread_type == thread_type::thread)
{
std::unique_lock<std::mutex> lk(m_thread_mutex);
return m_thread_var.wait_for(lk, timeout_duration, [this] { return m_ready.load(std::memory_order_relaxed); });
}
else
{
std::unique_lock<boost::fibers::mutex> lk(m_fiber_mutex);
return m_fiber_var.wait_for(lk, timeout_duration, [this] { return m_ready.load(std::memory_order_relaxed); });
}
}
示例5:
progressIndicatorThreadWrapper( const std::chrono::nanoseconds& updateInterval )
{
m_stopCondition.store( false );
m_thread = std::thread( [this, &updateInterval]
{
FormattedPrint::On(std::cout, false).app(" ");
int slashIndex = 0;
while( ! m_stopCondition.load() )
{
FormattedPrint::On(std::cout, false).app("\b\b\b \b")
.color( Green )
.app('[')
.color( Yellow )
.app( slashes[ slashIndex++ ] )
.color( Green )
.app(']')
.color();
slashIndex = slashIndex % 4;
std::this_thread::sleep_for( updateInterval );
}
FormattedPrint::On(std::cout, false).app("\b\b\b");
});
}
示例6: gstate_update_func
void gstate_update_func()
{
POINT p;
int mButton;
if(GetSystemMetrics(SM_SWAPBUTTON))
mButton = VK_RBUTTON; // if swapped
else
mButton = VK_LBUTTON; // not swapped (normal)
int screenWidth = GetSystemMetrics( SM_CXSCREEN );
int screenHeight = GetSystemMetrics( SM_CYSCREEN );
// default: SM_CX/CYSCREEN gets the size of a primary screen.
// lines uncommented below are just for a specially need on multi-display.
//int screenWidth = GetSystemMetrics( SM_CXVIRTUALSCREEN );
//int screenHeight = GetSystemMetrics( SM_CYVIRTUALSCREEN );
float r_screenWidth = 1.f / (float)(screenWidth -1);
float r_screenHeight = 1.f / (float)(screenHeight -1);
while ( inputThreadRunning.load( std::memory_order_relaxed ) ) {
// "KeyState" is disabled for now, on Windows...
//GetKey((long*)gstate->keys);
GetCursorPos(&p);
gMouseUGenGlobals.mouseX = (float)p.x * r_screenWidth;
gMouseUGenGlobals.mouseY = 1.f - (float)p.y * r_screenHeight;
gMouseUGenGlobals.mouseButton = (GetKeyState(mButton) < 0);
std::this_thread::sleep_for( std::chrono::milliseconds( 17 ) );
}
}
示例7: example1_rx
bool example1_rx(const std::string& dataaddress, unsigned short dataport, std::atomic_bool& stopFlag)
{
SuperBlock rxBlock;
uint8_t rawBlock[sizeof(SuperBlock)];
int rawBlockSize;
UDPSocket rxSocket(dataport);
std::string senderaddress, senderaddress0;
unsigned short senderport, senderport0 = 0;
Example1Rx ex1(nbSamplesPerBlock, nbOriginalBlocks, nbRecoveryBlocks);
std::cerr << "example1_rx: receiving on address: " << dataaddress << " port: " << (int) dataport << std::endl;
while (!stopFlag.load())
{
rawBlockSize = 0;
while (rawBlockSize < sizeof(SuperBlock))
{
rawBlockSize += rxSocket.RecvDataGram((void *) &rawBlock[rawBlockSize], (int) sizeof(SuperBlock), senderaddress, senderport);
if ((senderaddress != senderaddress0) || (senderport != senderport0))
{
std::cerr << "example1_rx: connected to: " << senderaddress << ":" << senderport << std::endl;
senderaddress0 = senderaddress;
senderport0 = senderport;
}
usleep(10);
}
rxBlock = *((SuperBlock *) rawBlock);
ex1.processBlock(rxBlock);
}
}
示例8: reader_thread
void reader_thread()
{
while (!data_ready.load()) {
std::this_thread::sleep_for(std::chrono::milliseconds(1));
}
std::cout<<"The answer = "<<data[0]<<"\n";
}
示例9: consume
void consume(std::atomic_bool& done, int* array, int_queue& q)
{
while (!done.load())
{
int val;
if(q.pop(val))
{
array[val] = val;
}
else
{
std::this_thread::yield();
}
}
// drain
while (!q.empty())
{
int val;
if(q.pop(val))
{
array[val] = val;
}
else
{
std::this_thread::yield();
}
}
}
示例10: operator
/**
* This is the actual function that the thread executes.
* It receives a block from the scheduler, class its run() method and returns it to the scheduler.
* The thread runs until the it is told to stop by setting the m_stop boolean flag
*/
void operator()()
{
if(CPU_COUNT(&m_mask)>0)
{
pthread_t id = pthread_self();
int ret = pthread_setaffinity_np(id, sizeof(m_mask), &m_mask);
if(ret != 0)
{
perror("setaffinity");
throw(std::runtime_error("set affinity failed"));
}
}
while(!m_stop.load())
{
std::shared_ptr<Block>torun(m_scheduler.next_task(m_id));
if(torun)
{
torun->run();
m_scheduler.task_done(m_id, std::move(torun));
}
else
{
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
}
m_stop.store(false);
}
示例11: read
static void
run(std::atomic_bool& running, int fd, felix::netio::DataSinkCallbacks* callbacks)
{
while(running.load())
{
/* felix::netio::msgheader header;
ssize_t count = read(fd, &header, sizeof(header));
assert(count == sizeof(header));
char* data = new char[header.len];
ssize_t bytes_read = 0;
while(bytes_read < header.len)
{
count = read(fd, data+bytes_read, header.len-bytes_read);
if (count == 0)
{
std::vector<felix::netio::DataSinkMessage> messages;
messages.emplace_back(data, bytes_read);
callbacks->on_data_received_with_error(messages);
return;
}
bytes_read += count;
}
*/
char* data = new char[1024];
ssize_t count = read(fd, data, 1024);
std::vector<felix::netio::DataSinkMessage> messages;
messages.emplace_back(data, count);
callbacks->on_data_received(messages);
}
}
示例12: calculateNextInstr
static void
stepCore(uint32_t coreId, bool stepOver)
{
decaf_check(sIsPaused.load());
const cpu::CoreRegs *state = sCorePauseState[coreId];
uint32_t nextInstr = calculateNextInstr(state, stepOver);
cpu::addBreakpoint(nextInstr, cpu::SYSTEM_BPFLAG);
resumeAll();
}
示例13: lock
void
handleDbgBreakInterrupt()
{
// If we are not initialised, we should ignore DbgBreaks
if (!decaf::config::debugger::enabled) {
return;
}
std::unique_lock<std::mutex> lock(sMutex);
auto coreId = cpu::this_core::id();
// Store our core state before we flip isPaused
sCorePauseState[coreId] = cpu::this_core::state();
// Check to see if we were the last core to join on the fun
auto coreBit = 1 << coreId;
auto isPausing = sIsPausing.fetch_or(coreBit);
if (isPausing == 0) {
// This is the first core to hit a breakpoint
sPauseInitiatorCoreId = coreId;
// Signal the rest of the cores to stop
for (auto i = 0; i < 3; ++i) {
cpu::interrupt(i, cpu::DBGBREAK_INTERRUPT);
}
}
if ((isPausing | coreBit) == (1 | 2 | 4)) {
// This was the last core to join.
sIsPaused.store(true);
sIsPausing.store(0);
sIsResuming.store(0);
}
// Spin around the release condition while we are paused
while (sIsPausing.load() || sIsPaused.load()) {
sPauseReleaseCond.wait(lock);
}
// Clear any additional DbgBreaks that occured
cpu::this_core::clearInterrupt(cpu::DBGBREAK_INTERRUPT);
// Everyone needs to leave at once in case new breakpoints occur.
if ((sIsResuming.fetch_or(coreBit) | coreBit) == (1 | 2 | 4)) {
sPauseReleaseCond.notify_all();
} else {
while ((sIsResuming.load() | coreBit) != (1 | 2 | 4)) {
sPauseReleaseCond.wait(lock);
}
}
}
示例14: thread_recv
void thread_recv() {
while (connected.load()) {
spmsg_t msg = std::make_shared<msg_t>(sizeof(uint32_t));
if (!_do_recv(msg->data(), sizeof(uint32_t)))
return;
uint32_t msg_len = *(uint32_t*)msg->data();
msg->resize(msg_len + sizeof(uint32_t));
*(uint32_t*)msg->data() = msg_len;
if (!_do_recv(msg->data() + sizeof(uint32_t), msg_len))
return;
recv_queue.push(std::move(msg));
}
}
示例15: while
/**
* Main thread entry point for the IPC thread.
*
* This thread represents the IOS side of the IPC mechanism.
*
* Responsible for receiving IPC requests and dispatching them to the
* correct IOS device.
*/
void
ipcThreadEntry()
{
std::unique_lock<std::mutex> lock { sIpcMutex };
while (true) {
if (!sIpcRequests.empty()) {
auto request = sIpcRequests.front();
sIpcRequests.pop();
lock.unlock();
iosDispatchIpcRequest(request);
lock.lock();
switch (request->cpuId) {
case IOSCpuId::PPC0:
sIpcResponses[0].push(request);
cpu::interrupt(0, cpu::IPC_INTERRUPT);
break;
case IOSCpuId::PPC1:
sIpcResponses[1].push(request);
cpu::interrupt(1, cpu::IPC_INTERRUPT);
break;
case IOSCpuId::PPC2:
sIpcResponses[2].push(request);
cpu::interrupt(2, cpu::IPC_INTERRUPT);
break;
default:
decaf_abort("Unexpected cpu id");
}
}
if (!sIpcThreadRunning.load()) {
break;
}
if (sIpcRequests.empty()) {
sIpcCond.wait(lock);
}
}
sIpcThreadRunning.store(false);
}