ReadLock Serializable::read_lock () const { if (!_lock) return ReadLock (); return ReadLock (_lock); }
void stats::reset() { { scoped_mutex_lock ReadLock(read_mutex); //assert(acc_reads == 0); if (acc_reads) STXXL_ERRMSG("Warning: " << acc_reads << " read(s) not yet finished"); reads = 0; volume_read = 0; c_reads = 0; c_volume_read = 0; t_reads = 0; p_reads = 0.0; } { scoped_mutex_lock WriteLock(write_mutex); //assert(acc_writes == 0); if (acc_writes) STXXL_ERRMSG("Warning: " << acc_writes << " write(s) not yet finished"); writes = 0; volume_written = 0; c_writes = 0; c_volume_written = 0; t_writes = 0.0; p_writes = 0.0; } { scoped_mutex_lock IOLock(io_mutex); //assert(acc_ios == 0); if (acc_ios) STXXL_ERRMSG("Warning: " << acc_ios << " io(s) not yet finished"); p_ios = 0.0; } { scoped_mutex_lock WaitLock(wait_mutex); //assert(acc_waits == 0); if (acc_waits) STXXL_ERRMSG("Warning: " << acc_waits << " wait(s) not yet finished"); t_waits = 0.0; p_waits = 0.0; t_wait_read = 0.0; p_wait_read = 0.0; t_wait_write = 0.0; p_wait_write = 0.0; } last_reset = timestamp(); }
void FreeThunkEntry(ALuint index) { ReadLock(&ThunkLock); if(index > 0 && index <= ThunkArraySize) ATOMIC_STORE(&ThunkArray[index-1], AL_FALSE); ReadUnlock(&ThunkLock); }
ALenum NewThunkEntry(ALuint *index) { ALenum *NewList; ALuint i; ReadLock(&ThunkLock); for(i = 0;i < ThunkArraySize;i++) { if(ExchangeInt(&ThunkArray[i], AL_TRUE) == AL_FALSE) { ReadUnlock(&ThunkLock); *index = i+1; return AL_NO_ERROR; } } ReadUnlock(&ThunkLock); WriteLock(&ThunkLock); NewList = realloc(ThunkArray, ThunkArraySize*2 * sizeof(*ThunkArray)); if(!NewList) { WriteUnlock(&ThunkLock); ERR("Realloc failed to increase to %u entries!\n", ThunkArraySize*2); return AL_OUT_OF_MEMORY; } memset(&NewList[ThunkArraySize], 0, ThunkArraySize*sizeof(*ThunkArray)); ThunkArraySize *= 2; ThunkArray = NewList; ThunkArray[i] = AL_TRUE; WriteUnlock(&ThunkLock); *index = i+1; return AL_NO_ERROR; }
void FreeThunkEntry(ALuint index) { ReadLock(&ThunkLock); if(index > 0 && index <= ThunkArraySize) ExchangeInt(&ThunkArray[index-1], AL_FALSE); ReadUnlock(&ThunkLock); }
AL_API ALvoid AL_APIENTRY alGetListenerf(ALenum param, ALfloat *value) { ALCcontext *context; context = GetContextRef(); if(!context) return; ReadLock(&context->PropLock); if(!(value)) SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done); switch(param) { case AL_GAIN: *value = context->Listener->Gain; break; case AL_METERS_PER_UNIT: *value = context->Listener->MetersPerUnit; break; default: SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done); } done: ReadUnlock(&context->PropLock); ALCcontext_DecRef(context); }
AL_API void AL_APIENTRY alGetListener3i(ALenum param, ALint *value1, ALint *value2, ALint *value3) { ALCcontext *context; context = GetContextRef(); if(!context) return; ReadLock(&context->PropLock); if(!(value1 && value2 && value3)) SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done); switch (param) { case AL_POSITION: *value1 = (ALint)context->Listener->Position[0]; *value2 = (ALint)context->Listener->Position[1]; *value3 = (ALint)context->Listener->Position[2]; break; case AL_VELOCITY: *value1 = (ALint)context->Listener->Velocity[0]; *value2 = (ALint)context->Listener->Velocity[1]; *value3 = (ALint)context->Listener->Velocity[2]; break; default: SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done); } done: ReadUnlock(&context->PropLock); ALCcontext_DecRef(context); }
AL_API ALvoid AL_APIENTRY alGetBufferf(ALuint buffer, ALenum param, ALfloat *value) { ALCdevice *device; ALCcontext *context; ALbuffer *albuf; context = GetContextRef(); if(!context) return; device = context->Device; if((albuf=LookupBuffer(device, buffer)) == NULL) SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done); if(!(value)) SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done); switch(param) { case AL_SEC_LENGTH_SOFT: ReadLock(&albuf->lock); if(albuf->SampleLen != 0) *value = albuf->SampleLen / (ALfloat)albuf->Frequency; else *value = 0.0f; ReadUnlock(&albuf->lock); break; default: SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done); } done: ALCcontext_DecRef(context); }
void stats::read_cached(unsigned_type size_) { scoped_mutex_lock ReadLock(read_mutex); ++c_reads; c_volume_read += size_; }
bool ProcessRunLock::ReadTryLock () { ReadLock(m_rwlock); if (m_running == false) return true; ReadUnlock(); return false; }
/*static*/ VMArea* VMAreaHash::Lookup(area_id id) { ReadLock(); VMArea* area = LookupLocked(id); ReadUnlock(); return area; }
void DWindowHWInterface::GetMode(display_mode* mode) { if (mode && ReadLock()) { *mode = fDisplayMode; ReadUnlock(); } }
void RemoteHWInterface::GetMode(display_mode* mode) { if (mode == NULL || !ReadLock()) return; *mode = fDisplayMode; ReadUnlock(); }
AutoReadWriteLock::AutoReadWriteLock(ReadWriteLock &threadLock, AutoReadWriteLock::LockType lockInitial) { m_rwLock = &threadLock; m_lockedByMeType = AutoReadWriteLock::None; if (lockInitial == AutoReadWriteLock::Read) ReadLock(); else if (lockInitial == AutoReadWriteLock::Write) WriteLock(); }
LogAutoLock(pthread_rwlock_t *lock, LogAutoLock::LockType lockInitial) { m_rwLock = lock; m_lockedByMeType = LogAutoLock::None; if (lockInitial == LogAutoLock::Read) ReadLock(); else if (lockInitial == LogAutoLock::Write) WriteLock(); }
void stats::read_canceled(unsigned_type size_) { { scoped_mutex_lock ReadLock(read_mutex); --reads; volume_read -= size_; } read_finished(); }
void SeqMeasureControl::DrawRightOn(BRect rBounds, BView* view) { // READ SONG BLOCK #ifdef AM_TRACE_LOCKS printf("SeqMeasureControl::DrawRightOn() read lock\n"); fflush(stdout); #endif const AmSong* song = ReadLock(); if (song) LockedDrawRightOn(song->Signatures(), rBounds, view, song->CountEndTime() ); ReadUnlock(song); // END READ SONG BLOCK }
/* 函数名称 : CScriptFuncTable::GetFunction 函数功能 : 根据ID去函数, 目前id就是函数名, 用二分法查找 变量说明 : 返回值 : 编写人 : 居卫华 完成日期 : 2001 - 5 - 14 */ CFunction* CScriptFuncTable::GetFunction(char *szID, long* index) { *index = -1; int i, j, k, l; i = 0; j = this->m_FuncNum-1; k = -1; char* szName; //printf("k=%d l=%d j=%d i=%d\n", k, l, j, i); //lock if (ReadLock() != LOCKEX_ERR_OK) { fprintf(stderr, "readlock failed for getting function %s\n", szID); REPORT_ERROR("ReadLock failed", 9); return NULL; } fprintf(stderr, "readlock successfully for getting function %s\n", szID); while (i <= j) { //printf("k=%d l=%d j=%d i=%d\n", k, l, j, i); k = (i+j)/2; szName = table[k]->m_szName; //printf("szID:%s name:%s",szID, szName); l = strcmp(szID, szName); if (l == 0) { *index = k; // should unlock ? CFunction* fpn = table[k]; ReadUnlock(); printf("return %dth function %lx, %lx\n", k, table[k], fpn); fprintf(stderr, "readunlock successfully for getting function %s\n", szID); return fpn; } else { if (l < 0)//table[i] < table[k] j = k -1; if (l > 0)//table[i] > table[k] i = k + 1; } /* printf("k=%d l=%d j=%d i=%d\n", k, l, j, i);*/ } //unlock ReadUnlock(); fprintf(stderr, "readunlock successfully for getting function %s\n", szID); return NULL; }
AL_API void AL_APIENTRY alGetBufferSamplesSOFT(ALuint buffer, ALsizei offset, ALsizei samples, ALenum channels, ALenum type, ALvoid *data) { ALCdevice *device; ALCcontext *context; ALbuffer *albuf; ALsizei align; context = GetContextRef(); if(!context) return; device = context->Device; LockBuffersRead(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); ReadLock(&albuf->lock); align = ATOMIC_LOAD_SEQ(&albuf->PackAlign); if(SanitizeAlignment(type, &align) == AL_FALSE) { ReadUnlock(&albuf->lock); SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done); } if(channels != (ALenum)albuf->FmtChannels) { ReadUnlock(&albuf->lock); SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done); } if(offset > albuf->SampleLen || samples > albuf->SampleLen-offset) { ReadUnlock(&albuf->lock); SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done); } if((samples%align) != 0) { ReadUnlock(&albuf->lock); SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done); } /* offset -> byte offset */ offset *= FrameSizeFromFmt(albuf->FmtChannels, albuf->FmtType); ConvertData(data, type, (char*)albuf->data+offset, (enum UserFmtType)albuf->FmtType, ChannelsFromFmt(albuf->FmtChannels), samples, align); ReadUnlock(&albuf->lock); done: UnlockBuffersRead(device); ALCcontext_DecRef(context); }
/****************************************************************************** 函数名 :CRWScopeGuard 功能 :构造函数,加系统锁 输入 :无 输出 :无 返回值 :无 其他 :无 ******************************************************************************/ CRWScopeGuard::CRWScopeGuard(CRWLock& rwlock,bool is_readlock) { m_prwLock = &rwlock; if(is_readlock) { ReadLock(); } else { WriteLock(); } }
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 CScriptFuncTable::dump(){ if (ReadLock() != LOCKEX_ERR_OK) { REPORT_ERROR("ReadLock failed", 9); return; } printf("========>dump of script table %lx(size=%d)<=====\n", table, m_FuncNum); if (table) for (int i = 0; i< m_FuncNum; i++){ if (table[i]) printf("===>%lx=>%s\n", table[i], table[i]->name()); } printf("========>end dump of script table <=====\n"); ReadUnlock(); }
AL_API void AL_APIENTRY alGetBufferiv(ALuint buffer, ALenum param, ALint *values) { ALCdevice *device; ALCcontext *context; ALbuffer *albuf; switch(param) { case AL_FREQUENCY: case AL_BITS: case AL_CHANNELS: case AL_SIZE: case AL_INTERNAL_FORMAT_SOFT: case AL_BYTE_LENGTH_SOFT: case AL_SAMPLE_LENGTH_SOFT: case AL_UNPACK_BLOCK_ALIGNMENT_SOFT: case AL_PACK_BLOCK_ALIGNMENT_SOFT: alGetBufferi(buffer, param, values); return; } context = GetContextRef(); if(!context) return; device = context->Device; LockBuffersRead(device); if((albuf=LookupBuffer(device, buffer)) == NULL) SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done); if(!(values)) SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done); switch(param) { case AL_LOOP_POINTS_SOFT: ReadLock(&albuf->lock); values[0] = albuf->LoopStart; values[1] = albuf->LoopEnd; ReadUnlock(&albuf->lock); break; default: SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done); } done: UnlockBuffersRead(device); ALCcontext_DecRef(context); }
status_t RemoteHWInterface::GetDeviceInfo(accelerant_device_info* info) { if (!ReadLock()) return B_ERROR; info->version = fProtocolVersion; info->dac_speed = fConnectionSpeed; info->memory = 33554432; // 32MB snprintf(info->name, sizeof(info->name), "Haiku, Inc. RemoteHWInterface"); snprintf(info->chipset, sizeof(info->chipset), "Haiku, Inc. Chipset"); snprintf(info->serial_no, sizeof(info->serial_no), fTarget); ReadUnlock(); return B_OK; }
/* 函数名称 : CScriptFuncTable::GetFunction 函数功能 : 根据ID去函数, 目前id就是函数名, 用二分法查找 变量说明 : 返回值 : 编写人 : 居卫华 完成日期 : 2001 - 5 - 14 */ CFunction* CScriptFuncTable::GetFunction(char *szID, long* index) { *index = -1; int i, j, k, l; i = 0; j = this->m_FuncNum-1; k = -1; char* szName; //printf("k=%d l=%d j=%d i=%d\n", k, l, j, i); //lock if (ReadLock() != LOCKEX_ERR_OK) { REPORT_ERROR("ReadLock failed", 9); return NULL; } while (i <= j) { //printf("k=%d l=%d j=%d i=%d\n", k, l, j, i); k = (i+j)/2; szName = table[k]->m_szName; //printf("szID:%s name:%s",szID, szName); l = strcmp(szID, szName); if (l == 0) { *index = k; return table[k]; } else { if (l < 0)//table[i] < table[k] j = k -1; if (l > 0)//table[i] > table[k] i = k + 1; } /* printf("k=%d l=%d j=%d i=%d\n", k, l, j, i);*/ } //unlock ReadUnlock(); return NULL; }
void SeqMeasureControl::Initialize() { float fh = view_font_height(this); float row2B = Bounds().bottom; float row2T = row2B - fh - 1; float row1B = row2T - 1; float row1T = 0; if ( !(mMarker[POSITION_MARKER].image) ) { mMarker[POSITION_MARKER].image = ImageManager().FindBitmap(SONG_POSITION_MARKER_IMAGE_STR); if (mMarker[POSITION_MARKER].image) mMarker[POSITION_MARKER].offset = 0 - (mMarker[POSITION_MARKER].image->Bounds().Width() / 2); mMarker[POSITION_MARKER].origin.y = row2T; mMarker[POSITION_MARKER].bottom = row2B; } if ( !(mMarker[LEFT_LOOP_MARKER].image) ) { mMarker[LEFT_LOOP_MARKER].image = ImageManager().FindBitmap(LEFT_LOOP_STR); if (mMarker[LEFT_LOOP_MARKER].image) mMarker[LEFT_LOOP_MARKER].offset = 0 - mMarker[LEFT_LOOP_MARKER].image->Bounds().Width(); mMarker[LEFT_LOOP_MARKER].origin.y = row1T; mMarker[LEFT_LOOP_MARKER].bottom = row1B; } if ( !(mMarker[RIGHT_LOOP_MARKER].image) ) { mMarker[RIGHT_LOOP_MARKER].image = ImageManager().FindBitmap(RIGHT_LOOP_STR); mMarker[RIGHT_LOOP_MARKER].origin.y = row1T; mMarker[RIGHT_LOOP_MARKER].bottom = row1B; } mMarker[LEFT_LOOP_MARKER].SetVisible(false); mMarker[LEFT_LOOP_MARKER].dragLock = _AmMarkerEntry::LOCK_TO_BEAT; mMarker[LEFT_LOOP_MARKER].pair = &(mMarker[RIGHT_LOOP_MARKER]); mMarker[LEFT_LOOP_MARKER].pairPosition = _AmMarkerEntry::RIGHT_PAIR; mMarker[RIGHT_LOOP_MARKER].SetVisible(false); mMarker[RIGHT_LOOP_MARKER].dragLock = _AmMarkerEntry::LOCK_TO_BEAT; mMarker[RIGHT_LOOP_MARKER].pair = &(mMarker[LEFT_LOOP_MARKER]); mMarker[RIGHT_LOOP_MARKER].pairPosition = _AmMarkerEntry::LEFT_PAIR; // READ SONG BLOCK #ifdef AM_TRACE_LOCKS printf("SeqMeasureControl::Initialize() read lock\n"); fflush(stdout); #endif const AmSong* song = ReadLock(); if( song ) mCachedEndTime = song->CountEndTime(); ReadUnlock( song ); // END READ SONG BLOCK }
void SeqMeasureControl::DrawLeftOn(BRect lBounds, BView* view) { // If it's fixed than I just let the center view take care of drawing it. if ( IsLeftFixed() ) return; if ( mLeftBg ) view->DrawBitmapAsync( mLeftBg, BPoint(0, 1) ); // READ SONG BLOCK #ifdef AM_TRACE_LOCKS printf("SeqMeasureControl::DrawLeftOn() read lock\n"); fflush(stdout); #endif const AmSong* song = ReadLock(); if( !song ) return; LockedDrawLeftOn(song->Signatures(), lBounds, view); ReadUnlock( song ); // END READ SONG BLOCK }
status_t SeqMeasureControl::SignatureForPt(BPoint pt, AmSignature& sig) const { status_t err = B_ERROR; AmTime time = mMtc.PixelToTick(pt.x + mScrollX - mLeftIndent); /* If the time being requested is less than the first measure, constrain * it to the first measure. */ if (time < 0) time = 0; // READ SONG BLOCK #ifdef AM_TRACE_LOCKS printf("SeqMeasureControl::SignatureForPt() read lock\n"); fflush(stdout); #endif const AmSong* song = ReadLock(); if (song) err = song->GetSignature(time, sig); ReadUnlock( song ); // END READ SONG BLOCK return err; }
status_t DWindowHWInterface::GetDeviceInfo(accelerant_device_info* info) { // We really don't have to provide anything here because this is strictly // a software-only driver, but we'll have some fun, anyway. if (ReadLock()) { info->version = 100; sprintf(info->name, "Antares, Inc. DWindowHWInterface"); sprintf(info->chipset, "Antares, Inc. Chipset"); sprintf(info->serial_no, "3.14159265358979323846"); info->memory = 134217728; // 128 MB, not that we really have that much. :) info->dac_speed = 0xFFFFFFFF; // *heh* ReadUnlock(); } return B_OK; }
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; }