private static void OnTimerInterrupt(FOS_System.Object state) { #if SCHEDULER_HANDLER_TRACE || SCHEDULER_HANDLER_MIN_TRACE BasicConsole.Write("T"); #endif //LockupCounter++; //if (LockupCounter > 2000) //{ // Enable(); //} if (!Enabled || !Initialised) { return; } //LockupCounter = 0; #if SCHEDULER_HANDLER_TRACE || SCHEDULER_HANDLER_MIN_TRACE BasicConsole.Write("E"); #endif //UpdateCountdown -= MSFreq; //if (UpdateCountdown <= 0) //{ // UpdateCountdown = UpdatePeriod; UpdateCurrentState(); //} }
public static void AddDeviceAddedListener(DeviceAddedHandler aHandler, FOS_System.Object aState) { DeviceAddedListeners.Add(new DeviceAddedListener() { handler = aHandler, state = aState }); }
/// <summary> /// Initialises a recurring new PIT handler. /// </summary> /// <param name="HandleOnTrigger">The method to call when the timeout expires.</param> /// <param name="aState">The state object to pass to the handler.</param> /// <param name="NanosecondsTimeout">The timeout, in nanoseconds.</param> /// <param name="NanosecondsLeft">The intial timeout value, in nanoseconds.</param> public PITHandler(Devices.TimerHandler HandleOnTrigger, FOS_System.Object aState, long NanosecondsTimeout, uint NanosecondsLeft) { this.HandleTrigger = HandleOnTrigger; this.NanosecondsTimeout = NanosecondsTimeout; this.NSRemaining = NanosecondsLeft; this.Recurring = true; this.state = aState; }
public void Remove(FOS_System.Object obj) { //Determines whether we should be setting the array entries // to null or not. After we have removed an item and shifted // existing items up in the array, all remaining unused entries // must be set to null. bool setObjectToNull = false; //Store the current index. There is no point looping through the whole capacity // of the array, but we must at least loop through everything that has been set // including the last entry even after higher entries have been shifted or removed. //Note: It would be invalid to use nextIndex+1 because that assumes an entry will // be removed but if the object to remove is not in the list, it will not be // found and so nextIndex+1 would over-run the capacity of the list. int origNextIndex = nextIndex; //Loop through all items in the array that have had a value set. for (int i = 0; i < origNextIndex; i++) { //There are two scenarios here: // 1) We are searching from the start of the list until we find // the item to be removed. Until we find the item, we don't need // to make any changes to the internal array. // 2) Or, we have found the item to be removed and are in the process // of shifting entries up 1 in the array to remove the item. if (_array[i] == obj || setObjectToNull) { //If we are not setting objects to null, then "_array[i] == obj" must // have been true i.e. the current search index is the index of the // object to be removed. //Note: This if block is just a more efficient way of writing: // if (_array[i] == obj) if (!setObjectToNull) { //Removing the object reduces the total count of objects by 1 nextIndex--; } //We should now start shifting objects and setting entries to null setObjectToNull = true; //If we are still within the (new) count of objects then simply shift the // next object up one in the list if (i < nextIndex) { //Set current index to next value in the list. _array[i] = _array[i + 1]; } else { //Otherwise, just set the entry to null. // This ensures values aren't randomly left with entries // in the top of the list. _array[i] = null; } } } }
/// <summary> /// Pops an item off the stack. If the stack is empty, it returns null. /// </summary> /// <returns>The popped item or null if the stack is empty.</returns> public FOS_System.Object Pop() { int lastIndex = internalList.Count - 1; if (lastIndex < 0) { return(null); } FOS_System.Object result = internalList[lastIndex]; internalList.RemoveAt(lastIndex); return(result); }
public void Add(FOS_System.Object obj) { //If the next index to insert an item at is beyond the capacity of // the array, we need to expand the array. if (nextIndex >= _array.Length) { ExpandCapacity(ExpandAmount); } //Insert the object at the next index in the internal array then increment // next index _array[nextIndex] = obj; nextIndex++; }
public static void IncrementRefCount(FOS_System.Object anObj) { if (!Enabled /*|| InsideGC*/ || anObj == null) { return; } InsideGC = true; byte* objPtr = (byte*)Utilities.ObjectUtilities.GetHandle(anObj); _IncrementRefCount(objPtr); InsideGC = false; }
private static void OnTimerInterrupt(FOS_System.Object state) { if (!Enabled) { return; } UpdateCountdown -= MSFreq; if (UpdateCountdown <= 0) { UpdateCountdown = UpdatePeriod; UpdateCurrentState(); } }
public FOS_System.Object Pop() { if (Count > 0) { FOS_System.Object result = InternalArray[BackIdx]; InternalArray[BackIdx++] = null; if (BackIdx >= InternalArray.Length) { BackIdx = 0; } return(result); } return(null); }
private void ExpandCapacity(int amount) { //We need to expand the size of the internal array. Unfortunately, dynamic // expansion of an array to non-contiguous memory is not supported by my OS // or compiler because it's just too darn complicated. So, we must allocate // a new array and copy everything across. //Allocate the new, larger array FOS_System.Object[] newArray = new FOS_System.Object[_array.Length + amount]; //Copy all the values across for (int i = 0; i < _array.Length; i++) { newArray[i] = _array[i]; } //And set the internal array to the new, large array _array = newArray; }
public int IndexOf(FOS_System.Object obj) { //This is a straight forward search. Other search algorithms // may be faster but quite frankly who cares. Optimising the compiler // ASM output would have a far greater effect than changing this // nice, simple algorithm. for (int i = 0; i < nextIndex; i++) { if (_array[i] == obj) { return(i); } } //As per C# (perhaps C?) standard (convention?) return(-1); }
private static void SysCall_StopNoteHandler(FOS_System.Object objState) { NoteState state = (NoteState)objState; if (state.dur_ms >= 0) { state.dur_ms -= 2000; } else { //BasicConsole.WriteLine("Note muted."); Playing = false; Hardware.Timers.PIT.ThePIT.MuteSound(); Hardware.Timers.PIT.ThePIT.UnregisterHandler(state.handlerId); } }
public bool Push(FOS_System.Object obj) { AccessLock.Enter(); try { if (WriteIdx == ReadIdx && ReadIdx != -1) { if (ThrowExceptions) { ExceptionMethods.Throw(new Exceptions.OverflowException("Circular buffer cannot Push because the buffer is full.")); } return(false); } WriteIdx++; if (WriteIdx == _array.Length) { if (ReadIdx == -1) { WriteIdx--; if (ThrowExceptions) { ExceptionMethods.Throw(new Exceptions.OverflowException("Circular buffer cannot Push because the buffer is full.")); } return(false); } WriteIdx = 0; } _array[WriteIdx] = obj; return(true); } finally { AccessLock.Exit(); } }
public static void DecrementRefCount(FOS_System.Object anObj, bool overrideInside) { if (!Enabled /*|| (InsideGC && !overrideInside)*/ || anObj == null) { return; } if (!overrideInside) { InsideGC = true; } byte* objPtr = (byte*)Utilities.ObjectUtilities.GetHandle(anObj); _DecrementRefCount(objPtr); if (!overrideInside) { InsideGC = false; } }
public void Expand(int amount) { if (amount > 0) { FOS_System.Object[] newInternalArray = new FOS_System.Object[InternalArray.Length + amount]; int readIdx = BackIdx; int writeIdx = 0; while (readIdx != FrontIdx) { newInternalArray[writeIdx++] = InternalArray[readIdx++]; if (readIdx >= InternalArray.Length) { readIdx = 0; } } InternalArray = newInternalArray; BackIdx = 0; FrontIdx = writeIdx; } }
public void Push(FOS_System.Object val) { if ((BackIdx != 0 && FrontIdx == BackIdx - 1) || (BackIdx == 0 && FrontIdx == InternalArray.Length - 1)) { // Queue full if (CanExpand) { Expand(InternalArray.Length); } else { return; } } InternalArray[FrontIdx++] = val; if (FrontIdx >= InternalArray.Length) { FrontIdx = 0; } }
/// <summary> /// Removes the specified object from the stack. /// </summary> /// <param name="obj">The object to remove.</param> public void Remove(FOS_System.Object obj) { internalList.Remove(obj); }
/// <summary> /// Pushes the specified object onto the stack. /// </summary> /// <param name="obj">The object to push.</param> public void Push(FOS_System.Object obj) { internalList.Add(obj); }
private static void IRQHandler(FOS_System.Object state) { ((PATAPI)state).IRQHandler(); }
protected static void InterruptHandler(FOS_System.Object data) { ((UHCI)data).InterruptHandler(); }
public static void DecrementRefCount(FOS_System.Object anObj) { DecrementRefCount(anObj, false); }
public abstract int RegisterHandler(TimerHandler handler, long TimeoutNS, bool Recurring, FOS_System.Object state);
private static void DeviceManager_DeviceAdded(FOS_System.Object state, Hardware.Device aDevice) { MainConsole.WriteLine("Device added: " + aDevice._Type.Signature); }
public override int RegisterHandler(Devices.TimerHandler handler, long TimeoutNS, bool Recurring, FOS_System.Object state) { return(RegisterHandler(new PITHandler(handler, state, TimeoutNS, Recurring))); }
public static void _DecrementRefCount(byte *objPtr) { if ((uint)objPtr < (uint)sizeof(GCHeader)) { BasicConsole.SetTextColour(BasicConsole.error_colour); BasicConsole.WriteLine("Error! GC can't decrement ref count of an object in low memory."); BasicConsole.DelayOutput(5); BasicConsole.SetTextColour(BasicConsole.default_colour); } GCHeader *gcHeaderPtr = (GCHeader *)(objPtr - sizeof(GCHeader)); if (CheckSignature(gcHeaderPtr)) { gcHeaderPtr->RefCount--; //If the ref count goes below 0 then there was a circular reference somewhere. // In actuality we don't care we can just only do cleanup when the ref count is // exactly 0. if (gcHeaderPtr->RefCount == 0) { #if GC_TRACE if (OutputTrace) { BasicConsole.WriteLine("Cleaned up object."); } #endif FOS_System.Object obj = (FOS_System.Object)Utilities.ObjectUtilities.GetObject(objPtr); if (obj is FOS_System.Array) { //Decrement ref count of elements FOS_System.Array arr = (FOS_System.Array)obj; if (!arr.elemType.IsValueType) { FOS_System.Object[] objArr = (FOS_System.Object[])Utilities.ObjectUtilities.GetObject(objPtr); for (int i = 0; i < arr.length; i++) { DecrementRefCount(objArr[i], true); } } } //Cleanup fields FieldInfo *FieldInfoPtr = obj._Type.FieldTablePtr; //Loop through all fields. The if-block at the end handles moving to parent // fields. while (FieldInfoPtr != null) { if (FieldInfoPtr->Size > 0) { FOS_System.Type fieldType = (FOS_System.Type)Utilities.ObjectUtilities.GetObject(FieldInfoPtr->FieldType); if (!fieldType.IsValueType && !fieldType.IsPointer) { byte * fieldPtr = objPtr + FieldInfoPtr->Offset; FOS_System.Object theFieldObj = (FOS_System.Object)Utilities.ObjectUtilities.GetObject(fieldPtr); DecrementRefCount(theFieldObj, true); #if GC_TRACE if (OutputTrace) { BasicConsole.WriteLine("Cleaned up field."); } #endif } FieldInfoPtr++; } if (FieldInfoPtr->Size == 0) { FieldInfoPtr = (FieldInfo *)FieldInfoPtr->FieldType; } } AddObjectToCleanup(gcHeaderPtr, objPtr); } } }
/// <summary> /// Tests creating arrays where elements are reference-type and Gc managed. /// </summary> private void ObjectArrayTest() { console.WriteLine("Object array test..."); try { FOS_System.Object[] objArr = new FOS_System.Object[10]; objArr[0] = new FOS_System.Object(); objArr[0]._Type.Size = 5; if (objArr[0] != null) { console.WriteLine("Set object in array success!"); } } catch { console.WarningColour(); console.WriteLine(ExceptionMethods.CurrentException.Message); console.DefaultColour(); } console.WriteLine("End object array test."); }
public static void Cleanup() { if (!Enabled /*|| InsideGC*/) { return; } EnterCritical("Cleanup"); try { InsideGC = true; #if GC_TRACE int startNumObjs = NumObjs; int startNumStrings = NumStrings; #endif if (OutputTrace) { BasicConsole.WriteLine(" > Inside GC & Cleaning..."); } ObjectToCleanup *currObjToCleanupPtr = CleanupList; ObjectToCleanup *prevObjToCleanupPtr = null; if (OutputTrace) { BasicConsole.WriteLine(" > Got list..."); } while (currObjToCleanupPtr != null) { if (OutputTrace) { BasicConsole.WriteLine(" > Item not null."); FOS_System.String str1 = " > Item: 0x "; FOS_System.String str2 = " > Prev: 0x "; ExceptionMethods.FillString((uint)currObjToCleanupPtr, 18, str1); ExceptionMethods.FillString((uint)currObjToCleanupPtr->prevPtr, 18, str2); BasicConsole.WriteLine(str1); BasicConsole.WriteLine(str2); } GCHeader *objHeaderPtr = currObjToCleanupPtr->objHeaderPtr; void * objPtr = currObjToCleanupPtr->objPtr; if (OutputTrace) { BasicConsole.WriteLine(" > Got object handles."); } if (objHeaderPtr->RefCount <= 0) { if (OutputTrace) { BasicConsole.WriteLine(" > Ref count zero or lower."); } FOS_System.Object obj = (FOS_System.Object)Utilities.ObjectUtilities.GetObject(objPtr); if (OutputTrace) { BasicConsole.WriteLine(" > Got object."); } if (obj is FOS_System.String) { if (OutputTrace) { BasicConsole.WriteLine(" > (It's a string)."); } NumStrings--; } else { if (OutputTrace) { BasicConsole.WriteLine(" > (It's NOT a string)."); } NumObjs--; } if (OutputTrace) { BasicConsole.WriteLine(" > About to free object..."); } Heap.Free(objHeaderPtr); if (OutputTrace) { BasicConsole.WriteLine(" > Object freed."); } if (OutputTrace) { BasicConsole.WriteLine(" > Done."); } } if (OutputTrace) { BasicConsole.WriteLine(" > Shifting to next item..."); } prevObjToCleanupPtr = currObjToCleanupPtr; currObjToCleanupPtr = currObjToCleanupPtr->prevPtr; if (OutputTrace) { BasicConsole.WriteLine(" > Removing object to cleanup..."); } RemoveObjectToCleanup(prevObjToCleanupPtr); if (OutputTrace) { BasicConsole.WriteLine(" > Done."); BasicConsole.WriteLine(" > Loop back..."); } } InsideGC = false; #if GC_TRACE if (OutputTrace) { PrintCleanupData(startNumObjs, startNumStrings); } #endif } finally { ExitCritical(); } }
/// <summary> /// Secondary method used in testing the exception handling sub-system. /// </summary> private void ExceptionsTestP2() { FOS_System.Object obj = new FOS_System.Object(); try { ExceptionMethods.Throw(new FOS_System.Exception("An inner exception.")); } finally { console.WriteLine("Finally ran."); ExceptionMethods.Throw(new FOS_System.Exception("An outer exception.")); } }
/// <summary> /// The internal wait interrupt handler static wrapper. /// </summary> /// <param name="state">The PIT object state.</param> private static void SignalWait(FOS_System.Object state) { ((PIT)state).SignalWait(); }