本文整理汇总了C++中CriticalSection类的典型用法代码示例。如果您正苦于以下问题:C++ CriticalSection类的具体用法?C++ CriticalSection怎么用?C++ CriticalSection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CriticalSection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: while
//
// Given a buffer of size DWORDs, populates the buffer with
// the thread IDs of all currently active lisp threads.
// Returns the number of thread IDs actually stored in the buffer.
//
DWORD LispThreadQueue::GetLispThreadIDs(DWORD* buf, int size)
{
TQCriticalSection.Enter();
ThreadRecord* tr = list;
int i = 0;
while (tr && i < size)
{
buf[i++] = tr->threadID;
tr = tr->next;
}
TQCriticalSection.Leave();
return i;
}
示例2: while
CSSet FMLPAnalysis::short_outermost_cs(CSSet::const_iterator begin, CSSet::const_iterator end) const
{
stack<CriticalSection> s;
for (auto i = begin; i != end; ++i) s.push(*i);
CSSet work;
while(s.size() >0) {
CriticalSection cs = s.top();
s.pop();
Resource r = get_res(cs.get_resource());
if (r.is_short()) work.push_back(cs);
else
for (auto i = cs.begin(); i!=cs.end(); ++i) s.push(*i);
}
return work;
}
示例3: getOutputBuffer
void LogMgr::log(const std::string& tag, const std::string& message, const char* funcName, const char* sourceFile, unsigned int lineNum)
{
m_TagCriticalSection.lock();
Tags::iterator findIt = m_Tags.find(tag);
if (findIt != m_Tags.end())
{
m_TagCriticalSection.unlock();
std::string buffer;
getOutputBuffer(buffer, tag, message, funcName, sourceFile, lineNum);
outputFinalBufferToLogs(buffer, tag, findIt->second);
}
else
{
m_TagCriticalSection.unlock();
}
}
示例4: setDisplayFLags
void LogMgr::setDisplayFLags(const std::string& tag, unsigned char flags)
{
m_TagCriticalSection.lock();
if (flags != 0)
{
Tags::iterator findIt = m_Tags.find(tag);
if (findIt == m_Tags.end())
m_Tags.insert(std::make_pair(tag, flags));
else
findIt->second = flags;
}
else
{
m_Tags.erase(tag);
}
m_TagCriticalSection.unlock();
}
示例5: GetOutputBuffer
//------------------------------------------------------------------------------------------------------------------------------------
// This function builds up the log string and outputs it to various places based on the display flags (m_displayFlags).
//------------------------------------------------------------------------------------------------------------------------------------
void LogMgr::Log(const string& tag, const string& message, const char* funcName, const char* sourceFile, unsigned int lineNum)
{
m_tagCriticalSection.Lock();
Tags::iterator findIt = m_tags.find(tag);
if (findIt != m_tags.end())
{
m_tagCriticalSection.Unlock();
string buffer;
GetOutputBuffer(buffer, tag, message, funcName, sourceFile, lineNum);
OutputFinalBufferToLogs(buffer, findIt->second);
}
else
{
// Critical section is exited in the if statement above, so we need to exit it here if that didn't
// get executed.
m_tagCriticalSection.Unlock();
}
} // end LogMgr::Log()
示例6: MutexListList_GetID
int MutexListList_GetID(CriticalSection *mutexPointer)
{
queuelistmutex.enter();
MutexList_t *temp = MutexList;
int returnID = -1;
while (temp != NULL)
{
if (temp->mutexPointer == mutexPointer)
{
returnID = temp->mutexID;
break;
}
temp = temp->next;
}
queuelistmutex.exit();
return returnID;
}
示例7: dequeue
bool dequeue( _Tx *out )
{
bool success = false;
m_cs.Enter();
if (m_queue.size() > 0) {
*out = m_queue.front();
m_queue.pop();
success = true;
}
m_cs.Exit();
return success;
}
示例8: FlushAll
// Flush all existing thread streams... returns false on socket error
bool AsyncStream::FlushAll(Socket &s)
{
OVR_CAPTURE_CPU_ZONE(AsyncStream_FlushAll);
bool okay = true;
g_listlock.Lock();
for(AsyncStream *curr=s_head; curr; curr=curr->m_next)
{
okay = curr->Flush(s);
if(!okay) break;
}
g_listlock.Unlock();
return okay;
}
示例9: push
bool push(const _et &element,long timeout)
{
if (free_space.wait(timeout) ) {
c_region.enter();
int next = (last + 1) % element_count;
elements[last] = element;
last = next;
active_buffers++;
c_region.leave();
data_avail.signal();
return true;
}
return false;
}
示例10: release
int ServiceManager::release(void *svcptr) {
if (svcptr == NULL) return 0;
waServiceFactory *wsvc = NULL;
cs.enter(); // note cs getting locked twice via release+unlock
if (!lockmap.getItem(svcptr, &wsvc)) {
cs.leave();
DebugString("WARNING: got release with no lock record!");
return 0;
}
unlock(svcptr);
cs.leave();
ASSERT(wsvc != NULL);
return wsvc->releaseInterface(svcptr);
}
示例11: spiInitialize
//------------------------------------------------------------------------------------------------------------------------------------
bool __stdcall spiInitialize( client_info *gameClientInfo,
user_info *userData,
battle_info *bnCallbacks,
module_info *moduleData,
HANDLE hEvent)
{
// Called when the module is loaded
// DropMessage(0, "spiInitialize");
fatalError = false;
gameAppInfo = *gameClientInfo;
receiveEvent = hEvent;
critSec.init();
try
{
pluggedNetwork->initialize();
}
catch(GeneralException &e)
{
fatalError = true;
DropLastError(__FUNCTION__ " unhandled exception: %s", e.getMessage());
return false;
}
return true;
}
示例12: safeExit
void safeExit(int retcode)
{
bool shutdown;
globalMutex.lock(false);
shutdown=deadYet;
if(!deadYet)
{
deadYet=true;
cleanup();
fconfig_deleteinstance();
}
globalMutex.unlock(false);
if(!shutdown) exit(retcode);
else pthread_exit(0);
}
示例13: unlock
void unlock()
{
#ifdef DEBUG
if (!locked) throw "Already unlocked";
#endif
cs->leave();
locked = false;
}
示例14: Log
///////////////////////////////////////////////////////////////////////////////////////////////////////
// this function builds up the log string and outputs it to various places based on display flags
///////////////////////////////////////////////////////////////////////////////////////////////////////
void LogMgr::Log(const string& tag, const string& message, const char* func, const char* source, unsigned int line)
{
_tag_critical_section.Lock();
Tags::iterator it = _tags.find(tag);
if(it != _tags.end())
{
_tag_critical_section.Unlock();
string buffer;
GetOutputBuffer(buffer, tag, message, func, source, line);
OutputFinalBufferToLogs(buffer, it->second);
}
else
{
//critical section is exited in the if above, so need to do it here if above wasnt executed
_tag_critical_section.Unlock();
}
}
示例15: lock
void lock()
{
#ifdef DEBUG
if (locked) throw "Already locked";
#endif
cs->enter();
locked = true;
}