本文整理汇总了C++中Mutex::Lock方法的典型用法代码示例。如果您正苦于以下问题:C++ Mutex::Lock方法的具体用法?C++ Mutex::Lock怎么用?C++ Mutex::Lock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mutex
的用法示例。
在下文中一共展示了Mutex::Lock方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: assert
bool
KRT2Device::Send(const uint8_t *msg, unsigned msg_size,
OperationEnvironment &env)
{
//! Number of tries to send a message
unsigned retries = NR_RETRIES;
assert(msg_size > 0);
do {
response_mutex.Lock();
response = NO_RSP;
response_mutex.Unlock();
// Send the message
if (!port.FullWrite(msg, msg_size, env, CMD_TIMEOUT))
return false;
// Wait for the response
response_mutex.Lock();
rx_cond.timed_wait(response_mutex, CMD_TIMEOUT);
auto _response = response;
response_mutex.Unlock();
if (_response == ACK)
// ACK received, finish
return true;
// No ACK received, retry
retries--;
} while (retries);
return false;
}
示例2: main
int main(){
Mutex mutex;
cout << mutex.Lock() << endl;
cout << mutex.Unlock() << endl;
cout << mutex.Unlock() << endl;
cout << mutex.Lock() << endl;
return 0;
}
示例3: wait
bool Condition::wait(Mutex& mutex, long timeout)
{
#if defined(WIN32)
m_impl -> PreWait();
mutex.Unlock();
try
{
bool rc = m_impl -> Wait(timeout);
mutex.Lock();
return rc;
}
catch(...)
{
mutex.Lock();
throw;
}
#else
int ret = 0;
if (timeout < 0)
{
ret = pthread_cond_wait(&m_cond, &mutex.m_mutex);
}
else
{
struct timespec abstime = CalcAbsTime(timeout);
ret = pthread_cond_timedwait(&m_cond, &mutex.m_mutex, &abstime);
}
if (ret==0)
{
return true;
}
else
{
if (errno==EINTR)
{
THROW_EXCEPTION(InterruptedException,"pthread_cond_timedwait failed",errno);
}
else if (errno==ETIMEDOUT && timeout >= 0)
{
return false;
}
}
return true;
#endif
}
示例4: assert
void
InputEvents::DoQueuedEvents()
{
assert(InMainThread());
int GCE_Queue_copy[MAX_GCE_QUEUE];
int i;
// copy the queue first, blocking
mutexEventQueue.Lock();
std::copy(GCE_Queue, GCE_Queue + MAX_GCE_QUEUE, GCE_Queue_copy);
std::fill(GCE_Queue, GCE_Queue + MAX_GCE_QUEUE, -1);
mutexEventQueue.Unlock();
// process each item in the queue
for (i = 0; i < MAX_GCE_QUEUE; i++) {
if (GCE_Queue_copy[i] != -1) {
processGlideComputer_real(GCE_Queue_copy[i]);
}
}
for (i = 0; i < MAX_NMEA_QUEUE; i++) {
if (NMEA_Queue[i] != -1)
processNmea_real(NMEA_Queue[i]);
}
}
示例5: sizeof
// ******************************************************************
// * CxbxRtlAllocDebug - Debug track RTL alloc
// ******************************************************************
void *CxbxRtlAllocDebug(HANDLE Heap,
DWORD Flags,
SIZE_T Bytes,
char *pFile,
int Line)
{
void *pRetMem = NULL;
g_MemoryMutex.Lock();
void *pMem = NtDll::RtlAllocateHeap(Heap, Flags, Bytes + 2 * sizeof(MEMORY_GUARD));
if(!pMem)
{
printf("CxbxRtlAllocDebug: Allocation failed\n"
" Heap : 0x%.08X\n"
" Flags : 0x%.08X\n"
" Bytes : %d\n"
" File : %s\n"
" Line : %d\n",
Heap, Flags, Bytes, pFile, Line);
}
else
{
CXBX_MEMORY_BLOCK *pBlock = InsertMemoryBlock(pMem,
Bytes,
pFile,
Line,
CXBX_ALLOC_RTL);
pRetMem = pBlock->pMem;
}
g_MemoryMutex.Unlock();
return pRetMem;
}
示例6: calloc
// ******************************************************************
// * CxbxCallocDebug - Debug track calloc
// ******************************************************************
void *CxbxCallocDebug(size_t NbrElements,
size_t ElementSize,
char *pFile,
int Line)
{
void *pRetMem = NULL;
g_MemoryMutex.Lock();
void *pMem = calloc(NbrElements * ElementSize + 2 * sizeof(MEMORY_GUARD), 1);
if(!pMem)
{
printf("CxbxCallocDebug: Allocation failed\n"
" NbrElements: %d\n"
" ElementSize: %d\n"
" File : %s\n"
" Line : %d\n",
NbrElements, ElementSize, pFile, Line);
}
else
{
CXBX_MEMORY_BLOCK *pBlock = InsertMemoryBlock(pMem,
NbrElements * ElementSize,
pFile,
Line,
CXBX_ALLOC_NORMAL);
pRetMem = pBlock->pMem;
}
g_MemoryMutex.Unlock();
return pRetMem;
}
示例7: getInstance
static Cursor& getInstance() {
sLock.Lock();
if( sInstance==0 ) sInstance = new Cursor;
sLock.UnLock();
return *sInstance;
}
示例8: ClientThread
// Function that generates clients to receive messages.
void ClientThread(void* args)
{
MessageClient client;
std::string message;
unsigned int count = 0;
unsigned int total = 0;
if(client.Initialize(gServerID, MessageClient::AnyID, MappedMessageBox::DefaultSize, false))
{
while(gQuitFlag == false)
{
// See if a message has been received by this
// client process. A better method would be to
// use a callback so you don't have to poll.
if(client.ReadMessage(message))
{
++total;
// Only print to the screen every N messages, failure to do
// so will skew performance results because it takes time to
// write to the console window.
if(++count == 100)
{
count = 0;
gPrintMutex.Lock();
// Display the percent of messages generated that we've been
// able to receive.
cout << client.GetID() << " Received " << total*100.0/gTotalMessages << " Percent" << endl;
gPrintMutex.Unlock();
}
}
SleepMs(1);
}
}
}
示例9:
__declspec(dllexport) void __stdcall WH_KEYBOARD_LL_Block(unsigned long virtualkeycode)
{
mWH_KEYBOARD_LL_Keys.Lock(true);
sWH_KEYBOARD_LL_Keys.remove(virtualkeycode);
sWH_KEYBOARD_LL_Keys.push_back(virtualkeycode);
mWH_KEYBOARD_LL_Keys.Unlock();
}
示例10: startSendInfo
UINT startSendInfo(LPVOID lpParam)
{
mx.Lock();
sender.SendInfo();
return 0;
mx.Unlock();
}
示例11:
bool
System::Startup(
int*, char**)
{
Mutex mutex;
mutex.Lock();
{
System::m_StartupTime = Process::GetTimeInSeconds();
Process::Startup();
ThreadEngine::Startup();
LogEngine::Startup();
ResourceEngine::Startup();
Symbol::CreateRegistry();
MetaClass::CreateRegistry();
vd::f64 dt = Process::GetTimeInSeconds();
vdLogGlobalInfo("Void Framework v%d.%d.%d - %s: startup time '%f' sec",
VD_VERSION_MAJOR,
VD_VERSION_MINOR,
VD_VERSION_PATCH,
VD_BUILD_INFO,
dt - m_StartupTime);
}
mutex.Unlock();
return true;
}
示例12: AddMap
int MidiInstrumentMapper::AddMap(String MapName) throw (Exception) {
int ID;
midiMapsMutex.Lock();
if (midiMaps.empty()) ID = 0;
else {
// get the highest existing map ID
uint lastIndex = (--(midiMaps.end()))->first;
// check if we reached the index limit
if (lastIndex + 1 < lastIndex) {
// search for an unoccupied map ID starting from 0
for (uint i = 0; i < lastIndex; i++) {
if (midiMaps.find(i) != midiMaps.end()) continue;
// we found an unused ID, so insert the new map there
ID = i;
goto __create_map;
}
throw Exception("Internal error: could not find unoccupied MIDI instrument map ID.");
}
ID = lastIndex + 1;
}
__create_map:
midiMaps[ID].name = MapName;
fireMidiInstrumentMapCountChanged(Maps().size());
// If there were no maps until now we must set a default map.
if (midiMaps.size() == 1) SetDefaultMap(ID);
midiMapsMutex.Unlock();
return ID;
}
示例13: if
void
ManagedFileListWidget::OnDownloadComplete(Path path_relative,
bool success)
{
const auto name = path_relative.GetBase();
if (name == nullptr)
return;
const WideToUTF8Converter name2(name.c_str());
if (!name2.IsValid())
return;
const std::string name3(name2);
mutex.Lock();
downloads.erase(name3);
if (StringIsEqual(name2, "repository")) {
repository_failed = !success;
if (success)
repository_modified = true;
} else if (!success)
failures.insert(name3);
mutex.Unlock();
SendNotification();
}
示例14: RemoveAllMaps
void MidiInstrumentMapper::RemoveAllMaps() {
midiMapsMutex.Lock();
midiMaps.clear();
SetDefaultMap(-1);
fireMidiInstrumentMapCountChanged(Maps().size());
midiMapsMutex.Unlock();
}
示例15: SetDefaultMap
void MidiInstrumentMapper::SetDefaultMap(int MapId) {
midiMapsMutex.Lock();
DefaultMap = MapId;
midiMapsMutex.Unlock();
if (MapId != -1) fireMidiInstrumentMapInfoChanged(MapId);
}