本文整理汇总了C++中std::atomic::store方法的典型用法代码示例。如果您正苦于以下问题:C++ atomic::store方法的具体用法?C++ atomic::store怎么用?C++ atomic::store使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::atomic
的用法示例。
在下文中一共展示了atomic::store方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: write_x
void write_x() {
x.store(true, std::memory_order_release);
}
开发者ID:ordinary-developer,项目名称:book_c_plus_plus_concurrency_in_action_a_williams,代码行数:3,代码来源:main.cpp
示例2: write_y
void write_y()
{
y.store(true, std::memory_order_seq_cst);
}
示例3: unlock
void unlock()
{
locked.store(0, std::memory_order_release);
}
示例4: loop
void Hook::loop(Hook::Hid::HidControllerDevice &realD, Hook::Scp::VirtualDevice &vjd)
{
auto mapper(Remapper::create(Remapper::DEFAULT_PATH));
bool hasProcList(Config::get()->hasProcessList());
const auto &procList(Config::get()->getProcessList());
bool suicide(hasProcList ? Config::get()->shouldEndOnGameProcDeath() : false);
std::thread worker;
HOOK_TCHARSTR activeProc(HOOK_TCHARIFY(Remapper::DEFAULT_PATH));
if (!hasProcList)
{
std::cout << "\nSetup successful! Beginning controller translation. Press CTRL + END to quit. Press CTRL + HOME to re-read button mappings." << std::endl;
}
else
{
std::cout << "\nSetup successful! Awaiting game startup... Press CTRL + SHIFT + END to quit." << std::endl;
auto procIter(procWaitLoop(procList));
if (procIter == procList.cend())
{
return;
}
activeProc = *procIter;
HOOK_TCHAROUT << "Detected startup of " << activeProc << "." << std::endl;
mapper = Remapper::create(activeProc);
std::wcout << "Beginning controller translation. Press CTRL + END to quit. Press CTRL + HOME to re-read button mappings." << std::endl;
worker = std::thread(processCheckerThreadLoop, activeProc);
}
for (;;)
{
std::this_thread::sleep_for(std::chrono::milliseconds(1));
realD.pullData();
auto state(realD.parseData());
mapper.remap(state);
vjd.feed(state);
if (GetAsyncKeyState(VK_CONTROL) && GetAsyncKeyState(VK_HOME))
{
std::cout << "Re-reading button mappings from file...\n";
Remapper::reread(activeProc, mapper);
}
if (GetAsyncKeyState(VK_END) && GetAsyncKeyState(VK_CONTROL))
{
earlyDie.store(true);
cleanupThread(worker);
if (hasProcList)
{
goto rewait;
}
break;
}
else if (hasProcList && earlyDie.load())
{
if (suicide)
{
cleanupThread(worker);
std::cout << "Game process ended. Terminating controller translation and quitting." << std::endl;
break;
}
std::cout << "Game process ended. Terminating controller translation." << std::endl;
rewait:
cleanupThread(worker);
std::cout << "Awaiting game startup... Press CTRL + SHIFT + END to quit." << std::endl;
auto procIter(procWaitLoop(procList));
if (procIter == procList.cend())
{
break;
}
activeProc = *procIter;
mapper = Remapper::create(activeProc);
earlyDie.store(false);
worker = std::thread(processCheckerThreadLoop, *procIter);
}
}
}
示例6: reset
/** reset the ringbuffer
*
* \note Not thread-safe
* */
void reset(void)
{
write_index_.store(0, std::memory_order_relaxed);
read_index_.store(0, std::memory_order_release);
}
示例7: Update
void HiresTexture::Update()
{
s_check_native_format = false;
s_check_new_format = false;
if (s_prefetcher.joinable())
{
s_textureCacheAbortLoading.Set();
s_prefetcher.join();
}
if (!g_ActiveConfig.bHiresTextures)
{
s_textureMap.clear();
s_textureCache.clear();
size_sum.store(0);
return;
}
if (!g_ActiveConfig.bCacheHiresTextures)
{
s_textureCache.clear();
size_sum.store(0);
}
s_textureMap.clear();
const std::string& gameCode = SConfig::GetInstance().m_strUniqueID;
std::string szDir = StringFromFormat("%s%s", File::GetUserPath(D_HIRESTEXTURES_IDX).c_str(), gameCode.c_str());
std::string ddscode(".dds");
std::string cddscode(".DDS");
std::vector<std::string> Extensions = {
".png",
".dds"
};
auto rFilenames = DoFileSearch(Extensions, { szDir }, /*recursive*/ true);
const std::string code = StringFromFormat("%s_", gameCode.c_str());
const std::string miptag = "mip";
const std::string normaltag = ".nrm";
for (u32 i = 0; i < rFilenames.size(); i++)
{
std::string FileName;
std::string Extension;
SplitPath(rFilenames[i], nullptr, &FileName, &Extension);
if (FileName.substr(0, code.length()) == code)
{
s_check_native_format = true;
}
else if (FileName.substr(0, s_format_prefix.length()) == s_format_prefix)
{
s_check_new_format = true;
}
else
{
// Discard wrong files
continue;
}
const bool is_compressed = Extension.compare(ddscode) == 0 || Extension.compare(cddscode) == 0;
const bool is_normal_map = hasEnding(FileName, normaltag);
if (is_normal_map)
{
FileName = FileName.substr(0, FileName.size() - normaltag.size());
}
hires_mip_level mip_level_detail(rFilenames[i], Extension, is_compressed);
u32 level = 0;
size_t idx = FileName.find_last_of('_');
std::string miplevel = FileName.substr(idx + 1, std::string::npos);
if (miplevel.substr(0, miptag.length()) == miptag)
{
sscanf(miplevel.substr(3, std::string::npos).c_str(), "%i", &level);
FileName = FileName.substr(0, idx);
}
HiresTextureCache::iterator iter = s_textureMap.find(FileName);
u32 min_item_size = level + 1;
if (iter == s_textureMap.end())
{
HiresTextureCacheItem item(min_item_size);
if (is_normal_map)
{
item.normal_map.resize(min_item_size);
}
std::vector<hires_mip_level> &dst = is_normal_map ? item.normal_map : item.color_map;
dst[level] = mip_level_detail;
s_textureMap.emplace(FileName, item);
}
else
{
std::vector<hires_mip_level> &dst = is_normal_map ? iter->second.normal_map : iter->second.color_map;
if (dst.size() < min_item_size)
{
dst.resize(min_item_size);
}
dst[level] = mip_level_detail;
}
}
if (g_ActiveConfig.bCacheHiresTextures && s_textureMap.size() > 0)
{
// remove cached but deleted textures
//.........这里部分代码省略.........
示例8: unlock
void unlock() noexcept {
state_.store( spinlock_status::unlocked, std::memory_order_release);
}
示例9: unlock
void unlock() noexcept {
if ( 1 != value_.fetch_sub( 1, std::memory_order_acquire) ) {
value_.store( 0, std::memory_order_release);
futex_wake( & value_);
}
}
示例10: test_apply_with_executor
void test_apply_with_executor(Executor& exec)
{
accumulator.store(0);
{
using hpx::util::placeholders::_1;
hpx::apply(exec, &increment, 1);
hpx::apply(exec, hpx::util::bind(&increment, 1));
hpx::apply(exec, hpx::util::bind(&increment, _1), 1);
}
{
hpx::promise<std::int32_t> p;
hpx::shared_future<std::int32_t> f = p.get_future();
p.set_value(1);
using hpx::util::placeholders::_1;
hpx::apply(exec, &increment_with_future, f);
hpx::apply(exec, hpx::util::bind(&increment_with_future, f));
hpx::apply(exec, hpx::util::bind(&increment_with_future, _1), f);
}
{
using hpx::util::placeholders::_1;
hpx::apply(exec, increment, 1);
hpx::apply(exec, hpx::util::bind(increment, 1));
hpx::apply(exec, hpx::util::bind(increment, _1), 1);
}
{
increment_type inc;
using hpx::util::placeholders::_1;
using hpx::util::placeholders::_2;
hpx::apply(exec, &increment_type::call, inc, 1);
hpx::apply(exec, hpx::util::bind(&increment_type::call, inc, 1));
hpx::apply(exec, hpx::util::bind(&increment_type::call, inc, _1), 1);
}
{
increment_function_object obj;
using hpx::util::placeholders::_1;
using hpx::util::placeholders::_2;
hpx::apply(exec, obj, 1);
hpx::apply(exec, hpx::util::bind(obj, 1));
hpx::apply(exec, hpx::util::bind(obj, _1), 1);
}
{
using hpx::util::placeholders::_1;
using hpx::util::placeholders::_2;
hpx::apply(exec, increment_lambda, 1);
hpx::apply(exec, hpx::util::bind(increment_lambda, 1));
hpx::apply(exec, hpx::util::bind(increment_lambda, _1), 1);
}
hpx::lcos::local::no_mutex result_mutex;
std::unique_lock<hpx::lcos::local::no_mutex> l(result_mutex);
result_cv.wait_for(l, std::chrono::seconds(1),
hpx::util::bind(std::equal_to<std::int32_t>(),
std::ref(accumulator), 18));
HPX_TEST_EQ(accumulator.load(), 18);
}
示例11: producer
void producer()
{
std::string* p = new std::string("Hello");
data = 42;
ptr.store(p, std::memory_order_release);
}
示例12: backgroundProc
/* A method run in a backround thread, to keep filling the queue with new
* audio over time.
*/
void backgroundProc()
{
/* Temporary storage to read samples into, before passing to OpenAL.
* Kept here to avoid reallocating it during playback.
*/
std::vector<char> buffer(sBufferFrames * mFrameSize);
while (!mQuit.load())
{
/* First, make sure the buffer queue is filled. */
fillBufferQueue(buffer);
ALint state;
alGetSourcei(mSource, AL_SOURCE_STATE, &state);
if (state != AL_PLAYING && state != AL_PAUSED)
{
/* If the source is not playing or paused, it either underrun
* or hasn't started at all yet. So remove any buffers that
* have been played (will be 0 when first starting).
*/
ALint processed;
alGetSourcei(mSource, AL_BUFFERS_PROCESSED, &processed);
while (processed > 0)
{
ALuint bufid;
alSourceUnqueueBuffers(mSource, 1, &bufid);
--processed;
}
/* Make sure the buffer queue is still filled, in case another
* buffer had finished before checking the state and after the
* last fill. If the queue is empty, playback is over.
*/
if (fillBufferQueue(buffer) == 0)
{
mQuit.store(true);
return;
}
/* Now start the sound source. */
alSourcePlay(mSource);
}
ALint processed;
alGetSourcei(mSource, AL_BUFFERS_PROCESSED, &processed);
if (processed == 0)
{
/* Wait until a buffer in the queue has been processed. */
do {
std::this_thread::sleep_for(std::chrono::milliseconds(50));
if (mQuit.load()) break;
alGetSourcei(mSource, AL_BUFFERS_PROCESSED, &processed);
} while (processed == 0);
}
/* Remove processed buffers, then restart the loop to keep the
* queue filled.
*/
while (processed > 0)
{
ALuint bufid;
alSourceUnqueueBuffers(mSource, 1, &bufid);
--processed;
}
}
}
示例13: Ticked
// tick signal handler
void Ticked()
{
hasTicked_.store(true);
++numTicked_;
ticked_.notify_all();
}
示例14: hpx_main
int hpx_main()
{
// count_down_and_wait
{
hpx::lcos::local::latch l(NUM_THREADS+1);
HPX_TEST(!l.is_ready());
std::vector<hpx::future<void> > results;
for (std::ptrdiff_t i = 0; i != NUM_THREADS; ++i)
results.push_back(hpx::async(&test_count_down_and_wait, std::ref(l)));
HPX_TEST(!l.is_ready());
// Wait for all threads to reach this point.
l.count_down_and_wait();
hpx::wait_all(results);
HPX_TEST(l.is_ready());
HPX_TEST_EQ(num_threads.load(), NUM_THREADS);
}
// count_down
{
num_threads.store(0);
hpx::lcos::local::latch l(NUM_THREADS+1);
HPX_TEST(!l.is_ready());
hpx::future<void> f = hpx::async(&test_count_down, std::ref(l));
HPX_TEST(!l.is_ready());
l.count_down_and_wait();
f.get();
HPX_TEST(l.is_ready());
HPX_TEST_EQ(num_threads.load(), std::size_t(1));
}
// wait
{
num_threads.store(0);
hpx::lcos::local::latch l(NUM_THREADS);
HPX_TEST(!l.is_ready());
std::vector<hpx::future<void> > results;
for (std::ptrdiff_t i = 0; i != NUM_THREADS; ++i)
results.push_back(hpx::async(&test_count_down_and_wait, std::ref(l)));
hpx::wait_all(results);
l.wait();
HPX_TEST(l.is_ready());
HPX_TEST_EQ(num_threads.load(), NUM_THREADS);
}
// count_up
{
num_threads.store(0);
hpx::lcos::local::latch l(1);
HPX_TEST(!l.is_ready());
std::vector<hpx::future<void> > results;
for (std::ptrdiff_t i = 0; i != NUM_THREADS; ++i){
l.count_up(1);
results.push_back(hpx::async(&test_count_down_and_wait, std::ref(l)));
}
HPX_TEST(!l.is_ready());
// Wait for all threads to reach this point.
l.count_down_and_wait();
hpx::wait_all(results);
HPX_TEST(l.is_ready());
HPX_TEST_EQ(num_threads.load(), NUM_THREADS);
}
// reset
{
num_threads.store(0);
hpx::lcos::local::latch l(0);
l.reset(NUM_THREADS+1);
HPX_TEST(!l.is_ready());
std::vector<hpx::future<void> > results;
for (std::ptrdiff_t i = 0; i != NUM_THREADS; ++i){
results.push_back(hpx::async(&test_count_down_and_wait, std::ref(l)));
}
HPX_TEST(!l.is_ready());
// Wait for all threads to reach this point.
l.count_down_and_wait();
//.........这里部分代码省略.........
示例15: write_x
void write_x()
{
// x.store(true, std::memory_order_seq_cst);
// x.store(true, std::memory_order_release);
x.store(true, std::memory_order_relaxed);
}