本文整理汇总了C++中std::atomic_bool::exchange方法的典型用法代码示例。如果您正苦于以下问题:C++ atomic_bool::exchange方法的具体用法?C++ atomic_bool::exchange怎么用?C++ atomic_bool::exchange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::atomic_bool
的用法示例。
在下文中一共展示了atomic_bool::exchange方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: lock
inline void
lock()
{
while (m_spin.exchange(true)) {
if (yield) {
std::this_thread::yield();
}
}
}
示例2:
~ThreadPool() {
stoped.exchange(true);
for (auto& cond: thread_cond) {
cond.notify_one();
}
for (auto& worker : workers) {
if (worker.joinable()) worker.join();
}
}
示例3:
void
resumeAll()
{
auto oldState = sIsPaused.exchange(false);
decaf_check(oldState);
for (auto i = 0; i < 3; ++i) {
sCorePauseState[i] = nullptr;
}
sPauseReleaseCond.notify_all();
}
示例4:
/**
* Stop the IPC thread.
*/
void
ipcShutdown()
{
std::unique_lock<std::mutex> lock { sIpcMutex };
if (sIpcThreadRunning.exchange(false)) {
sIpcCond.notify_all();
lock.unlock();
sIpcThread.join();
}
}
示例5: stopwatch
void stopwatch() {
/* Setup Terminal */
std::cout << hide_cursor << std::setfill('0');
setup_terminal();
auto start = std::chrono::high_resolution_clock::now();
using jiffies = std::chrono::duration<int, std::centi>;
while(!die) {
auto delta = std::chrono::duration_cast<jiffies>(
std::chrono::high_resolution_clock::now() - start
).count();
auto cs = delta%100;
auto s = delta/100;
auto m = s/60; s %= 60;
auto h = m/60; m %= 60;
std::cout << to_first_column
<< std::setw(2) << h << ':'
<< std::setw(2) << m << ':'
<< std::setw(2) << s << '.'
<< std::setw(2) << cs
<< std::flush;
if(lap.exchange(false)) {
std::cout << std::endl;
}
/* justification: something about Nyquist frequencies, etc.
* don't want to thrash my CPU to death */
std::this_thread::sleep_for(std::chrono::milliseconds{4});
}
/* Reset Terminal */
reset_terminal();
std::cout << show_cursor << std::endl;
std::exit(0);
}
示例6: run
void Ozette::run() {
if (_editors.empty()) show_browser();
timeout(100);
do {
if (sig_io_flag.exchange(false)) {
_shell.poll();
}
int ch = fix_control_quirks(getch());
switch (ch) {
case Control::UpArrow: show_browser(); break;
case Control::NewFile: new_file(); break;
case Control::Open: open_file(); break;
case Control::Directory: change_directory(); break;
case Control::Help: show_help(); break;
case Control::Execute: execute(); break;
case KEY_F(4): search(); break;
case KEY_F(5): build(); break;
default: _done |= !_shell.process(ch);
}
update_panels();
doupdate();
} while (!_done);
}