本文整理汇总了C++中MutexType::Lock方法的典型用法代码示例。如果您正苦于以下问题:C++ MutexType::Lock方法的具体用法?C++ MutexType::Lock怎么用?C++ MutexType::Lock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MutexType
的用法示例。
在下文中一共展示了MutexType::Lock方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SDL_AudioCallbackX
static void SDL_AudioCallbackX(void *, Uint8 *stream, int len)
{
SDL_LockAudio();
//short *target = (short *) stream;
g_audioBuffer_lock.Lock();
unsigned ate = len; // number of bytes
if(ate > g_audioBuffer.size())
ate = (unsigned)g_audioBuffer.size();
for(unsigned a = 0; a < ate; ++a)
stream[a] = g_audioBuffer[a];
g_audioBuffer.erase(g_audioBuffer.begin(), g_audioBuffer.begin() + ate);
g_audioBuffer_lock.Unlock();
SDL_UnlockAudio();
}
示例2: main
int main( int nArgs, const char * const args[] )
{
if( nArgs != 2 )
{
printf("%s: <image>\n", args[0] );
return 1;
}
const char * infile = args[1];
std::vector<uint8_t> fbuf;
{
std::ifstream f( infile, std::ios::binary | std::ios::ate );
if( !f.is_open() )
{
printf("Unable to open %s\n",infile);
return 2;
}
fbuf.resize( f.tellg() );
f.seekg(0);
f.read( (char*)&fbuf[0], fbuf.size() );
if( f.gcount() != fbuf.size() )
{
printf("Unable to fully read %s\n",infile);
return 3;
}
}
printf( "Scanning binary for strings...\n" );
stable str_table = get_strings( fbuf );
printf( "Total strings found: %d\n", str_table.size() );
printf( "Scanning binary for pointers...\n" );
ptable ptr_table = get_pointers( fbuf );
printf( "Total pointers found: %d\n", ptr_table.size() );
// signal.signal(signal.SIGINT, high_scores)
MutexType mutex; //protects next few variables
unsigned top_score = 0;
scorecard scores;
#ifdef _OPENMP
#pragma omp parallel for
#endif
for( offset_t base = 0; base < 0xf0000000UL; base += 0x1000 )
{
#ifndef _OPENMP
//Turn off status display when using OpenMP
//otherwise the numbers will be scrabled
if( base % 0x10000 == 0 )
printf( "Trying base address 0x%x\n", base );
#endif
unsigned score = 0;
for(ptable::iterator iter = ptr_table.begin(); iter != ptr_table.end(); ++iter)
{
offset_t ptr = iter->first;
if( ptr < base )
continue;
if( ptr >= (base + fbuf.size()) )
continue;
unsigned offset = ptr - base;
if( str_table.find(offset) != str_table.end() )
score += iter->second;
}
if( score )
{
mutex.Lock();
scores.push_back( std::make_pair( score, base ) );
if( score > top_score )
{
top_score = score;
printf( "New highest score, 0x%x: %d\n", base, score );
}
mutex.Unlock();
}
}
std::sort(scores.begin(),scores.end() );
high_scores( scores );
}
示例3: main
//.........这里部分代码省略.........
# ifndef HARDWARE_OPL3
size_t got = (size_t)adl_playFormat(myDevice, 4096,
buff,
buff + g_audioFormat.containerSize,
&g_audioFormat) * g_audioFormat.containerSize;
if(got <= 0)
break;
# endif
# ifdef DEBUG_TRACE_ALL_CHANNELS
enum { TerminalColumns = 80 };
char channelText[TerminalColumns + 1];
char channelAttr[TerminalColumns + 1];
adl_describeChannels(myDevice, channelText, channelAttr, sizeof(channelText));
std::fprintf(stdout, "%*s\r", TerminalColumns, ""); // erase the line
std::fprintf(stdout, "%s\n", channelText);
# endif
# ifndef DEBUG_TRACE_ALL_EVENTS
double time_pos = adl_positionTell(myDevice);
std::fprintf(stdout, " \r");
uint64_t milliseconds = static_cast<uint64_t>(time_pos * 1000.0);
if(milliseconds != milliseconds_prev)
{
secondsToHMSM(time_pos, posHMS, 25);
std::fprintf(stdout, " \r");
std::fprintf(stdout, "Time position: %s / %s\r", posHMS, totalHMS);
flushout(stdout);
milliseconds_prev = milliseconds;
}
# endif
# ifndef HARDWARE_OPL3
g_audioBuffer_lock.Lock();
size_t pos = g_audioBuffer.size();
g_audioBuffer.resize(pos + got);
for(size_t p = 0; p < got; ++p)
g_audioBuffer[pos + p] = buff[p];
g_audioBuffer_lock.Unlock();
const SDL_AudioSpec &spec = obtained;
while(g_audioBuffer.size() > static_cast<size_t>(spec.samples + (spec.freq * g_audioFormat.sampleOffset) * OurHeadRoomLength))
{
SDL_Delay(1);
}
# ifdef DEBUG_SEEKING_TEST
if(delayBeforeSeek-- <= 0)
{
delayBeforeSeek = rand() % 50;
double seekTo = double((rand() % int(adl_totalTimeLength(myDevice)) - delayBeforeSeek - 1 ));
adl_positionSeek(myDevice, seekTo);
}
# endif
# else//HARDWARE_OPL3
const double mindelay = 1.0 / NewTimerFreq;
//__asm__ volatile("sti\nhlt");
//usleep(10000);
#ifdef __DJGPP__
__dpmi_yield();
#endif
#ifdef __WATCOMC__
//dpmi_dos_yield();
mch_delay((unsigned int)(tick_delay * 1000.0));