Go to index, previous page, next page

thread.cc, threadp2.cc, threadfreelist.cc, threadqueue.cc

In these modules there is the code for the classes used by AMIKE OS to handle threads. They are pretty simple and the code should be straightforward, thus you can find only some quick notes here.

Thread class

Public members

Thread( void )
~Thread( void )
Object constructor and destructor.
Thread *getNext( void )
void setNext( Thread *t_ptr )
get or set the next message pointer
Thread *getNext2( void )
void setNext2( Thread *t_ptr )
as above, but using the second pointer. This way a thread object can easily be inserted in two lists at the same time.
char getStatus( void )
void setStatus( Thread *t_ptr )

char getWaitFor( void )
void SetWaitFor( char code )

Message *getReply( void )
void setReply( Message *reply )

devreg *getVBA( void )
void setVBA( devreg *vba )

state_t *getState( void )
void setState( state_t *state )

cpu_t getCPUTime( void )

void setStartTime( void )

Thread *getParent( void )
void setParent( Thread *parent )

int getTrap( void )
void setTrap( int trap )

These functions return or set the correspoding thread memeber.
void updateCPUTime( void ) updates the CPU time used by the thread.
short HandleException( int type, int cause ) checks whether the thread has a trap manager for trap type. If so it sends it a message with the cause value and returns TRUE, otherwise it returns FALSE.
short setTrapManager( int type, Thread *mgr ) set the thread's trap manager for trap type. Returns FALSE if another manager has been previously specified for the same kind of trap or if the given thread is dead; it returns TRUE otherwise.
MessageQueue *MsgQ; pointer to the queue of messages awaiting processing by the thread.
ThreadQueue *Children; pointer to the queue of the thread's children.
Thread *ExcVectors[3]; this array contains the trap managers for the thread.
state_t proc_s; current state of the thread.

Private members

Thread *t_next, *t_next2; points to the successive message in a list or queue (a pointer for every possible list it can be in at the same time)
char Status; thread status: running, ready, waiting or killed.
char WaitFor; specifies which kind of event the thread is waiting for
char Trap; specifies which kind of trap has blocked the thread. It's needed to intercept messages from the right trap manager.
Thread *Parent; pointer to the parent thread or NULL.
Message *Reply; this variable will hold the pointer passed to MsgRecv()
devreg *VBA; vector base address of the device the thread is waiting an interrupt from
cpu_t CPUTime; CPU time used by the thread
cpu_t StartTime; value of the TDLO register when accounting started

ThreadFreeList class

Public members

ThreadFreeList( int list_size ) list constructor. It will create a list with list_size threads
~ThreadFreeList( void ) destructor. All the threads in the list will be freed.
Thread *getThread( void )
void putThread( Thread *t_ptr )
remove a node from the list or place it back in.

Private members

Thread *t_first; points to the first item in the list

ThreadQueue class

Public members

ThreadQueue( void )
ThreadQueue( int stat )
constructors. They prepare the queue for use.

The first version creates an unqualified queue, while the second creates a queue whose members will have their status set to stat at insertion time.

~ThreadQueue( void ) destructor. It will free all the threads left in the queue.
void insertThread( Thread *t_ptr, int listn = 0 ) appends the given thread to the queue, using the first or second pointer according to listn.
Thread *removeThread( int listn = 0 ) removes the first thread in the queue, using the first or second pointer according to listn. It returns a pointer to it or NULL if the queue was empty
Thread *outThread( Thread *t_ptr, int listn = 0 ) Removes and return the given thread from the queue, if it's there, using the first or second pointer according to listn. Returns NULL otherwise.
Thread *headThread( void ) Returns a pointer to the first thread in the queue, or NULL if the queue is empty.

Private members

Thread *t_first; pointer to the first thread in the queue
Thread *t_last; pointer to the last thread in the queue
char status; status for the queue nodes.


Look at the header file: threadq.e

Look at the code: thread.cc, threadp2.cc, threadfreelist.cc, threadqueue.cc


Go to index, previous page, next page