本文整理汇总了C++中AtomicInt类的典型用法代码示例。如果您正苦于以下问题:C++ AtomicInt类的具体用法?C++ AtomicInt怎么用?C++ AtomicInt使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AtomicInt类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _initialized
/*
Builds the DynamicRoutingTable from Control Provider and Services
definition tables in this file:
- SvcsRegDefinitionTable defines OpenPegasus services to be registered
- CtlProviderRegDefinitionTable defines Control Providers
This is a static method.
*/
void DynamicRoutingTable::buildRoutingTable()
{
// Lock during table build
static AtomicInt _initialized(0);
static Mutex _monitor;
// Get the address of the routing table
DynamicRoutingTable * routingTable =
DynamicRoutingTable::getRoutingTable();
// Assure table built only once
if (_initialized.get() == 0)
{
// lock and retest
AutoMutex autoMut(_monitor);
if (_initialized.get() == 0)
{
const Uint32 NUM_SVCS = sizeof(SvcsRegDefinitionTable) /
sizeof(SvcsRegDefinitionTable[0]);
// Insert a record into the table for each entry in the
// SvcsDefinitionTable
for (Uint32 i = 0; i < NUM_SVCS; i++)
{
Uint32 serviceId = MessageQueue::lookup(
SvcsRegDefinitionTable[i].serviceName)->getQueueId();
routingTable->_insertRecord(
SvcsRegDefinitionTable[i].className,
SvcsRegDefinitionTable[i].namespaceName,
String::EMPTY,
serviceId);
}
// Add Control Providers from CtlProviderRegDefintionTable
const Uint32 NUM_CTL_PROVIDERS =
sizeof(CtlProviderRegDefinitionTable) /
sizeof(CtlProviderRegDefinitionTable[0]);
// all Control provider routing is through controlService
Uint32 controlServiceId = MessageQueue::lookup(
PEGASUS_QUEUENAME_CONTROLSERVICE)->getQueueId();
for (Uint32 i = 0; i < NUM_CTL_PROVIDERS; i++)
{
routingTable->_insertRecord(
CtlProviderRegDefinitionTable[i].className,
CtlProviderRegDefinitionTable[i].namespaceName,
CtlProviderRegDefinitionTable[i].providerName,
controlServiceId);
}
// set initialized flag
_initialized = 1;
#ifdef PEGASUS_DEBUG
_tableInitialized = true;
#endif
}
}
//// routingTable->dumpRegTable();
}
示例2: test02
// Test Thread and AtomicInt
void test02()
{
const Uint32 numThreads = 64;
AtomicInt * atom = new AtomicInt(0);
Thread* threads[numThreads];
(*atom)++;
Boolean zero = atom->DecAndTestIfZero();
assert(zero);
for (Uint32 i=0; i<numThreads; i++)
{
threads[i] = new Thread(atomicIncrement, atom, false);
}
for (Uint32 i=0; i<numThreads; i++)
{
threads[i]->run();
}
for (Uint32 i=0; i<numThreads; i++)
{
threads[i]->join();
delete threads[i];
}
assert(atom->value() == numThreads);
delete atom;
}
示例3: test02
// Test Thread and AtomicInt
void test02()
{
const Uint32 numThreads = 64;
AtomicInt * atom = new AtomicInt(0);
Thread* threads[numThreads];
(*atom)++;
Boolean zero = atom->decAndTestIfZero();
PEGASUS_TEST_ASSERT(zero);
for (Uint32 i=0; i<numThreads; i++)
{
threads[i] = new Thread(atomicIncrement, atom, false);
}
for (Uint32 i=0; i<numThreads; i++)
{
threads[i]->run();
}
for (Uint32 i=0; i<numThreads; i++)
{
threads[i]->join();
delete threads[i];
}
PEGASUS_TEST_ASSERT(atom->get() == numThreads);
delete atom;
}
示例4: funcSleepUntilCancelled
ThreadReturnType PEGASUS_THREAD_CDECL funcSleepUntilCancelled(
void* parm)
{
AtomicInt* cancelled = static_cast<AtomicInt*>(parm);
while (cancelled->get() == 0)
{
Threads::sleep(1);
}
return 0;
}
示例5: atomicIncrement
ThreadReturnType PEGASUS_THREAD_CDECL atomicIncrement(void * parm)
{
Thread* my_thread = (Thread *)parm;
AtomicInt * atom = (AtomicInt *)my_thread->get_parm();
(*atom)++;
(*atom)++; (*atom)++; (*atom)++; (*atom)++;
(*atom)--; (*atom)--;
(*atom)--;
Boolean zero = atom->decAndTestIfZero();
PEGASUS_TEST_ASSERT(zero == false);
return ThreadReturnType(0);
}
示例6: atomicIncrement
PEGASUS_THREAD_RETURN PEGASUS_THREAD_CDECL atomicIncrement(void * parm)
{
Thread* my_thread = (Thread *)parm;
AtomicInt * atom = (AtomicInt *)my_thread->get_parm();
(*atom)++;
(*atom)+=4;
(*atom)-=2;
(*atom)--;
Boolean zero = atom->DecAndTestIfZero();
assert(zero == false);
my_thread->exit_self(0);
return 0;
}
示例7: ftor
void AtomicIntOp::exec_both (AtomicInt <T> &atom, F &ftor, T &val_old, T &val_new)
{
assert (&atom != 0);
assert (&ftor != 0);
T val_cur;
do
{
val_cur = atom;
val_new = ftor (val_cur);
val_old = atom.cas (val_new, val_cur);
}
while (val_old != val_cur);
}
示例8: Initialize
static void Initialize()
{
static AtomicInt s_initialized;
static Mutex s_mutex;
if ( !s_initialized )
{
volatile AutoLock lock( s_mutex );
if ( s_initialized.Load() == 0 )
{
uint32 M, m, r, b, beta, conf, le;
char lang[ 8 ];
(*API->Global->GetPixInsightVersion)( &M, &m, &r, &b, &beta, &conf, &le, lang );
s_major = int( M );
s_minor = int( m );
s_release = int( r );
s_build = int( b );
s_beta = int( beta );
s_confidential = conf != 0;
s_le = le != 0;
s_language = lang;
#if ( PCL_API_Version >= 0x0126 )
char16_type* s = (*API->Global->GetPixInsightCodename)( ModuleHandle() );
if ( s != nullptr )
{
s_codename = String( s );
if ( Module != nullptr )
Module->Deallocate( s );
}
#endif
s_initialized.Store( 1 );
}
}
}
示例9: autoMut
FAKE_MESSAGE *get_next_msg(void *key)
{
AutoPtr<FAKE_MESSAGE> msg;
AutoMutex autoMut(msg_mutex);
if(requests.value() < NUMBER_MSGS)
{
msg.reset(PEGASUS_NEW(FAKE_MESSAGE, dq_handle) FAKE_MESSAGE(key, 0));
/*****
check for corrupted memory
char *p = (char *)msg;
p += sizeof(FAKE_MESSAGE);
*p = 0x00;
if(peg_suballocator::CheckMemory(msg))
abort();
******/
requests++;
}
return msg.release();
}
示例10: testReadWriteThreads
void testReadWriteThreads()
{
if (verbose)
{
cout << "testReadWriteThreads" << endl;
}
ReadWriteSem *rwSem = new ReadWriteSem();
Thread *readers[READER_COUNT];
Thread *writers[WRITER_COUNT];
for(int i = 0; i < READER_COUNT; i++)
{
readers[i] = new Thread(reading_thread, rwSem, false);
readers[i]->run();
}
for( int i = 0; i < WRITER_COUNT; i++)
{
writers[i] = new Thread(writing_thread, rwSem, false);
writers[i]->run();
}
Threads::sleep(20000);
die = true;
for( int i = 0; i < 40; i++)
{
readers[i]->join();
delete readers[i];
}
for( int i = 0; i < 10; i++)
{
writers[i]->join();
delete writers[i];
}
delete rwSem;
if (verbose)
{
cout << endl
<< "read operations: " << read_count.get() << endl
<< "write operations: " << write_count.get() << endl;
}
}
示例11: _beginTest
int _beginTest(CIMClient& workClient,
Uint32 indicationSendCount,
Uint32 runClientThreadCount,
const String& processIdFile,
const String& logFile)
{
#ifdef PEGASUS_USE_NET_SNMP
// Stop snmptrapd process if it is running
_stopSnmptrapd(processIdFile);
// if trapLogFile exists, remove it
_removeTrapLogFile(logFile);
FILE * trapInfo;
try
{
_startSnmptrapd(&trapInfo, processIdFile, logFile);
}
catch (Exception & e)
{
cerr << e.getMessage() << endl;
return (-1);
}
// Extended for all snmp implementation
_receiveExpectedTraps(workClient, indicationSendCount,
runClientThreadCount, logFile);
// Stop snmptrapd process if it is running and remove procIdFile
_stopSnmptrapd(processIdFile);
pclose(trapInfo);
// if error encountered then fail the test.
if (errorsEncountered.get())
{
cout << "+++++ test failed" << endl;
return (-1);
}
else
{
cout << "+++++ passed all tests" << endl;
}
return (0);
#else
cerr << "Cannot create a trap receiver." << endl;
return (-1);
#endif
}
示例12: notify
void ThreadPool::notify(int inIndex)
{
#ifdef POOL_DEBUG
printf("ThreadPool notified for index %d\n", inIndex);
#endif
if (mRequestCount.decrementAndTest()) {
#if defined(POOL_DEBUG) || defined(THREAD_DEBUG)
printf("ThreadPool posting to wait semaphore\n");
#endif
mWaitSema.post();
}
}
示例13: _idleThd
ThreadReturnType PEGASUS_THREAD_CDECL _idleThd(void *parm)
{
Thread *my_thread = (Thread *)parm;
AutoPtr<T_Parms> parms((T_Parms *)my_thread->get_parm());
Uint32 durationSeconds = parms->durationSeconds;
const char * testUserid = parms->testUserid;
const char * testPasswd = parms->testPasswd;
CIMClient client;
try
{
if (testUserid == NULL)
{
client.connectLocal();
}
else
{
client.connect(System::getHostName(), 5988,
String(testUserid), String(testPasswd));
}
CIMClass tmpClass =
client.getClass (OSINFO_NAMESPACE, OSINFO_CLASSNAME);
cout << "Test 2 of 2: Begin " << durationSeconds
<< " second idle period..." << endl;
while (sleepIterations.get() < durationSeconds)
{
Threads::sleep(1000);
}
//the client shall reconnect if the connection was closed and
//so the operation should succeed.
CIMClass tmpClass2 =
client.getClass (OSINFO_NAMESPACE, OSINFO_CLASSNAME);
}
catch(Exception& e)
{
test2CaughtException = true;
cerr << "Error: " << e.getMessage() << endl;
}
client.disconnect();
return ThreadReturnType(0);
}
示例14: _testConcurrent
//
// Tests subscription creation by sending the similar concurrent subscription
// creation requests .
//
void _testConcurrent(CIMClient &client)
{
CIMObjectPath filterPath;
CIMObjectPath handlerPath;
CIMObjectPath subscriptionPath;
try
{
HandlerPath = CreateHandler1Instance(client,
PEGASUS_NAMESPACENAME_INTEROP);
FilterPath = CreateFilterInstance(client,
QUERY1, "WQL", "Filter1",
PEGASUS_NAMESPACENAME_INTEROP);
Thread thread1(createSubscriptionFunc, (void *)0, false);
Thread thread2(createSubscriptionFunc, (void *)0, false);
Thread thread3(createSubscriptionFunc, (void *)0, false);
Thread thread4(createSubscriptionFunc, (void *)0, false);
thread1.run();
thread2.run();
thread3.run();
thread4.run();
thread1.join();
thread2.join();
thread3.join();
thread4.join();
_checkSubscriptionCount(client);
PEGASUS_TEST_ASSERT(exceptionCount.get() == 3);
DeleteInstance(client, SubscriptionPath, PEGASUS_NAMESPACENAME_INTEROP);
DeleteInstance(client, FilterPath, PEGASUS_NAMESPACENAME_INTEROP);
DeleteInstance(client, HandlerPath, PEGASUS_NAMESPACENAME_INTEROP);
}
catch(const CIMException &e)
{
PEGASUS_STD(cerr) << "Exception: " << e.getMessage()
<< PEGASUS_STD (endl);
PEGASUS_TEST_ASSERT(0);
}
}
示例15: _test2
// _test2 verifies that a CIM Operation on a client connection will still
// succeed when the idleConnectionTimeout period is exceeded (_idleThd) *and*
// there is concurrent server activity (_runningThd) so that the Monitor
// will wake up and check for timeouts and close the connection.
// In this case, the second call to getClass() in _idleThd() will reconnect
// and send the request.
Boolean _test2(
int durationSeconds, const char * testUserid, const char * testPasswd)
{
try
{
sleepIterations.set(0);
// run tests
Array<Thread *> clientThreads;
test2CaughtException = false;
clientThreads.append(
_runTestThreads(
_runningThd, durationSeconds, testUserid, testPasswd));
clientThreads.append(
_runTestThreads(
_idleThd, durationSeconds, testUserid, testPasswd));
// wait for threads to terminate
for(Uint32 i=0; i< clientThreads.size(); i++)
{
clientThreads[i]->join();
}
// clean up threads
for(Uint32 i=0; i < clientThreads.size(); i++)
{
if(clientThreads[i])
delete clientThreads[i];
}
}
catch(Exception& e)
{
cerr << "Error: " << e.getMessage() << endl;
return TEST_FAILED;
}
// We do not expect exception in this case.
return (test2CaughtException == false);
}