本文整理汇总了C++中MutexType类的典型用法代码示例。如果您正苦于以下问题:C++ MutexType类的具体用法?C++ MutexType怎么用?C++ MutexType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MutexType类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: try_based_timed_lock
bool try_based_timed_lock(MutexType &m, const boost::posix_time::ptime &abs_time)
{
//Same as lock()
if(abs_time == boost::posix_time::pos_infin){
m.lock();
return true;
}
//Always try to lock to achieve POSIX guarantees:
// "Under no circumstance shall the function fail with a timeout if the mutex
// can be locked immediately. The validity of the abs_timeout parameter need not
// be checked if the mutex can be locked immediately."
else if(m.try_lock()){
return true;
}
else{
spin_wait swait;
while(microsec_clock::universal_time() < abs_time){
if(m.try_lock()){
return true;
}
swait.yield();
}
return false;
}
}
示例2: try_based_lock
void try_based_lock(MutexType &m)
{
if(!m.try_lock()){
spin_wait swait;
do{
if(m.try_lock()){
break;
}
else{
swait.yield();
}
}
while(1);
}
}
示例3: activate
void activate(MutexType& m_)
{
m_.unlock();
m=&m_;
}
示例4: 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 );
}
示例5: 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();
}
示例6:
~lock_on_exit()
{
if(m)
{
m->lock();
}
}
示例7: main
int main(int argc, char **argv)
{
std::fprintf(stdout, "==========================================\n"
#ifdef HARDWARE_OPL3
" libADLMIDI demo utility (HW OPL)\n"
#else
" libADLMIDI demo utility\n"
#endif
"==========================================\n\n");
flushout(stdout);
if(argc < 2 || std::string(argv[1]) == "--help" || std::string(argv[1]) == "-h")
{
std::printf(
"Usage: adlmidi <midifilename> [ <options> ] [ <bank> [ <numchips> [ <numfourops>] ] ]\n"
" -p Enables adlib percussion instrument mode\n"
" -t Enables tremolo amplification mode\n"
" -v Enables vibrato amplification mode\n"
" -s Enables scaling of modulator volumes\n"
" -frb Enables full-ranged CC74 XG Brightness controller\n"
" -nl Quit without looping\n"
" -w Write WAV file rather than playing\n"
" -mb Run the test of multibank over embedded. 62, 14, 68, and 74'th banks will be combined into one\n"
" --solo <track> Selects a solo track to play\n"
" --only <track1,...,trackN> Selects a subset of tracks to play\n"
#ifndef HARDWARE_OPL3
" -fp Enables full-panning stereo support\n"
" --emu-nuked Uses Nuked OPL3 v 1.8 emulator\n"
" --emu-nuked7 Uses Nuked OPL3 v 1.7.4 emulator\n"
" --emu-dosbox Uses DosBox 0.74 OPL3 emulator\n"
#endif
"\n"
"Where <bank> - number of embeeded bank or filepath to custom WOPL bank file\n"
"\n"
"Note: To create WOPL bank files use OPL Bank Editor you can get here: \n"
"https://github.com/Wohlstand/OPL3BankEditor\n"
"\n"
);
// Get count of embedded banks (no initialization needed)
int banksCount = adl_getBanksCount();
//Get pointer to list of embedded bank names
const char *const *banknames = adl_getBankNames();
if(banksCount > 0)
{
std::printf(" Available embedded banks by number:\n\n");
for(int a = 0; a < banksCount; ++a)
std::printf("%10s%2u = %s\n", a ? "" : "Banks:", a, banknames[a]);
std::printf(
"\n"
" Use banks 2-5 to play Descent \"q\" soundtracks.\n"
" Look up the relevant bank number from descent.sng.\n"
"\n"
" The fourth parameter can be used to specify the number\n"
" of four-op channels to use. Each four-op channel eats\n"
" the room of two regular channels. Use as many as required.\n"
" The Doom & Hexen sets require one or two, while\n"
" Miles four-op set requires the maximum of numcards*6.\n"
"\n"
);
}
else
{
std::printf(" This build of libADLMIDI has no embedded banks!\n\n");
}
flushout(stdout);
return 0;
}
long sampleRate = 44100;
#ifndef HARDWARE_OPL3
//const unsigned MaxSamplesAtTime = 512; // 512=dbopl limitation
// How long is SDL buffer, in seconds?
// The smaller the value, the more often SDL_AudioCallBack()
// is called.
const double AudioBufferLength = 0.08;
// How much do WE buffer, in seconds? The smaller the value,
// the more prone to sound chopping we are.
const double OurHeadRoomLength = 0.1;
// The lag between visual content and audio content equals
// the sum of these two buffers.
#ifndef OUTPUT_WAVE_ONLY
SDL_AudioSpec spec;
SDL_AudioSpec obtained;
spec.freq = (int)sampleRate;
spec.format = AUDIO_S16SYS;
spec.channels = 2;
spec.samples = Uint16((double)spec.freq * AudioBufferLength);
spec.callback = SDL_AudioCallbackX;
#endif //OUTPUT_WAVE_ONLY
#endif //HARDWARE_OPL3
ADL_MIDIPlayer *myDevice;
//.........这里部分代码省略.........