Embedded Xinu Operating System
An ongoing research project and educational operating system.
 All Data Structures Files Functions Variables Typedefs Enumerations Macros Groups Pages
Functions

Thread functions. More...

Functions

syscall chprio (tid_typ tid, int newprio)
 
tid_typ create (void *procaddr, uint ssize, int priority, const char *name, int nargs,...)
 
tid_typ getfirst (qid_typ q)
 
tid_typ getlast (qid_typ q)
 
tid_typ getitem (tid_typ tid)
 
syscall getprio (tid_typ tid)
 
tid_typ gettid (void)
 
int insert (tid_typ tid, qid_typ q, int key)
 
int insertd (tid_typ tid, qid_typ q, int key)
 
syscall kill (tid_typ tid)
 
qid_typ queinit (void)
 
tid_typ enqueue (tid_typ tid, qid_typ q)
 
tid_typ dequeue (qid_typ q)
 
int ready (tid_typ tid, bool resch, uint core)
 
message receive (void)
 
message recvclr (void)
 
message recvtime (int maxwait)
 
int resched (void)
 
syscall resume (tid_typ tid)
 
syscall send (tid_typ tid, message msg)
 
syscall sleep (uint ms)
 
syscall suspend (tid_typ tid)
 
syscall unsleep (tid_typ tid)
 
void userret (void)
 
syscall yield (void)
 

Detailed Description

Thread functions.

Function Documentation

syscall chprio ( tid_typ  tid,
int  newprio 
)

Change the scheduling priority of a thread

Parameters
tidtarget thread
newprionew priority
Returns
old priority of thread
tid_typ create ( void *  procaddr,
uint  ssize,
int  priority,
const char *  name,
int  nargs,
  ... 
)

Create a thread to start running a procedure.

Parameters
procaddrprocedure address
ssizestack size in bytes
prioritythread priority (0 is lowest priority)
namename of the thread, used for debugging
nargsnumber of arguments that follow
...arguments to pass to thread procedure
Returns
the new thread's thread id, or ::SYSERR if a new thread could not be created (not enough memory or thread entries).
tid_typ dequeue ( qid_typ  q)

Remove and return the first thread on a list

Parameters
qtarget queue
Returns
thread id of removed thread, or EMPTY
tid_typ enqueue ( tid_typ  tid,
qid_typ  q 
)

Insert a thread at the tail of a queue

Parameters
tidthread ID to enqueue
qtarget queue
Returns
thread id of enqueued thread
tid_typ getfirst ( qid_typ  q)

Remove a thread from front of queue

Parameters
qtarget queue
Returns
thread ID of removed thread
tid_typ getitem ( tid_typ  tid)

Remove a thread from anywhere in a queue

Parameters
tidthread ID to get
Returns
thread ID of removed thread
tid_typ getlast ( qid_typ  q)

Remove a thread from end of queue

Parameters
qtarget queue
Returns
thread ID of removed thread
syscall getprio ( tid_typ  tid)

Return the scheduling priority of a thread

Parameters
tidthread ID
Returns
priority of thread on success, SYSERR on failure
tid_typ gettid ( void  )

Get the thread id of currently executing thread.

Returns
thread id of the currently running thread
int insert ( tid_typ  tid,
qid_typ  q,
int  key 
)

Insert a thread into a queue in descending key order.

Parameters
tidthread ID to insert
qtarget queue
keysorting key
Returns
OK
int insertd ( tid_typ  tid,
qid_typ  q,
int  key 
)

Insert a thread in delta queue in ascending order

Parameters
tidthread id to insert
qqueue in which thread should be inserted
keydelta key
Returns
OK
syscall kill ( tid_typ  tid)

Kill a thread and remove it from the system

Parameters
tidtarget thread
Returns
OK on success, SYSERR otherwise
qid_typ queinit ( void  )

Initialize a new queue in the global thread queue table

Returns
newly allocated queue ID or SYSERR

< next available quetab entry

int ready ( tid_typ  tid,
bool  resch,
uint  core 
)

Make a thread eligible for CPU service.

Parameters
tidtarget thread
reschif RESCHED_YES, reschedules
Returns
OK if thread has been added to readylist, else SYSERR
message receive ( void  )

receive - wait for a message and return it

Returns
message
message recvclr ( void  )

Clear messages, return waiting message (if any)

Returns
msg if available, NOMSG if no message
message recvtime ( int  maxwait)

wait to receive a message or timeout and return result

Parameters
maxwaitticks to wait before timeout
Returns
msg if becomes available, TIMEOUT if no message
int resched ( void  )

Reschedule processor to highest priority ready thread. Upon entry, thrcurrent gives current thread id. Threadtab[thrcurrent].pstate gives correct NEXT state for current thread if other than THRREADY.

Returns
OK when the thread is context switched back
syscall resume ( tid_typ  tid)

Unsuspend a thread, making it ready

Parameters
tidtarget thread
Returns
priority
syscall send ( tid_typ  tid,
message  msg 
)

Send a message to another thread

Parameters
tidthread id of recipient
msgcontents of message
Returns
OK on success, SYSERR on failure
syscall sleep ( uint  ms)

Yields the processor for the specified number of milliseconds, allowing other threads to be scheduled.

Parameters
msnumber of milliseconds to sleep
Returns
If successful, the thread will sleep for the specified number of milliseconds, then return ::OK. Otherwise, ::SYSERR will be returned. If a system timer is not supported, ::SYSERR will always returned.
syscall suspend ( tid_typ  tid)

Suspend a thread, placing it in hibernation

Parameters
tidtarget thread
Returns
priority or SYSERR
syscall unsleep ( tid_typ  tid)

Remove thread from the sleep queue prematurely

Parameters
tidtarget thread
Returns
OK if thread removed, else SYSERR
void userret ( void  )

Entered when a thread exits by return.

syscall yield ( void  )

Yield processor.

Returns
OK when the thread is context switched back