int32_t MV_VoiceAvailable(int32_t priority) { // Check if we have any free voices if (!LL_Empty(&VoicePool, next, prev)) return TRUE; DisableInterrupts(); VoiceNode *voice, *node; // check if we have a higher priority than a voice that is playing. for (voice = node = VoiceList.next; node != &VoiceList; node = node->next) { if (node->priority < voice->priority) voice = node; } if ((voice == &VoiceList) || (priority < voice->priority)) { RestoreInterrupts(); return FALSE; } RestoreInterrupts(); return TRUE; }
int32_t MV_KillAllVoices(void) { if (!MV_Installed) return MV_Error; DisableInterrupts(); if (&VoiceList == VoiceList.next) { RestoreInterrupts(); return MV_Ok; } VoiceNode * voice = VoiceList.prev; // Remove all the voices from the list while (voice != &VoiceList) { if (voice->priority == MV_MUSIC_PRIORITY) { voice = voice->prev; continue; } MV_Kill(voice->handle); voice = VoiceList.prev; } RestoreInterrupts(); return MV_Ok; }
int GUSWAVE_Kill ( int handle ) { VoiceNode *voice; unsigned flags; flags = DisableInterrupts(); voice = GUSWAVE_GetVoice( handle ); if ( voice == NULL ) { RestoreInterrupts( flags ); GUSWAVE_SetErrorCode( GUSWAVE_VoiceNotFound ); if ( GUS_Debug ) { DB_printf( "Could not find voice to kill.\n" ); } return( GUSWAVE_Warning ); } RestoreInterrupts( flags ); if ( !GUS_Debug ) { if ( voice->Active ) { gf1_stop_digital( voice->GF1voice ); } } else { DB_printf( "Kill - GUS Voice %d ", voice->GF1voice ); if ( voice->Active ) { DB_printf( "active\n" ); gf1_stop_digital( voice->GF1voice ); } else { DB_printf( "inactive\n" ); } } // RestoreInterrupts( flags ); return( GUSWAVE_Ok ); }
static void TS_SetClockSpeed ( long speed ) { unsigned flags; flags = DisableInterrupts(); if ( ( speed > 0 ) && ( speed < 0x10000L ) ) { TaskServiceRate = speed; } else { TaskServiceRate = 0x10000L; } outp( 0x43, 0x36 ); outp( 0x40, TaskServiceRate ); outp( 0x40, TaskServiceRate >> 8 ); RestoreInterrupts( flags ); }
static void TS_FreeTaskList ( void ) { task *node; task *next; unsigned flags; flags = DisableInterrupts(); node = TaskList->next; while( node != TaskList ) { next = node->next; FreeMem( node ); node = next; } TaskList->next = TaskList; TaskList->prev = TaskList; RestoreInterrupts( flags ); }
static void TS_SetTimerToMaxTaskRate ( void ) { task *ptr; long MaxServiceRate; unsigned flags; flags = DisableInterrupts(); MaxServiceRate = 0x10000L; ptr = TaskList->next; while( ptr != TaskList ) { if ( ptr->rate < MaxServiceRate ) { MaxServiceRate = ptr->rate; } ptr = ptr->next; } if ( TaskServiceRate != MaxServiceRate ) { TS_SetClockSpeed( MaxServiceRate ); } RestoreInterrupts( flags ); }
int ADLIBFX_Stop ( int handle ) { unsigned flags; if ( ( handle != ADLIBFX_VoiceHandle ) || ( ADLIBFX_Sound == NULL ) ) { ADLIBFX_SetErrorCode( ADLIBFX_VoiceNotFound ); return( ADLIBFX_Warning ); } flags = DisableInterrupts(); ADLIBFX_SendOutput( 0xb0, 0 ); ADLIBFX_Sound = NULL; ADLIBFX_SoundPtr = NULL; ADLIBFX_LengthLeft = 0; ADLIBFX_Priority = 0; RestoreInterrupts( flags ); if ( ADLIBFX_CallBackFunc ) { ADLIBFX_CallBackFunc( ADLIBFX_CallBackVal ); } return( ADLIBFX_Ok ); }
int GUSWAVE_SetPitch ( int handle, int pitchoffset ) { VoiceNode *voice; unsigned flags; flags = DisableInterrupts(); voice = GUSWAVE_GetVoice( handle ); if ( voice == NULL ) { RestoreInterrupts( flags ); GUSWAVE_SetErrorCode( GUSWAVE_VoiceNotFound ); return( GUSWAVE_Warning ); } if ( voice->Active ) { voice->PitchScale = PITCH_GetScale( pitchoffset ); voice->RateScale = ( voice->SamplingRate * voice->PitchScale ) >> 16; gf1_dig_set_freq( voice->GF1voice, voice->RateScale ); }
int PCFX_Stop ( int handle ) { unsigned flags; if ( ( handle != PCFX_VoiceHandle ) || ( PCFX_Sound == NULL ) ) { PCFX_SetErrorCode( PCFX_VoiceNotFound ); return( PCFX_Warning ); } flags = DisableInterrupts(); // Turn off speaker outp( 0x61, inp( 0x61 ) & 0xfc ); PCFX_Sound = NULL; PCFX_LengthLeft = 0; PCFX_Priority = 0; PCFX_LastSample = 0; RestoreInterrupts( flags ); if ( PCFX_CallBackFunc ) { PCFX_CallBackFunc( PCFX_CallBackVal ); } return( PCFX_Ok ); }
void AddressSpace::TrimWorkingSet() { int mappedMemory = fPhysicalMap->CountMappedPages() * PAGE_SIZE; bigtime_t now = SystemTime(); // Adjust the working set size based on fault rate. if (now - fLastWorkingSetAdjust > kWorkingSetAdjustInterval) { cpu_flags fl = DisableInterrupts(); int faultsPerSecond = static_cast<int64>(fFaultCount) * 1000000 / (now - fLastWorkingSetAdjust); if (faultsPerSecond > kMaxFaultsPerSecond && mappedMemory >= fWorkingSetSize && fWorkingSetSize < fMaxWorkingSet) { fWorkingSetSize = MIN(fWorkingSetSize + kWorkingSetIncrement, fMaxWorkingSet); } else if (faultsPerSecond < kMinFaultsPerSecond && mappedMemory <= fWorkingSetSize && fWorkingSetSize > fMaxWorkingSet && Page::CountFreePages() < kMinFreePages) { fWorkingSetSize = MAX(fWorkingSetSize - kWorkingSetIncrement, fMaxWorkingSet); } fLastWorkingSetAdjust = now; fFaultCount = 0; RestoreInterrupts(fl); } // Trim some pages if needed while (mappedMemory > fWorkingSetSize) { break; } }
static VoiceNode *GUSWAVE_GetVoice ( int handle ) { VoiceNode *voice; unsigned flags; flags = DisableInterrupts(); voice = VoiceList.start; while( voice != NULL ) { if ( handle == voice->handle ) { break; } voice = voice->next; } RestoreInterrupts( flags ); if ( voice == NULL ) { GUSWAVE_SetErrorCode( GUSWAVE_VoiceNotFound ); } return( voice ); }
int VgaText::Write(off_t, const void *buf, size_t size) { cpu_flags fl = DisableInterrupts(); char *s = (char*) buf; while (size-- > 0) { char c = *s++; switch (c) { case '\n': fOffset += kScreenWidth - (fOffset % kScreenWidth); if (fOffset >= kScreenWidth * kScreenHeight) { fOffset -= kScreenWidth; ScrollUp(); } break; case '\010': // Backspace if (fOffset > 0) fTextBuffer[--fOffset] = fCurrentAttribute | ' '; break; default: fTextBuffer[fOffset++] = fCurrentAttribute | c; if (fOffset > kScreenWidth * kScreenHeight) { fOffset -= kScreenWidth; ScrollUp(); } } } UpdateHardwareCursor(); RestoreInterrupts(fl); return E_NO_ERROR; }
int GUSWAVE_VoicesPlaying ( void ) { int index; int NumVoices = 0; unsigned flags; flags = DisableInterrupts(); for( index = 0; index < GUSWAVE_MaxVoices; index++ ) { if ( GUSWAVE_Voices[ index ].Active ) { NumVoices++; } } RestoreInterrupts( flags ); if ( GUS_Debug ) { DB_printf( "Number of voices = %d.\n", NumVoices ); } return( NumVoices ); }
static void ADLIBFX_SendOutput ( int reg, int data ) { int i; int adlib_port = 0x388; unsigned flags; flags = DisableInterrupts(); outp( adlib_port, reg ); for( i = 6; i ; i-- ) { inp( adlib_port ); } outp( adlib_port + 1, data ); for( i = 35; i ; i-- ) { inp( adlib_port ); } RestoreInterrupts( flags ); }
void PAS_SetSampleRateTimer ( void ) { int LoByte; int HiByte; int data; unsigned flags; flags = DisableInterrupts(); // Disable the Sample Rate Timer data = PAS_State->audiofilt; data &= ~SampleRateTimerGateFlag; PAS_Write( AudioFilterControl, data ); PAS_State->audiofilt = data; // Select the Sample Rate Timer data = SelectSampleRateTimer; PAS_Write( LocalTimerControl, data ); PAS_State->tmrctlr = data; LoByte = lobyte( PAS_TimeInterval ); HiByte = hibyte( PAS_TimeInterval ); // Program the Sample Rate Timer PAS_Write( SampleRateTimer, LoByte ); PAS_Write( SampleRateTimer, HiByte ); PAS_State->samplerate = PAS_TimeInterval; RestoreInterrupts( flags ); }
APC* Thread::DequeueAPC() { cpu_flags fl = DisableInterrupts(); APC *apc = static_cast<APC*>(fApcQueue.Dequeue()); RestoreInterrupts(fl); return apc; }
status_t Dispatcher::WaitForMultipleDispatchers(int dispatcherCount, Dispatcher *dispatchers[], WaitFlags flags, bigtime_t timeout) { status_t result = E_NO_ERROR; cpu_flags fl = DisableInterrupts(); bool satisfied; if (flags & WAIT_FOR_ALL) { satisfied = true; for (int dispatcherIndex = 0; dispatcherIndex < dispatcherCount; dispatcherIndex++) if (!dispatchers[dispatcherIndex]->fSignalled) { satisfied = false; break; } } else { satisfied = false; for (int dispatcherIndex = 0; dispatcherIndex < dispatcherCount; dispatcherIndex++) { if (dispatchers[dispatcherIndex]->fSignalled) { satisfied = true; break; } } } if (satisfied) { for (int dispatcherIndex = 0; dispatcherIndex < dispatcherCount; dispatcherIndex++) dispatchers[dispatcherIndex]->ThreadWoken(); RestoreInterrupts(fl); return E_NO_ERROR; } const int kMaxStackAlloc = 5; if (dispatcherCount <= kMaxStackAlloc) { WaitTag tags[kMaxStackAlloc]; result = WaitInternal(dispatcherCount, dispatchers, flags, timeout, tags); } else { WaitTag *tags = new WaitTag[dispatcherCount]; result = WaitInternal(dispatcherCount, dispatchers, flags, timeout, tags); delete [] tags; } RestoreInterrupts(fl); return result; }
VoiceNode *MV_AllocVoice(int32_t priority) { VoiceNode *voice, *node; DisableInterrupts(); // Check if we have any free voices if (LL_Empty(&VoicePool, next, prev)) { // check if we have a higher priority than a voice that is playing. for (voice = node = VoiceList.next; node != &VoiceList; node = node->next) { if (node->priority < voice->priority) voice = node; } if (priority >= voice->priority && voice != &VoiceList && voice->handle >= MV_MINVOICEHANDLE) MV_Kill(voice->handle); if (LL_Empty(&VoicePool, next, prev)) { // No free voices RestoreInterrupts(); return NULL; } } voice = VoicePool.next; LL_Remove(voice, next, prev); RestoreInterrupts(); int32_t vhan = MV_MINVOICEHANDLE; // Find a free voice handle do { if (++vhan < MV_MINVOICEHANDLE || vhan > MV_MaxVoices) vhan = MV_MINVOICEHANDLE; } while (MV_VoicePlaying(vhan)); voice->handle = vhan; return voice; }
int GUSWAVE_KillAllVoices ( void ) { int i; unsigned flags; if ( !GUSWAVE_Installed ) { return( GUSWAVE_Ok ); } if ( GUS_Debug ) { DB_printf( "Kill All Voices\n" ); } flags = DisableInterrupts(); // Remove all the voices from the list for( i = 0; i < GUSWAVE_MaxVoices; i++ ) { if ( GUSWAVE_Voices[ i ].Active ) { // GUSWAVE_Kill( GUSWAVE_Voices[ i ].handle ); gf1_stop_digital( GUSWAVE_Voices[ i ].GF1voice ); } } for( i = 0; i < MAX_VOICES; i++ ) { VoiceStatus[ i ].playing = FALSE; VoiceStatus[ i ].Voice = NULL; } VoicePool.start = NULL; VoicePool.end = NULL; VoiceList.start = NULL; VoiceList.end = NULL; for( i = 0; i < GUSWAVE_MaxVoices; i++ ) { GUSWAVE_Voices[ i ].Active = FALSE; if ( GUSWAVE_Voices[ i ].mem != NULL ) { LL_AddToTail( VoiceNode, &VoicePool, &GUSWAVE_Voices[ i ] ); } } RestoreInterrupts( flags ); return( GUSWAVE_Ok ); }
void VgaText::Clear() { cpu_flags fl = DisableInterrupts(); for (int i = 0; i < kScreenWidth * kScreenHeight; i++) fTextBuffer[i] = fCurrentAttribute | ' '; fOffset = 0; UpdateHardwareCursor(); RestoreInterrupts(fl); }
void Semaphore::Release(int releaseCount, bool reschedule) { cpu_flags cs = DisableInterrupts(); int oldCount = fCount; fCount += releaseCount; if (oldCount == 0) Signal(reschedule); RestoreInterrupts(cs); }
void Thread::EnqueueAPC(APC *apc) { cpu_flags fl = DisableInterrupts(); fApcQueue.Enqueue(apc); #if 0 if (GetState() == kThreadWaiting) Wake(E_INTERRUPTED); #endif RestoreInterrupts(fl); }
void Thread::Exit() { ASSERT(GetRunningThread() == this); cpu_flags fl = DisableInterrupts(); SetState(kThreadDead); fReapQueue.Enqueue(this); fThreadsToReap.Release(1, false); RestoreInterrupts(fl); gScheduler.Reschedule(); panic("terminated thread got scheduled"); }
// The Grim Reaper thread reclaims resources for threads and teams that // have exited. int Thread::GrimReaper(void*) { for (;;) { fThreadsToReap.Wait(); cpu_flags fl = DisableInterrupts(); Thread *victim = static_cast<Thread*>(fReapQueue.Dequeue()); RestoreInterrupts(fl); // The thread may not actually get deleted here if someone else has // a handle to it. victim->ReleaseRef(); } }
int TS_Terminate ( task *NodeToRemove ) { task *ptr; task *next; unsigned flags; flags = DisableInterrupts(); ptr = TaskList->next; while( ptr != TaskList ) { next = ptr->next; if ( ptr == NodeToRemove ) { LL_RemoveNode( NodeToRemove, next, prev ); NodeToRemove->next = NULL; NodeToRemove->prev = NULL; FreeMem( NodeToRemove ); TS_SetTimerToMaxTaskRate(); RestoreInterrupts( flags ); return( TASK_Ok ); } ptr = next; } RestoreInterrupts( flags ); return( TASK_Warning ); }
void Thread::SwitchTo() { cpu_flags cs = DisableInterrupts(); fState = kThreadRunning; if (fRunningThread != this) { bigtime_t now = SystemTime(); fRunningThread->fLastEvent = now; fLastEvent = now; fRunningThread = this; fThreadContext.SwitchTo(); } RestoreInterrupts(cs); }
int ADLIBFX_SetVolume ( int handle, int volume ) { unsigned flags; int carrierlevel; flags = DisableInterrupts(); if ( ( handle != ADLIBFX_VoiceHandle ) || ( ADLIBFX_Sound == NULL ) ) { RestoreInterrupts( flags ); ADLIBFX_SetErrorCode( ADLIBFX_VoiceNotFound ); return( ADLIBFX_Warning ); } volume = min( volume, ADLIBFX_MaxVolume ); volume = max( volume, 0 ); ADLIBFX_SoundVolume = volume; volume *= ADLIBFX_TotalVolume; volume /= ADLIBFX_MaxVolume; carrierlevel = ADLIBFX_Sound->cScale & 0x3f; carrierlevel ^= 0x3f; carrierlevel *= ( volume / 2 ) + 0x80; carrierlevel /= ADLIBFX_MaxVolume; carrierlevel ^= 0x3f; carrierlevel |= ADLIBFX_Sound->cScale & 0xc0; ADLIBFX_SendOutput( 0x43, carrierlevel ); RestoreInterrupts( flags ); return( ADLIBFX_Ok ); }
status_t Dispatcher::Wait(bigtime_t timeout) { cpu_flags fl = DisableInterrupts(); status_t result = E_NO_ERROR; if (fSignalled) ThreadWoken(); else { WaitTag tag; Dispatcher *list = this; result = WaitInternal(1, &list, WAIT_FOR_ONE, timeout, &tag); } RestoreInterrupts(fl); return result; }
static VoiceNode *MV_GetVoice(int32_t handle) { if (handle < MV_MINVOICEHANDLE || handle > MV_MaxVoices) { if (MV_Printf) MV_Printf("MV_GetVoice(): bad handle (%d)!\n", handle); return NULL; } DisableInterrupts(); for (VoiceNode *voice = VoiceList.next; voice != &VoiceList; voice = voice->next) { if (handle == voice->handle) { RestoreInterrupts(); return voice; } } RestoreInterrupts(); MV_SetErrorCode(MV_VoiceNotFound); return NULL; }
void UStart (struct MST *ms) { uint32 count; uint32 int_state; int_state = DisableInterrupts(); OutByte (TMR_TCW, TMRC_MODE0); count = InByte (TMR_TMRCNT0); count |= (InByte (TMR_TMRCNT0) << 8); RestoreInterrupts (int_state); ms->prev_count = count; ms->accum_count = 0; }