本文整理汇总了C++中atomic::inc方法的典型用法代码示例。如果您正苦于以下问题:C++ atomic::inc方法的具体用法?C++ atomic::inc怎么用?C++ atomic::inc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类atomic
的用法示例。
在下文中一共展示了atomic::inc方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: bind
bool server::bind(const std::string& ipcfile, size_t buffer_size) {
logstream(LOG_INFO) << "Server attaching to " << ipcfile << " " << buffer_size << std::endl;
size_t _run_progress = 0;
try {
m_shmname = ipcfile;
if (m_shmname.empty()) {
std::stringstream strm;
strm << get_my_pid() << "_" << SERVER_IPC_COUNTER.inc();
m_shmname= strm.str();
}
// sets up the raii deleter so that we eventually
// delete this file
_run_progress = 1;
m_ipcfile_deleter = register_shared_memory_name(m_shmname);
// this is really modified from code in
// http://www.boost.org/doc/libs/1_58_0/doc/html/interprocess/synchronization_mechanisms.html
_run_progress = 2;
m_shared_object.reset(new shared_memory_object(create_only,
m_shmname.c_str(),
read_write));
//Set size
_run_progress = 3;
m_shared_object->truncate(buffer_size + sizeof(shared_memory_buffer));
//Map the whole shared memory in this process
_run_progress = 4;
m_mapped_region.reset(new mapped_region(*m_shared_object,
read_write));
_run_progress = 5;
void* buffer = m_mapped_region->get_address();
// placement new. put the data in the buffer
_run_progress = 6;
m_buffer = new (buffer) shared_memory_buffer;
m_buffer->m_buffer_size = buffer_size;
m_buffer->m_server_to_client.sender_pid = get_my_pid();
} catch (const std::string& error) {
logstream(LOG_ERROR) << "SHMIPC initialization Error (1), stage "
<< _run_progress << ": " << error << std::endl;
return false;
} catch (const std::exception& error) {
logstream(LOG_ERROR) << "SHMIPC initialization Error (2), stage "
<< _run_progress << ": " << error.what() << std::endl;
return false;
} catch (...) {
logstream(LOG_ERROR) << "Unknown SHMIPC Initialization Error, stage "
<< _run_progress << "." << std::endl;
return false;
}
return true;
}
示例2: readlock
inline void readlock(request *I) {
I->lockclass =QUEUED_RW_LOCK_REQUEST_READ;
I->next = NULL;
I->s.stateu = 0;
I->s.state.successor_class = QUEUED_RW_LOCK_REQUEST_NONE;
I->s.state.blocked = true;
__sync_synchronize();
request* predecessor = __sync_lock_test_and_set(&tail, I);
if (predecessor == NULL) {
reader_count.inc();
I->s.state.blocked = false;
}
else {
state_union tempold, tempnew;
tempold.state.blocked = true;
tempold.state.successor_class = QUEUED_RW_LOCK_REQUEST_NONE;
tempnew.state.blocked = true;
tempnew.state.successor_class = QUEUED_RW_LOCK_REQUEST_READ;
__sync_synchronize();
if (predecessor->lockclass == QUEUED_RW_LOCK_REQUEST_WRITE ||
atomic_compare_and_swap(predecessor->s.stateu,
tempold.stateu,
tempnew.stateu)) {
predecessor->next = I;
// wait
__sync_synchronize();
volatile state_union& is = I->s;
while(is.state.blocked) sched_yield();
}
else {
reader_count.inc();
predecessor->next = I;
__sync_synchronize();
I->s.state.blocked = false;
}
}
__sync_synchronize();
if (I->s.state.successor_class == QUEUED_RW_LOCK_REQUEST_READ) {
// wait
while(I->next == NULL) sched_yield();
reader_count.inc();
I->next->s.state.blocked = false;
}
}
示例3: try_terminate
bool try_terminate(size_t cpuid, std::pair<size_t, bool> &job) {
job.second = false;
numactive.dec();
cons.begin_done_critical_section(cpuid);
job = queue.try_dequeue();
if (job.second == false) {
bool ret = cons.end_done_critical_section(cpuid);
numactive.inc();
return ret;
}
else {
cons.cancel_critical_section(cpuid);
numactive.inc();
return false;
}
}
示例4: wrunlock
inline void wrunlock(request *I) {
__sync_synchronize();
if (I->next != NULL || !__sync_bool_compare_and_swap(&tail, I, (request*)NULL)) {
// wait
while(I->next == NULL) sched_yield();
__sync_synchronize();
if (I->next->lockclass == QUEUED_RW_LOCK_REQUEST_READ) {
reader_count.inc();
}
I->next->s.state.blocked = false;
}
}
示例5: receive_string
void receive_string(const std::string &s) {
ctr.inc();
}
示例6: receive_vector
void receive_vector(const std::vector<size_t> &s) {
ctr.inc();
}
示例7: receive_ints
void receive_ints(size_t i0, size_t i1, size_t i2, size_t i3) {
ctr.inc();
}
示例8: increment_running_counter
inline void increment_running_counter() {
threads_running.inc();
}