Exemplo n.º 1
0
        public bool CheckCallbacks(KThread thread)
        {
            Debug.Assert(thread != null);

            if (thread.NotifiedCallbacks.Count == 0)
            {
                return(false);
            }

            Debug.Assert(_runningUserCall == false);
            Debug.Assert(_runningCallback == null);

            if (this.ActiveThread != thread)
            {
                Debug.Assert((thread.State == KThreadState.Waiting) || (thread.State == KThreadState.WaitSuspended));
                _oldThread        = this.ActiveThread;
                this.ActiveThread = thread;
            }

            _oldThreadState = thread.State;
            thread.State    = KThreadState.Ready;

            KCallback callback = thread.NotifiedCallbacks.Dequeue();

            Log.WriteLine(Verbosity.Verbose, Feature.Bios, "Kernel::CheckCallbacks: issuing callback {0} on thread {1} (thread was {2})", callback.UID.ToString("X"), this.ActiveThread.UID.ToString("X"), _oldThread.UID.ToString("X"));

            _runningCallback = callback;

            // Format is arg1, arg2, commonAddress
            // arg1 = passed during notify
            // arg2 is passed during notify and given to use in argument
            Cpu.MarshalCall(this.ActiveThread.ContextID, callback.Address, new uint[] { callback.NotifyCount, callback.NotifyArguments, callback.CommonAddress }, new MarshalCompleteDelegate(this.CallbackComplete), 0);

            return(true);
        }
Exemplo n.º 2
0
        public bool CheckCallbacks( KThread thread )
        {
            Debug.Assert( thread != null );

            if( thread.NotifiedCallbacks.Count == 0 )
                return false;

            Debug.Assert( _runningUserCall == false );
            Debug.Assert( _runningCallback == null );

            if( this.ActiveThread != thread )
            {
                Debug.Assert( ( thread.State == KThreadState.Waiting ) || ( thread.State == KThreadState.WaitSuspended ) );
                _oldThread = this.ActiveThread;
                this.ActiveThread = thread;
            }

            _oldThreadState = thread.State;
            thread.State = KThreadState.Ready;

            KCallback callback = thread.NotifiedCallbacks.Dequeue();

            Log.WriteLine( Verbosity.Verbose, Feature.Bios, "Kernel::CheckCallbacks: issuing callback {0} on thread {1} (thread was {2})", callback.UID.ToString( "X" ), this.ActiveThread.UID.ToString( "X" ), _oldThread.UID.ToString( "X" ) );

            _runningCallback = callback;

            // Format is arg1, arg2, commonAddress
            // arg1 = passed during notify
            // arg2 is passed during notify and given to use in argument
            Cpu.MarshalCall( this.ActiveThread.ContextID, callback.Address, new uint[] { callback.NotifyCount, callback.NotifyArguments, callback.CommonAddress }, new MarshalCompleteDelegate( this.CallbackComplete ), 0 );

            return true;
        }
Exemplo n.º 3
0
        public void DeleteCallback(KCallback callback)
        {
            // Unset?? walk callback listings and remove?
            foreach (FastLinkedList <KCallback> list in this.Callbacks)
            {
                list.Remove(callback);
            }

            // Trickier - remove from pending notification threads
            foreach (KThread thread in this.Threads)
            {
                thread.NotifiedCallbacks.Remove(callback);
            }

            this.RemoveHandle(callback.UID);
        }
Exemplo n.º 4
0
        public bool NotifyCallback(KCallback callback, uint argument)
        {
            Debug.Assert(callback != null);
            callback.NotifyCount++;
            callback.NotifyArguments = argument;

            KThread thread = callback.Thread;

            if (thread.NotifiedCallbacks.Find(callback) == null)
            {
                thread.NotifiedCallbacks.Enqueue(callback);
            }
            //if( ( thread.State == KThreadState.Waiting ) &&
            //    ( thread.CanHandleCallbacks == true ) )
            //{
            //    this.CheckCallbacks( thread );
            //}

            return(true);
        }
Exemplo n.º 5
0
        private bool CallbackComplete(int tcsId, int state, int result)
        {
            Debug.Assert(_oldThread != null);
            Debug.Assert(_runningCallback != null);

            // Something ? return value something?
            if (result == 1)
            {
                // Delete callback
                Log.WriteLine(Verbosity.Normal, Feature.Bios, "Kernel::CallbackComplete: callback {0} deleted by request", _runningCallback.UID.ToString("X"));
                this.DeleteCallback(_runningCallback);
            }

            Log.WriteLine(Verbosity.Verbose, Feature.Bios, "Kernel::CallbackComplete: finished callback {0} on thread {1}; result was {2}", _runningCallback.UID.ToString("X"), this.ActiveThread.UID.ToString("X"), result.ToString("X"));

            _runningCallback = null;

            this.ActiveThread.State = _oldThreadState;
            Debug.Assert(this.ActiveThread.State == _oldThreadState);

            // See if there are more
            if (this.CheckCallbacks(this.ActiveThread) == true)
            {
                return(true);
            }

            if (_oldThread != null)
            {
                this.ActiveThread = _oldThread;
                _oldThread        = null;
            }

            this.Schedule();

            return(true);
        }
Exemplo n.º 6
0
        public void DeleteCallback( KCallback callback )
        {
            // Unset?? walk callback listings and remove?
            foreach( FastLinkedList<KCallback> list in this.Callbacks )
                list.Remove( callback );

            // Trickier - remove from pending notification threads
            foreach( KThread thread in this.Threads )
                thread.NotifiedCallbacks.Remove( callback );

            this.RemoveHandle( callback.UID );
        }
Exemplo n.º 7
0
        private bool CallbackComplete( int tcsId, int state, int result )
        {
            Debug.Assert( _oldThread != null );
            Debug.Assert( _runningCallback != null );

            // Something ? return value something?
            if( result == 1 )
            {
                // Delete callback
                Log.WriteLine( Verbosity.Normal, Feature.Bios, "Kernel::CallbackComplete: callback {0} deleted by request", _runningCallback.UID.ToString( "X" ) );
                this.DeleteCallback( _runningCallback );
            }

            Log.WriteLine( Verbosity.Verbose, Feature.Bios, "Kernel::CallbackComplete: finished callback {0} on thread {1}; result was {2}", _runningCallback.UID.ToString( "X" ), this.ActiveThread.UID.ToString( "X" ), result.ToString( "X" ) );

            _runningCallback = null;

            this.ActiveThread.State = _oldThreadState;
            Debug.Assert( this.ActiveThread.State == _oldThreadState );

            // See if there are more
            if( this.CheckCallbacks( this.ActiveThread ) == true )
                return true;

            if( _oldThread != null )
            {
                this.ActiveThread = _oldThread;
                _oldThread = null;
            }

            this.Schedule();

            return true;
        }
Exemplo n.º 8
0
        public bool NotifyCallback( KCallback callback, uint argument )
        {
            Debug.Assert( callback != null );
            callback.NotifyCount++;
            callback.NotifyArguments = argument;

            KThread thread = callback.Thread;
            if( thread.NotifiedCallbacks.Find( callback ) == null )
                thread.NotifiedCallbacks.Enqueue( callback );
            //if( ( thread.State == KThreadState.Waiting ) &&
            //    ( thread.CanHandleCallbacks == true ) )
            //{
            //    this.CheckCallbacks( thread );
            //}

            return true;
        }