本文整理汇总了C++中std::atomic_int::fetch_add方法的典型用法代码示例。如果您正苦于以下问题:C++ atomic_int::fetch_add方法的具体用法?C++ atomic_int::fetch_add怎么用?C++ atomic_int::fetch_add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::atomic_int
的用法示例。
在下文中一共展示了atomic_int::fetch_add方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: while
Texture TextureBuilder::Build2DTexture(TextureBindpoint target, unsigned width, unsigned height, unsigned count,
unsigned channels, TexturePixelFormat pixelFormat, bool useMipmaps)
{
int current_id = id.fetch_add(1, std::memory_order_relaxed);
Texture result;
result.info.width = width;
result.info.height = height;
result.info.count = count;
result.info.type = TextureType::Tex2D;
result.info.target = target;
result.info.targetPixelFormat = pixelFormat;
result.info.channels = channels;
result.info.name = std::string(NAME_PREFIX) + std::to_string(current_id);
unsigned minSize = std::min(width, height);
if (useMipmaps)
{
unsigned i = 0;
while (minSize > 1)
{
minSize /= 2;
i++;
}
result.info.mipmaps = i;
}
return result;
}
示例2: initializeNotifier
void* initializeNotifier(void (*process)(uint64_t, void*), void *param, int32_t *status)
{
if (!process) {
*status = NULL_PARAMETER;
return nullptr;
}
if (!notifierAtexitRegistered.test_and_set())
std::atexit(cleanupNotifierAtExit);
if (notifierRefCount.fetch_add(1) == 0) {
std::lock_guard<priority_mutex> sync(notifierInterruptMutex);
// create manager and alarm if not already created
if (!notifierManager) {
notifierManager = new tInterruptManager(1 << kTimerInterruptNumber, false, status);
notifierManager->registerHandler(alarmCallback, NULL, status);
notifierManager->enable(status);
}
if (!notifierAlarm) notifierAlarm = tAlarm::create(status);
}
std::lock_guard<priority_recursive_mutex> sync(notifierMutex);
// create notifier structure and add to list
Notifier* notifier = new Notifier();
notifier->prev = nullptr;
notifier->next = notifiers;
if (notifier->next) notifier->next->prev = notifier;
notifier->param = param;
notifier->process = process;
notifiers = notifier;
return notifier;
}
示例3: stepLeft
void stepLeft() {
std::unique_lock<std::mutex> lock(mutex);
for (int i = 0; i < 10; ++i) {
std::cout << "left" << std::endl;
isWaiting.fetch_add(1);
if (isWaiting.load() % 2 != 0) {
condVar.notify_one();
}
else {
condVar.wait(lock);
}
}
}
示例4:
Order::Order(int clientAssignedId, const std::string& account, const std::string& security,
double price, int amount, Operation operation, OrderType type) :
m_id(gs_id.fetch_add(1)),
m_clientAssignedId(clientAssignedId),
m_account(account),
m_security(security),
m_price(price),
m_amount(amount),
m_operation(operation),
m_type(type),
m_state(State::Unsubmitted)
{
}
示例5: HAL_InitializeNotifier
HAL_NotifierHandle HAL_InitializeNotifier(HAL_NotifierProcessFunction process,
void* param, int32_t* status) {
if (!process) {
*status = NULL_PARAMETER;
return 0;
}
if (!notifierAtexitRegistered.test_and_set())
std::atexit(cleanupNotifierAtExit);
if (notifierRefCount.fetch_add(1) == 0) {
std::lock_guard<priority_mutex> sync(notifierInterruptMutex);
// create manager and alarm if not already created
if (!notifierManager) {
notifierManager = std::make_unique<tInterruptManager>(
1 << kTimerInterruptNumber, false, status);
notifierManager->registerHandler(alarmCallback, nullptr, status);
notifierManager->enable(status);
}
if (!notifierAlarm) notifierAlarm.reset(tAlarm::create(status));
}
std::lock_guard<priority_recursive_mutex> sync(notifierMutex);
std::shared_ptr<Notifier> notifier = std::make_shared<Notifier>();
HAL_NotifierHandle handle = notifierHandles.Allocate(notifier);
if (handle == HAL_kInvalidHandle) {
*status = HAL_HANDLE_ERROR;
return HAL_kInvalidHandle;
}
// create notifier structure and add to list
notifier->next = notifiers;
if (notifier->next) notifier->next->prev = notifier;
notifier->param = param;
notifier->process = process;
notifier->handle = handle;
notifier->threaded = false;
notifiers = notifier;
return handle;
}
示例6: increaseGLCommandFunctionCount
// ------------------------------------------------------------------------
void increaseGLCommandFunctionCount(int count)
{ m_gl_cmd_function_count.fetch_add(count); }