AL_API void AL_APIENTRY alBufferSubSamplesSOFT(ALuint buffer, ALsizei offset, ALsizei samples, ALenum channels, ALenum type, const ALvoid *data) { ALCdevice *device; ALCcontext *context; ALbuffer *albuf; ALsizei align; context = GetContextRef(); if(!context) return; device = context->Device; if((albuf=LookupBuffer(device, buffer)) == NULL) SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done); if(!(samples >= 0 && offset >= 0)) SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done); if(IsValidType(type) == AL_FALSE) SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done); WriteLock(&albuf->lock); align = albuf->UnpackAlign; if(SanitizeAlignment(type, &align) == AL_FALSE) { WriteUnlock(&albuf->lock); SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done); } if(channels != (ALenum)albuf->FmtChannels) { WriteUnlock(&albuf->lock); SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done); } if(offset > albuf->SampleLen || samples > albuf->SampleLen-offset) { WriteUnlock(&albuf->lock); SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done); } if((samples%align) != 0) { WriteUnlock(&albuf->lock); SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done); } /* offset -> byte offset */ offset *= FrameSizeFromFmt(albuf->FmtChannels, albuf->FmtType); ConvertData((char*)albuf->data+offset, (enum UserFmtType)albuf->FmtType, data, type, ChannelsFromFmt(albuf->FmtChannels), samples, align); WriteUnlock(&albuf->lock); done: ALCcontext_DecRef(context); }
AL_API ALvoid AL_APIENTRY alDeleteSoundfontsSOFT(ALsizei n, const ALuint *ids) { ALCdevice *device; ALCcontext *context; ALsoundfont *sfont; ALsizei i; context = GetContextRef(); if(!context) return; if(!(n >= 0)) SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done); device = context->Device; for(i = 0;i < n;i++) { /* Check for valid soundfont ID */ if(ids[i] == 0) { if(!(sfont=device->DefaultSfont)) continue; } else if((sfont=LookupSfont(device, ids[i])) == NULL) SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done); if(ReadRef(&sfont->ref) != 0) SET_ERROR_AND_GOTO(context, AL_INVALID_OPERATION, done); } for(i = 0;i < n;i++) { if(ids[i] == 0) { MidiSynth *synth = device->Synth; WriteLock(&synth->Lock); if(device->DefaultSfont != NULL) ALsoundfont_deleteSoundfont(device->DefaultSfont, device); device->DefaultSfont = NULL; WriteUnlock(&synth->Lock); continue; } else if((sfont=RemoveSfont(device, ids[i])) == NULL) continue; ALsoundfont_Destruct(sfont); memset(sfont, 0, sizeof(*sfont)); free(sfont); } done: ALCcontext_DecRef(context); }
/****************************************************************************** 函数名 :CRWScopeGuard 功能 :构造函数,加系统锁 输入 :无 输出 :无 返回值 :无 其他 :无 ******************************************************************************/ CRWScopeGuard::CRWScopeGuard(CRWLock& rwlock,bool is_readlock) { m_prwLock = &rwlock; if(is_readlock) { ReadLock(); } else { WriteLock(); } }
AL_API ALvoid AL_APIENTRY alListenerfv(ALenum param, const ALfloat *values) { ALCcontext *context; if(values) { switch(param) { case AL_GAIN: case AL_METERS_PER_UNIT: alListenerf(param, values[0]); return; case AL_POSITION: case AL_VELOCITY: alListener3f(param, values[0], values[1], values[2]); return; } } context = GetContextRef(); if(!context) return; WriteLock(&context->PropLock); if(!(values)) SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done); switch(param) { case AL_ORIENTATION: if(!(isfinite(values[0]) && isfinite(values[1]) && isfinite(values[2]) && isfinite(values[3]) && isfinite(values[4]) && isfinite(values[5]))) SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done); /* AT then UP */ context->Listener->Forward[0] = values[0]; context->Listener->Forward[1] = values[1]; context->Listener->Forward[2] = values[2]; context->Listener->Up[0] = values[3]; context->Listener->Up[1] = values[4]; context->Listener->Up[2] = values[5]; break; default: SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done); } if(!ATOMIC_LOAD(&context->DeferUpdates, almemory_order_acquire)) UpdateListenerProps(context); done: WriteUnlock(&context->PropLock); ALCcontext_DecRef(context); }
void AmChannelPressureControl::NotifyHook(int32 newValue) { if (!mContainer || !mChannelPressure) return; // WRITE TRACK BLOCK AmSong* song = WriteLock(); AmTrack* track = song ? song->Track(mTrackRef) : NULL; if (track) { if (!mUndo) PrepareUndoState(track, mContainer->Phrase(), mChannelPressure); mChannelPressure->SetPressure(newValue); if (mUndo) mUndo->EventChanged(mChannelPressure); } WriteUnlock(song); // END WRITE TRACK BLOCK }
void AmVelocityView::NotifyHook(int32 newValue) { if (!mContainer || !mNoteOn) return; // WRITE TRACK BLOCK AmSong* song = WriteLock(); AmTrack* track = song ? song->Track(mTrackRef) : NULL; if (track) { if (!mUndo) PrepareUndoState(track, mContainer->Phrase(), mNoteOn); mNoteOn->SetVelocity(newValue); if (mUndo) mUndo->EventChanged(mNoteOn); } WriteUnlock(song); // END WRITE TRACK BLOCK }
ALenum NewThunkEntry(ALuint *index) { void *NewList; ALuint i; ReadLock(&ThunkLock); for(i = 0;i < ThunkArraySize;i++) { if(ATOMIC_EXCHANGE(ALenum, &ThunkArray[i], AL_TRUE, almemory_order_acq_rel) == AL_FALSE) { ReadUnlock(&ThunkLock); *index = i+1; return AL_NO_ERROR; } } ReadUnlock(&ThunkLock); WriteLock(&ThunkLock); /* Double-check that there's still no free entries, in case another * invocation just came through and increased the size of the array. */ for(;i < ThunkArraySize;i++) { if(ATOMIC_EXCHANGE(ALenum, &ThunkArray[i], AL_TRUE, almemory_order_acq_rel) == AL_FALSE) { WriteUnlock(&ThunkLock); *index = i+1; return AL_NO_ERROR; } } NewList = al_calloc(16, ThunkArraySize*2 * sizeof(*ThunkArray)); if(!NewList) { WriteUnlock(&ThunkLock); ERR("Realloc failed to increase to %u entries!\n", ThunkArraySize*2); return AL_OUT_OF_MEMORY; } memcpy(NewList, ThunkArray, ThunkArraySize*sizeof(*ThunkArray)); al_free(ThunkArray); ThunkArray = NewList; ThunkArraySize *= 2; ATOMIC_STORE_SEQ(&ThunkArray[i], AL_TRUE); WriteUnlock(&ThunkLock); *index = i+1; return AL_NO_ERROR; }
void AmEventTimeView::PrepareUndoState() { if (mUndo) delete mUndo; mUndo = NULL; if (!mContainer || !mEvent) return; // WRITE TRACK BLOCK AmSong* song = WriteLock(); AmTrack* track = song ? song->Track(mTrackRef) : NULL; if (track) { mUndo = new AmChangeEventUndo(track); mUndo->EventChanging(mContainer->Phrase(), mEvent); } WriteUnlock(song); // END WRITE TRACK BLOCK }
AL_API void AL_APIENTRY alMidiPlaySOFT(void) { ALCcontext *context; MidiSynth *synth; context = GetContextRef(); if(!context) return; synth = context->Device->Synth; WriteLock(&synth->Lock); V(synth,setState)(AL_PLAYING); WriteUnlock(&synth->Lock); ALCcontext_DecRef(context); }
void DataPipe::PurgeChunks() { unsigned i; WriteLock(); for (i = 0; i < HOLDCHUNKS; i++) if (chunks[i]) { free(chunks[i]); chunks[i] = NULL; allocated -= sizeof(VChunk); } status = DPIPE_NOTREADY; WriteUnlock(); }
AL_API void AL_APIENTRY alMidiPauseSOFT(void) { ALCcontext *context; MidiSynth *synth; context = GetContextRef(); if(!context) return; synth = context->Device->Synth; WriteLock(&synth->Lock); MidiSynth_setState(synth, AL_PAUSED); WriteUnlock(&synth->Lock); ALCcontext_DecRef(context); }
void DWindowHWInterface::SetOffset(int32 left, int32 top) { if (!WriteLock()) return; fXOffset = left; fYOffset = top; _UpdateFrameBufferConfig(); // TODO: someone would have to call DrawingEngine::Update() now! WriteUnlock(); }
AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSloti(ALuint effectslot, ALenum param, ALint value) { ALCdevice *device; ALCcontext *context; ALeffectslot *slot; ALeffect *effect = NULL; ALenum err; context = GetContextRef(); if(!context) return; WriteLock(&context->PropLock); if((slot=LookupEffectSlot(context, effectslot)) == NULL) SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done); switch(param) { case AL_EFFECTSLOT_EFFECT: device = context->Device; LockEffectsRead(device); effect = (value ? LookupEffect(device, value) : NULL); if(!(value == 0 || effect != NULL)) { UnlockEffectsRead(device); SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done); } err = InitializeEffect(device, slot, effect); UnlockEffectsRead(device); if(err != AL_NO_ERROR) SET_ERROR_AND_GOTO(context, err, done); break; case AL_EFFECTSLOT_AUXILIARY_SEND_AUTO: if(!(value == AL_TRUE || value == AL_FALSE)) SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done); slot->AuxSendAuto = value; UpdateEffectSlotProps(slot, AL_FALSE); break; default: SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done); } done: WriteUnlock(&context->PropLock); ALCcontext_DecRef(context); }
static void WaitForCriticalSection() { time_t now = time(NULL), then = FindLockTime("CF_CRITICAL_SECTION"); /* Another agent has been waiting more than a minute, it means there is likely crash detritus to clear up... After a minute we take our chances ... */ while ((then != -1) && (now - then < 60)) { sleep(1); now = time(NULL); then = FindLockTime("CF_CRITICAL_SECTION"); } WriteLock("CF_CRITICAL_SECTION"); }
bool CInMemoryBuffer::dropTagSafe(PCTAG_NAME tn) { bool ret; //utils_debug("wlock 5\n"); WriteLock(); if(!lock_rtdb(__false, 100)){ Release(); return __false; } ret = dropTag(tn); unlock_rtdb(); //utils_debug("release 10\n"); Release(); return ret; }
AL_API void AL_APIENTRY alListeneriv(ALenum param, const ALint *values) { ALCcontext *context; if(values) { ALfloat fvals[6]; switch(param) { case AL_POSITION: case AL_VELOCITY: alListener3f(param, (ALfloat)values[0], (ALfloat)values[1], (ALfloat)values[2]); return; case AL_ORIENTATION: fvals[0] = (ALfloat)values[0]; fvals[1] = (ALfloat)values[1]; fvals[2] = (ALfloat)values[2]; fvals[3] = (ALfloat)values[3]; fvals[4] = (ALfloat)values[4]; fvals[5] = (ALfloat)values[5]; alListenerfv(param, fvals); return; } } context = GetContextRef(); if(!context) return; WriteLock(&context->PropLock); if(!(values)) SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done); switch(param) { default: SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done); } if(!ATOMIC_LOAD(&context->DeferUpdates, almemory_order_acquire)) UpdateListenerProps(context); done: WriteUnlock(&context->PropLock); ALCcontext_DecRef(context); }
DWORD CNdasServiceDwordConfig::Get( NDASSVC_CONFIG_DWORD_TYPE Type) { SIZE_T i = (SIZE_T) Type; XTLASSERT(i < DEF_SIZE); if (i >= DEF_SIZE) return 0; ReadLock(); if (m_cached[i]) { DWORD data = m_data[i]; ReadUnlock(); return data; } ReadUnlock(); WriteLock(); DWORD value; BOOL fSuccess = _NdasSystemCfg.GetValueEx( SubContainer, NSCONFIG_DWORD_DEF[i].RegValueName, &value); if (fSuccess && value >= NSCONFIG_DWORD_DEF[i].Min && value <= NSCONFIG_DWORD_DEF[i].Max) { m_data[i] = value; } else { m_data[i] = NSCONFIG_DWORD_DEF[i].Default; } m_cached[i] = true; DWORD data = m_data[i]; WriteUnlock(); return data; }
AL_API ALvoid AL_APIENTRY alSpeedOfSound(ALfloat value) { ALCcontext *context; context = GetContextRef(); if(!context) return; if(!(value > 0.0f && isfinite(value))) SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done); WriteLock(&context->PropLock); context->SpeedOfSound = value; if(!ATOMIC_LOAD(&context->DeferUpdates, almemory_order_acquire)) UpdateListenerProps(context); WriteUnlock(&context->PropLock); done: ALCcontext_DecRef(context); }
void AmProgramChangeView::MessageReceived(BMessage* msg) { switch (msg->what) { case PROGRAM_MSG: { int32 number; if (msg->FindInt32("number", &number) == B_OK) { // WRITE SONG BLOCK AmSong* song = WriteLock(); if (song) LockedSetProgramNumber(song, number); WriteUnlock(song); // END WRITE SONG BLOCK } } break; default: inherited::MessageReceived( msg ); } }
BOOL CNdasServiceBoolConfig::Get( NDASSVC_CONFIG_BOOL_TYPE Type) { SIZE_T i = (SIZE_T) Type; XTLASSERT(i < DEF_SIZE); if (i >= DEF_SIZE) return 0; ReadLock(); if (m_cached[i]) { BOOL data = m_data[i]; ReadUnlock(); return data; } ReadUnlock(); WriteLock(); BOOL value; BOOL fSuccess = _NdasSystemCfg.GetValueEx( SubContainer, NSCONFIG_BOOL_DEF[i].RegValueName, &value); if (fSuccess) { m_data[i] = value ? TRUE : FALSE; } else { m_data[i] = NSCONFIG_BOOL_DEF[i].Default; } m_cached[i] = true; BOOL data = m_data[i]; WriteUnlock(); return data; }
void stats::write_finished() { double now = timestamp(); { scoped_mutex_lock WriteLock(write_mutex); double diff = now - p_begin_write; t_writes += double(acc_writes) * diff; p_begin_write = now; p_writes += (acc_writes--) ? diff : 0.0; } { scoped_mutex_lock IOLock(io_mutex); double diff = now - p_begin_io; p_ios += (acc_ios--) ? diff : 0.0; p_begin_io = now; } }
AL_API ALvoid AL_APIENTRY alListeneri(ALenum param, ALint UNUSED(value)) { ALCcontext *context; context = GetContextRef(); if(!context) return; WriteLock(&context->PropLock); switch(param) { default: SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done); } if(!ATOMIC_LOAD(&context->DeferUpdates, almemory_order_acquire)) UpdateListenerProps(context); done: WriteUnlock(&context->PropLock); ALCcontext_DecRef(context); }
ALenum InsertUIntMapEntry(UIntMap *map, ALuint key, ALvoid *value) { ALsizei pos = 0; WriteLock(&map->lock); if(map->size > 0) { ALsizei count = map->size; do { ALsizei step = count>>1; ALsizei i = pos+step; if(map->keys[i] >= key) count = step; else { pos = i+1; count -= step+1; } } while(count > 0); }
MultiLocker::~MultiLocker() { //become the writer if (!IsWriteLocked()) WriteLock(); //set locker to be uninitialized fInit = B_NO_INIT; //delete the semaphores delete_sem(fReadSem); delete_sem(fWriteSem); delete_sem(fWriterLock); #if DEBUG //we are in debug mode! //clear and delete the reader tracking list free(fDebugArray); #endif #if TIMING //let's produce some performance numbers printf("MultiLocker Statistics:\n" "Avg ReadLock: %lld\n" "Avg ReadUnlock: %lld\n" "Avg WriteLock: %lld\n" "Avg WriteUnlock: %lld\n" "Avg IsWriteLocked: %lld\n", rl_count > 0 ? rl_time / rl_count : 0, ru_count > 0 ? ru_time / ru_count : 0, wl_count > 0 ? wl_time / wl_count : 0, wu_count > 0 ? wu_time / wu_count : 0, islock_count > 0 ? islock_time / islock_count : 0 ); #if DEBUG printf( "Avg register_thread: %lld\n" "Avg unregister_thread: %lld\n", reg_count > 0 ? reg_time / reg_count : 0, unreg_count > 0 ? unreg_time / unreg_count : 0 ); #endif #endif }
static time_t FindLock(char *last) { time_t mtime; if ((mtime = FindLockTime(last)) == -1) { /* Do this to prevent deadlock loops from surviving if IfElapsed > T_sched */ if (WriteLock(last) == -1) { CfOut(OUTPUT_LEVEL_ERROR, "", "Unable to lock %s\n", last); return 0; } return 0; } else { return mtime; } }
void CInMemoryBuffer::archive(hislog_key_t now, int color) { __uint size; hislog_stream_list::iterator it; CHislogStream * str; if(now < m_endTime){ return; } //utils_debug("wlock 6\n"); WriteLock(); m_endTime = now; if(m_state != bs_logging){ //utils_debug("release 11\n"); Release(); return; } if(!lock_rtdb(__false, 100)){ //utils_debug("release 12\n"); Release(); return; } for(size = m_streams.size(), it = m_streams.begin(); size; it++, size--){ str = it->second; // if(str->m_color == color) { it->second->putSnapshot(now, NULL, false); } } unlock_rtdb(); //utils_debug("release 13\n"); Release(); }
void CInMemoryBuffer::stopRecord(hislog_key_t now) { __uint size; hislog_stream_list::iterator it; #if 1 { DEBUG_PRINTF(( "Recording stopped on %s\n", timeAsString(now).c_str() )); } #endif //utils_debug("wlock 2\n"); WriteLock(); if(m_state != bs_logging){ //utils_debug("release 3\n"); Release(); throw(m_state); } if(!lock_rtdb(__false, 100)){ //utils_debug("release 4\n"); Release(); return; } for(size = m_streams.size(), it = m_streams.begin(); size; it++, size--){ it->second->putSnapshot(now, NULL, __true); } m_state = bs_ready; unlock_rtdb(); //utils_debug("release 5\n"); Release(); }
AL_API void AL_APIENTRY alMidiResetSOFT(void) { ALCdevice *device; ALCcontext *context; MidiSynth *synth; context = GetContextRef(); if(!context) return; device = context->Device; synth = device->Synth; WriteLock(&synth->Lock); MidiSynth_setState(synth, AL_INITIAL); ALCdevice_Lock(device); V0(synth,reset)(); ALCdevice_Unlock(device); WriteUnlock(&synth->Lock); ALCcontext_DecRef(context); }
AL_API void AL_APIENTRY alMidiStopSOFT(void) { ALCdevice *device; ALCcontext *context; MidiSynth *synth; context = GetContextRef(); if(!context) return; device = context->Device; synth = device->Synth; WriteLock(&synth->Lock); V(synth,setState)(AL_STOPPED); ALCdevice_Lock(device); V0(synth,stop)(); ALCdevice_Unlock(device); WriteUnlock(&synth->Lock); ALCcontext_DecRef(context); }
void stats::write_started(unsigned_type size_, double now) { if (now == 0.0) now = timestamp(); { scoped_mutex_lock WriteLock(write_mutex); ++writes; volume_written += size_; double diff = now - p_begin_write; t_writes += double(acc_writes) * diff; p_begin_write = now; p_writes += (acc_writes++) ? diff : 0.0; } { scoped_mutex_lock IOLock(io_mutex); double diff = now - p_begin_io; p_ios += (acc_ios++) ? diff : 0.0; p_begin_io = now; } }