本文整理汇总了C++中std::recursive_mutex::lock方法的典型用法代码示例。如果您正苦于以下问题:C++ recursive_mutex::lock方法的具体用法?C++ recursive_mutex::lock怎么用?C++ recursive_mutex::lock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::recursive_mutex
的用法示例。
在下文中一共展示了recursive_mutex::lock方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: f
void f()
{
time_point t0 = Clock::now();
m.lock();
time_point t1 = Clock::now();
m.lock();
m.unlock();
m.unlock();
ns d = t1 - t0 - ms(250);
assert(d < ns(2500000)); // within 2.5ms
}
示例2: __AudioMix
// numFrames is number of stereo frames.
// This is called from *outside* the emulator thread.
int __AudioMix(short *outstereo, int numFrames)
{
// TODO: if mixFrequency != the actual output frequency, resample!
section.lock();
int underrun = -1;
s16 sampleL = 0;
s16 sampleR = 0;
bool anythingToPlay = false;
for (int i = 0; i < numFrames; i++) {
if (outAudioQueue.size() >= 2)
{
sampleL = outAudioQueue.pop_front();
sampleR = outAudioQueue.pop_front();
outstereo[i * 2 + 0] = sampleL;
outstereo[i * 2 + 1] = sampleR;
anythingToPlay = true;
} else {
if (underrun == -1) underrun = i;
outstereo[i * 2 + 0] = sampleL; // repeat last sample, can reduce clicking
outstereo[i * 2 + 1] = sampleR; // repeat last sample, can reduce clicking
}
}
if (anythingToPlay && underrun >= 0) {
DEBUG_LOG(HLE, "Audio out buffer UNDERRUN at %i of %i", underrun, numFrames);
} else {
// DEBUG_LOG(HLE, "No underrun, mixed %i samples fine", numFrames);
}
section.unlock();
return underrun >= 0 ? underrun : numFrames;
}
示例3: StartRecording
void FifoRecorder::StartRecording(s32 numFrames, CallbackFunc finishedCb)
{
sMutex.lock();
delete m_File;
delete []m_Ram;
delete []m_ExRam;
m_File = new FifoDataFile;
m_Ram = new u8[Memory::RAM_SIZE];
m_ExRam = new u8[Memory::EXRAM_SIZE];
memset(m_Ram, 0, Memory::RAM_SIZE);
memset(m_ExRam, 0, Memory::EXRAM_SIZE);
m_File->SetIsWii(SConfig::GetInstance().m_LocalCoreStartupParameter.bWii);
if (!m_IsRecording)
{
m_WasRecording = false;
m_IsRecording = true;
m_RecordFramesRemaining = numFrames;
}
m_RequestedRecordingEnd = false;
m_FinishedCb = finishedCb;
sMutex.unlock();
}
示例4: __AudioDoState
void __AudioDoState(PointerWrap &p)
{
section.lock();
p.Do(eventAudioUpdate);
CoreTiming::RestoreRegisterEvent(eventAudioUpdate, "AudioUpdate", &hleAudioUpdate);
p.Do(eventHostAudioUpdate);
CoreTiming::RestoreRegisterEvent(eventHostAudioUpdate, "AudioUpdateHost", &hleHostAudioUpdate);
p.Do(mixFrequency);
outAudioQueue.DoState(p);
int chanCount = ARRAY_SIZE(chans);
p.Do(chanCount);
if (chanCount != ARRAY_SIZE(chans))
{
ERROR_LOG(HLE, "Savestate failure: different number of audio channels.");
section.unlock();
return;
}
for (int i = 0; i < chanCount; ++i)
chans[i].DoState(p);
section.unlock();
p.DoMarker("sceAudio");
}
示例5: __AudioEnqueue
u32 __AudioEnqueue(AudioChannel &chan, int chanNum, bool blocking)
{
u32 ret = 0;
section.lock();
if (chan.sampleAddress == 0)
return SCE_ERROR_AUDIO_NOT_OUTPUT;
if (chan.sampleQueue.size() > chan.sampleCount*2*chanQueueMaxSizeFactor) {
// Block!
if (blocking) {
chan.waitingThread = __KernelGetCurThread();
// WARNING: This changes currentThread so must grab waitingThread before (line above).
__KernelWaitCurThread(WAITTYPE_AUDIOCHANNEL, (SceUID)chanNum, 0, 0, false, "blocking audio waited");
// Fall through to the sample queueing, don't want to lose the samples even though
// we're getting full.
}
else
{
chan.waitingThread = 0;
return SCE_ERROR_AUDIO_CHANNEL_BUSY;
}
}
if (chan.format == PSP_AUDIO_FORMAT_STEREO)
{
const u32 totalSamples = chan.sampleCount * 2;
if (IS_LITTLE_ENDIAN)
{
s16 *sampleData = (s16 *) Memory::GetPointer(chan.sampleAddress);
// Walking a pointer for speed. But let's make sure we wouldn't trip on an invalid ptr.
if (Memory::IsValidAddress(chan.sampleAddress + (totalSamples - 1) * sizeof(s16)))
{
for (u32 i = 0; i < totalSamples; i++)
chan.sampleQueue.push(*sampleData++);
}
}
else
{
for (u32 i = 0; i < totalSamples; i++)
chan.sampleQueue.push((s16)Memory::Read_U16(chan.sampleAddress + sizeof(s16) * i));
}
ret = chan.sampleCount;
}
else if (chan.format == PSP_AUDIO_FORMAT_MONO)
{
for (u32 i = 0; i < chan.sampleCount; i++)
{
// Expand to stereo
s16 sample = (s16)Memory::Read_U16(chan.sampleAddress + 2 * i);
chan.sampleQueue.push(sample);
chan.sampleQueue.push(sample);
}
ret = chan.sampleCount;
}
section.unlock();
return ret;
}
示例6: main
int main()
{
m.lock();
std::thread t(f);
std::this_thread::sleep_for(ms(250));
m.unlock();
t.join();
}
示例7: __AudioUpdate
// Mix samples from the various audio channels into a single sample queue.
// This single sample queue is where __AudioMix should read from. If the sample queue is full, we should
// just sleep the main emulator thread a little.
void __AudioUpdate()
{
// Audio throttle doesn't really work on the PSP since the mixing intervals are so closely tied
// to the CPU. Much better to throttle the frame rate on frame display and just throw away audio
// if the buffer somehow gets full.
s32 mixBuffer[hwBlockSize * 2];
memset(mixBuffer, 0, sizeof(mixBuffer));
for (int i = 0; i < PSP_AUDIO_CHANNEL_MAX; i++)
{
if (!chans[i].reserved)
continue;
if (!chans[i].sampleQueue.size()) {
// ERROR_LOG(HLE, "No queued samples, skipping channel %i", i);
continue;
}
for (int s = 0; s < hwBlockSize; s++)
{
if (chans[i].sampleQueue.size() >= 2)
{
s16 sampleL = chans[i].sampleQueue.pop_front();
s16 sampleR = chans[i].sampleQueue.pop_front();
mixBuffer[s * 2 + 0] += sampleL;
mixBuffer[s * 2 + 1] += sampleR;
}
else
{
ERROR_LOG(HLE, "Channel %i buffer underrun at %i of %i", i, s, hwBlockSize);
break;
}
}
if (chans[i].sampleQueue.size() < chans[i].sampleCount * 2 * chanQueueMinSizeFactor)
{
// Ask the thread to send more samples until next time, queue is being drained.
if (chans[i].waitingThread) {
SceUID waitingThread = chans[i].waitingThread;
chans[i].waitingThread = 0;
// DEBUG_LOG(HLE, "Woke thread %i for some buffer filling", waitingThread);
__KernelResumeThreadFromWait(waitingThread, chans[i].sampleCount);
}
}
}
if (g_Config.bEnableSound) {
section.lock();
if (outAudioQueue.room() >= hwBlockSize * 2) {
// Push the mixed samples onto the output audio queue.
for (int i = 0; i < hwBlockSize; i++) {
s32 sampleL = mixBuffer[i * 2 + 0] >> 2; // TODO - what factor?
s32 sampleR = mixBuffer[i * 2 + 1] >> 2;
outAudioQueue.push((s16)sampleL);
outAudioQueue.push((s16)sampleR);
}
} else {
示例8: __AudioUpdate
// Mix samples from the various audio channels into a single sample queue.
// This single sample queue is where __AudioMix should read from. If the sample queue is full, we should
// just sleep the main emulator thread a little.
void __AudioUpdate()
{
// Audio throttle doesn't really work on the PSP since the mixing intervals are so closely tied
// to the CPU. Much better to throttle the frame rate on frame display and just throw away audio
// if the buffer somehow gets full.
s32 mixBuffer[hwBlockSize * 2];
memset(mixBuffer, 0, sizeof(mixBuffer));
for (u32 i = 0; i < PSP_AUDIO_CHANNEL_MAX + 1; i++)
{
if (!chans[i].reserved)
continue;
__AudioWakeThreads(chans[i], hwBlockSize);
if (!chans[i].sampleQueue.size()) {
// ERROR_LOG(HLE, "No queued samples, skipping channel %i", i);
continue;
}
for (int s = 0; s < hwBlockSize; s++)
{
if (chans[i].sampleQueue.size() >= 2)
{
s16 sampleL = chans[i].sampleQueue.pop_front();
s16 sampleR = chans[i].sampleQueue.pop_front();
mixBuffer[s * 2 + 0] += sampleL;
mixBuffer[s * 2 + 1] += sampleR;
}
else
{
ERROR_LOG(HLE, "Channel %i buffer underrun at %i of %i", i, s, hwBlockSize);
break;
}
}
}
if (g_Config.bEnableSound) {
section.lock();
if (outAudioQueue.room() >= hwBlockSize * 2) {
// Push the mixed samples onto the output audio queue.
for (int i = 0; i < hwBlockSize; i++) {
s16 sampleL = clamp_s16(mixBuffer[i * 2 + 0]);
s16 sampleR = clamp_s16(mixBuffer[i * 2 + 1]);
outAudioQueue.push((s16)sampleL);
outAudioQueue.push((s16)sampleR);
}
} else {
// This happens quite a lot. There's still something slightly off
// about the amount of audio we produce.
DEBUG_LOG(HLE, "Audio outbuffer overrun! room = %i / %i", outAudioQueue.room(), (u32)outAudioQueue.capacity());
}
section.unlock();
}
}
示例9: RecordingFinished
void FifoPlayerDlg::RecordingFinished()
{
sMutex.lock();
if (m_EvtHandler)
{
wxCommandEvent event(RECORDING_FINISHED_EVENT);
m_EvtHandler->AddPendingEvent(event);
}
sMutex.unlock();
}
示例10: FileLoaded
void FifoPlayerDlg::FileLoaded()
{
sMutex.lock();
if (m_EvtHandler)
{
wxPaintEvent event;
m_EvtHandler->AddPendingEvent(event);
}
sMutex.unlock();
}
示例11: FrameWritten
void FifoPlayerDlg::FrameWritten()
{
sMutex.lock();
if (m_EvtHandler)
{
wxCommandEvent event(FRAME_WRITTEN_EVENT);
m_EvtHandler->AddPendingEvent(event);
}
sMutex.unlock();
}
示例12: GetEventHandler
FifoPlayerDlg::FifoPlayerDlg(wxWindow * const parent) :
wxDialog(parent, wxID_ANY, _("FIFO Player"), wxDefaultPosition, wxDefaultSize),
m_FramesToRecord(1)
{
CreateGUIControls();
sMutex.lock();
m_EvtHandler = GetEventHandler();
sMutex.unlock();
FifoPlayer::GetInstance().SetFileLoadedCallback(FileLoaded);
FifoPlayer::GetInstance().SetFrameWrittenCallback(FrameWritten);
}
示例13: attemp_10k_increasesR
void attemp_10k_increasesR() {
int i;
mrtx.lock();
mrtx.lock(); // 递归锁,多次调用lock都不会死锁
for (i=0; i<10; ++i) {
++counter;
std::this_thread::sleep_for(std::chrono::microseconds(1*1000000));
std::cout << "thread Reverse[" << std::this_thread::get_id() <<"]" << "add the counter" << endl;
}
mrtx.unlock();
}
示例14: EndFrame
void FifoRecorder::EndFrame(u32 fifoStart, u32 fifoEnd)
{
// m_IsRecording is assumed to be true at this point, otherwise this function would not be called
sMutex.lock();
m_FrameEnded = true;
m_CurrentFrame.fifoStart = fifoStart;
m_CurrentFrame.fifoEnd = fifoEnd;
if (m_WasRecording)
{
// If recording a fixed number of frames then check if the end of the recording was reached
if (m_RecordFramesRemaining > 0)
{
--m_RecordFramesRemaining;
if (m_RecordFramesRemaining == 0)
m_RequestedRecordingEnd = true;
}
}
else
{
m_WasRecording = true;
// Skip the first data which will be the frame copy command
m_SkipNextData = true;
m_SkipFutureData = false;
m_FrameEnded = false;
m_FifoData.reserve(1024 * 1024 * 4);
m_FifoData.clear();
}
if (m_RequestedRecordingEnd)
{
// Skip data after the next time WriteFifoData is called
m_SkipFutureData = true;
// Signal video backend that it should not call this function when the next frame ends
m_IsRecording = false;
}
sMutex.unlock();
}
示例15: SetVideoMemory
void FifoRecorder::SetVideoMemory(u32 *bpMem, u32 *cpMem, u32 *xfMem, u32 *xfRegs, u32 xfRegsSize)
{
sMutex.lock();
if (m_File)
{
memcpy(m_File->GetBPMem(), bpMem, FifoDataFile::BP_MEM_SIZE * 4);
memcpy(m_File->GetCPMem(), cpMem, FifoDataFile::CP_MEM_SIZE * 4);
memcpy(m_File->GetXFMem(), xfMem, FifoDataFile::XF_MEM_SIZE * 4);
u32 xfRegsCopySize = std::min((u32)FifoDataFile::XF_REGS_SIZE, xfRegsSize);
memcpy(m_File->GetXFRegs(), xfRegs, xfRegsCopySize * 4);
}
m_RecordAnalyzer.Initialize(bpMem, cpMem);
sMutex.unlock();
}