2005-06-07 14:34:25 +02:00
|
|
|
#define NEW_ELOCKED_CHECK 1
|
|
|
|
#define NEW_SCHED_Q 1
|
|
|
|
#define OLD_SEND 0
|
|
|
|
#define OLD_RECV 0
|
2005-04-21 16:53:53 +02:00
|
|
|
/* This file contains essentially all of the process and message handling.
|
2005-05-30 13:05:42 +02:00
|
|
|
* Together with "mpx.s" it forms the lowest layer of the MINIX kernel.
|
|
|
|
* There is one entry point from the outside:
|
2005-04-21 16:53:53 +02:00
|
|
|
*
|
2005-05-24 12:06:17 +02:00
|
|
|
* sys_call: a system call, i.e., the kernel is trapped with an INT
|
2005-04-21 16:53:53 +02:00
|
|
|
*
|
2005-05-30 13:05:42 +02:00
|
|
|
* As well as several entry points used from the interrupt and task level:
|
2005-04-21 16:53:53 +02:00
|
|
|
*
|
2005-05-24 12:06:17 +02:00
|
|
|
* lock_notify: send a notification to inform a process of a system event
|
2005-05-18 12:36:23 +02:00
|
|
|
* lock_send: send a message to a process
|
2005-04-21 16:53:53 +02:00
|
|
|
* lock_ready: put a process on one of the ready queues so it can be run
|
|
|
|
* lock_unready: remove a process from the ready queues
|
|
|
|
* lock_sched: a process has run too long; schedule another one
|
|
|
|
* lock_pick_proc: pick a process to run (used by system initialization)
|
|
|
|
*
|
|
|
|
* Changes:
|
2005-05-30 13:05:42 +02:00
|
|
|
* , 2005 better protection in sys_call() (Jorrit N. Herder)
|
2005-05-26 15:17:57 +02:00
|
|
|
* May 26, 2005 optimized message passing functions (Jorrit N. Herder)
|
2005-05-24 12:06:17 +02:00
|
|
|
* May 24, 2005 new, queued NOTIFY system call (Jorrit N. Herder)
|
2005-05-30 13:05:42 +02:00
|
|
|
* Oct 28, 2004 new, non-blocking SEND and RECEIVE (Jorrit N. Herder)
|
|
|
|
* Oct 28, 2004 rewrite of sys_call() function (Jorrit N. Herder)
|
|
|
|
* Aug 19, 2004 generalized multilevel scheduling (Jorrit N. Herder)
|
|
|
|
*
|
|
|
|
* The code here is critical to make everything work and is important for the
|
|
|
|
* overall performance of the system. A large fraction of the code deals with
|
|
|
|
* list manipulation. To make this both easy to understand and fast to execute
|
|
|
|
* pointer pointers are used throughout the code. Pointer pointers prevent
|
|
|
|
* exceptions for the head or tail of a linked list.
|
|
|
|
*
|
|
|
|
* node_t *queue, *new_node; // assume these as global variables
|
|
|
|
* node_t **xpp = &queue; // get pointer pointer to head of queue
|
|
|
|
* while (*xpp != NULL) // find last pointer of the linked list
|
|
|
|
* xpp = &(*xpp)->next; // get pointer to next pointer
|
|
|
|
* *xpp = new_node; // now replace the end (the NULL pointer)
|
|
|
|
* new_node->next = NULL; // and mark the new end of the list
|
|
|
|
*
|
|
|
|
* For example, when adding a new node to the end of the list, one normally
|
|
|
|
* makes an exception for an empty list and looks up the end of the list for
|
|
|
|
* nonempty lists. As shown above, this is not required with pointer pointers.
|
2005-04-21 16:53:53 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "kernel.h"
|
|
|
|
#include <minix/callnr.h>
|
|
|
|
#include <minix/com.h>
|
|
|
|
#include "proc.h"
|
2005-06-01 11:37:52 +02:00
|
|
|
#include "debug.h"
|
2005-05-27 15:57:00 +02:00
|
|
|
#include "ipc.h"
|
2005-04-21 16:53:53 +02:00
|
|
|
#include "sendmask.h"
|
|
|
|
|
|
|
|
|
2005-05-24 12:06:17 +02:00
|
|
|
/* Scheduling and message passing functions. The functions are available to
|
|
|
|
* other parts of the kernel through lock_...(). The lock temporarily disables
|
|
|
|
* interrupts to prevent race conditions.
|
|
|
|
*/
|
|
|
|
FORWARD _PROTOTYPE( int mini_send, (struct proc *caller_ptr, int dst,
|
2005-05-27 14:44:14 +02:00
|
|
|
message *m_ptr, unsigned flags) );
|
2005-06-07 14:34:25 +02:00
|
|
|
FORWARD _PROTOTYPE( int mini_receive, (struct proc *caller_ptr, int src,
|
2005-05-27 14:44:14 +02:00
|
|
|
message *m_ptr, unsigned flags) );
|
2005-05-24 12:06:17 +02:00
|
|
|
FORWARD _PROTOTYPE( int mini_notify, (struct proc *caller_ptr, int dst,
|
2005-05-18 12:36:23 +02:00
|
|
|
message *m_ptr ) );
|
2005-05-24 12:06:17 +02:00
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
FORWARD _PROTOTYPE( void ready, (struct proc *rp) );
|
|
|
|
FORWARD _PROTOTYPE( void unready, (struct proc *rp) );
|
2005-05-30 13:05:42 +02:00
|
|
|
FORWARD _PROTOTYPE( void sched, (int queue) );
|
2005-04-21 16:53:53 +02:00
|
|
|
FORWARD _PROTOTYPE( void pick_proc, (void) );
|
|
|
|
|
2005-05-26 15:17:57 +02:00
|
|
|
#define BuildMess(m,n) \
|
|
|
|
(m).NOTIFY_SOURCE = (n)->n_source, \
|
|
|
|
(m).NOTIFY_TYPE = (n)->n_type, \
|
|
|
|
(m).NOTIFY_FLAGS = (n)->n_flags, \
|
|
|
|
(m).NOTIFY_ARG = (n)->n_arg;
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
#if (CHIP == INTEL)
|
|
|
|
#define CopyMess(s,sp,sm,dp,dm) \
|
|
|
|
cp_mess(s, (sp)->p_memmap[D].mem_phys, (vir_bytes)sm, (dp)->p_memmap[D].mem_phys, (vir_bytes)dm)
|
|
|
|
#endif /* (CHIP == INTEL) */
|
|
|
|
|
|
|
|
#if (CHIP == M68000)
|
|
|
|
/* M68000 does not have cp_mess() in assembly like INTEL. Declare prototype
|
|
|
|
* for cp_mess() here and define the function below. Also define CopyMess.
|
|
|
|
*/
|
|
|
|
#endif /* (CHIP == M68000) */
|
|
|
|
|
|
|
|
|
2005-05-18 12:36:23 +02:00
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* sys_call *
|
|
|
|
*===========================================================================*/
|
|
|
|
PUBLIC int sys_call(call_nr, src_dst, m_ptr)
|
2005-05-30 13:05:42 +02:00
|
|
|
int call_nr; /* system call number and flags */
|
2005-05-24 12:06:17 +02:00
|
|
|
int src_dst; /* src to receive from or dst to send to */
|
2005-04-21 16:53:53 +02:00
|
|
|
message *m_ptr; /* pointer to message in the caller's space */
|
|
|
|
{
|
|
|
|
/* System calls are done by trapping to the kernel with an INT instruction.
|
|
|
|
* The trap is caught and sys_call() is called to send or receive a message
|
|
|
|
* (or both). The caller is always given by 'proc_ptr'.
|
|
|
|
*/
|
|
|
|
register struct proc *caller_ptr = proc_ptr; /* get pointer to caller */
|
|
|
|
int function = call_nr & SYSCALL_FUNC; /* get system call function */
|
2005-05-27 14:44:14 +02:00
|
|
|
unsigned flags = call_nr & SYSCALL_FLAGS; /* get flags */
|
2005-04-21 16:53:53 +02:00
|
|
|
int mask_entry; /* bit to check in send mask */
|
|
|
|
int result; /* the system call's result */
|
2005-05-26 15:17:57 +02:00
|
|
|
vir_bytes vb; /* message buffer pointer as vir_bytes */
|
|
|
|
vir_clicks vlo, vhi; /* virtual clicks containing message to send */
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2005-05-31 11:50:51 +02:00
|
|
|
/* Check if the process has privileges for the requested call. Calls to the
|
|
|
|
* kernel may only be SENDREC, because tasks always reply and may not block
|
|
|
|
* if the caller doesn't do receive().
|
2005-04-21 16:53:53 +02:00
|
|
|
*/
|
2005-05-31 11:50:51 +02:00
|
|
|
if (! (caller_ptr->p_call_mask & (1 << function)) ||
|
2005-06-07 14:34:25 +02:00
|
|
|
(iskerneltask(src_dst) && function != SENDREC))
|
|
|
|
return(ECALLDENIED);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2005-06-07 14:34:25 +02:00
|
|
|
/* Require a valid source and/ or destination process, unless echoing. */
|
|
|
|
if (! (isokprocn(src_dst) || src_dst == ANY || function == ECHO))
|
|
|
|
return(EBADSRCDST);
|
2005-05-26 15:17:57 +02:00
|
|
|
|
|
|
|
/* Check validity of message pointer. */
|
|
|
|
vb = (vir_bytes) m_ptr;
|
|
|
|
vlo = vb >> CLICK_SHIFT; /* vir click for bottom of message */
|
|
|
|
vhi = (vb + MESS_SIZE - 1) >> CLICK_SHIFT; /* vir click for top of msg */
|
|
|
|
#if ALLOW_GAP_MESSAGES
|
|
|
|
/* This check allows a message to be anywhere in data or stack or gap.
|
|
|
|
* It will have to be made more elaborate later for machines which
|
|
|
|
* don't have the gap mapped.
|
|
|
|
*/
|
|
|
|
if (vlo < caller_ptr->p_memmap[D].mem_vir || vlo > vhi ||
|
|
|
|
vhi >= caller_ptr->p_memmap[S].mem_vir + caller_ptr->p_memmap[S].mem_len)
|
|
|
|
return(EFAULT);
|
|
|
|
#else
|
|
|
|
/* Check for messages wrapping around top of memory or outside data seg. */
|
|
|
|
if (vhi < vlo ||
|
|
|
|
vhi - caller_ptr->p_memmap[D].mem_vir >= caller_ptr->p_memmap[D].mem_len)
|
|
|
|
return(EFAULT);
|
|
|
|
#endif
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* Now check if the call is known and try to perform the request. The only
|
|
|
|
* system calls that exist in MINIX are sending and receiving messages.
|
2005-05-30 13:05:42 +02:00
|
|
|
* - SENDREC: combines SEND and RECEIVE in a single system call
|
|
|
|
* - SEND: sender blocks until its message has been delivered
|
|
|
|
* - RECEIVE: receiver blocks until an acceptable message has arrived
|
|
|
|
* - NOTIFY: sender continues; either directly deliver the message or
|
|
|
|
* queue the notification message until it can be delivered
|
|
|
|
* - ECHO: the message directly will be echoed to the sender
|
2005-04-21 16:53:53 +02:00
|
|
|
*/
|
2005-05-26 15:17:57 +02:00
|
|
|
switch(function) {
|
2005-06-07 14:34:25 +02:00
|
|
|
case SENDREC: /* has FRESH_ANSWER flag */
|
2005-05-27 14:44:14 +02:00
|
|
|
/* fall through */
|
|
|
|
case SEND:
|
2005-05-26 15:17:57 +02:00
|
|
|
if (! isalive(src_dst)) {
|
|
|
|
result = EDEADDST; /* cannot send to the dead */
|
2005-04-21 16:53:53 +02:00
|
|
|
break;
|
|
|
|
}
|
2005-05-26 15:17:57 +02:00
|
|
|
mask_entry = isuser(src_dst) ? USER_PROC_NR : src_dst;
|
|
|
|
if (! isallowed(caller_ptr->p_sendmask, mask_entry)) {
|
|
|
|
kprintf("WARNING: sys_call denied %d ", caller_ptr->p_nr);
|
|
|
|
kprintf("sending to %d\n", proc_addr(src_dst)->p_nr);
|
|
|
|
result = ECALLDENIED; /* call denied by send mask */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-05-27 14:44:14 +02:00
|
|
|
result = mini_send(caller_ptr, src_dst, m_ptr, flags);
|
2005-05-26 15:17:57 +02:00
|
|
|
if (function == SEND || result != OK) {
|
|
|
|
break; /* done, or SEND failed */
|
2005-05-27 14:44:14 +02:00
|
|
|
} /* fall through for SENDREC */
|
2005-05-26 15:17:57 +02:00
|
|
|
case RECEIVE:
|
2005-06-07 14:34:25 +02:00
|
|
|
result = mini_receive(caller_ptr, src_dst, m_ptr, flags);
|
2005-05-26 15:17:57 +02:00
|
|
|
break;
|
|
|
|
case NOTIFY:
|
|
|
|
result = mini_notify(caller_ptr, src_dst, m_ptr);
|
|
|
|
break;
|
2005-05-27 15:57:00 +02:00
|
|
|
case ECHO:
|
|
|
|
kprintf("Echo message from process %s\n", proc_nr(caller_ptr));
|
|
|
|
CopyMess(caller_ptr->p_nr, caller_ptr, m_ptr, caller_ptr, m_ptr);
|
|
|
|
result = OK;
|
|
|
|
break;
|
2005-05-26 15:17:57 +02:00
|
|
|
default:
|
|
|
|
result = EBADCALL; /* illegal system call */
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Now, return the result of the system call to the caller. */
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* mini_send *
|
|
|
|
*===========================================================================*/
|
2005-05-26 15:17:57 +02:00
|
|
|
PRIVATE int mini_send(caller_ptr, dst, m_ptr, flags)
|
2005-04-21 16:53:53 +02:00
|
|
|
register struct proc *caller_ptr; /* who is trying to send a message? */
|
2005-05-24 12:06:17 +02:00
|
|
|
int dst; /* to whom is message being sent? */
|
2005-04-21 16:53:53 +02:00
|
|
|
message *m_ptr; /* pointer to message buffer */
|
2005-05-27 14:44:14 +02:00
|
|
|
unsigned flags; /* system call flags */
|
2005-04-21 16:53:53 +02:00
|
|
|
{
|
2005-05-24 12:06:17 +02:00
|
|
|
/* Send a message from 'caller_ptr' to 'dst'. If 'dst' is blocked waiting
|
|
|
|
* for this message, copy the message to it and unblock 'dst'. If 'dst' is
|
2005-04-21 16:53:53 +02:00
|
|
|
* not waiting at all, or is waiting for another source, queue 'caller_ptr'.
|
|
|
|
*/
|
2005-05-26 15:17:57 +02:00
|
|
|
register struct proc *dst_ptr;
|
2005-05-27 14:44:14 +02:00
|
|
|
#if OLD_SEND
|
2005-05-26 15:17:57 +02:00
|
|
|
register struct proc *next_ptr;
|
|
|
|
register struct proc *xp;
|
2005-05-27 14:44:14 +02:00
|
|
|
#else
|
2005-05-26 15:17:57 +02:00
|
|
|
register struct proc **xpp;
|
2005-06-07 14:34:25 +02:00
|
|
|
register struct proc *xp;
|
2005-05-27 14:44:14 +02:00
|
|
|
#endif
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2005-05-24 12:06:17 +02:00
|
|
|
dst_ptr = proc_addr(dst); /* pointer to destination's proc entry */
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2005-05-27 14:44:14 +02:00
|
|
|
|
2005-06-06 11:30:44 +02:00
|
|
|
/* Check for deadlock by 'caller_ptr' and 'dst' sending to each other. */
|
2005-06-07 14:34:25 +02:00
|
|
|
#if NEW_ELOCKED_CHECK
|
|
|
|
xp = dst_ptr;
|
|
|
|
while (xp->p_flags & SENDING) { /* check while sending */
|
|
|
|
xp = proc_addr(xp->p_sendto); /* get xp's destination */
|
|
|
|
if (xp == caller_ptr) return(ELOCKED); /* deadlock if cyclic */
|
|
|
|
}
|
|
|
|
#else
|
2005-05-24 12:06:17 +02:00
|
|
|
if (dst_ptr->p_flags & SENDING) {
|
|
|
|
next_ptr = proc_addr(dst_ptr->p_sendto);
|
2005-04-21 16:53:53 +02:00
|
|
|
while (TRUE) {
|
|
|
|
if (next_ptr == caller_ptr) return(ELOCKED);
|
|
|
|
if (next_ptr->p_flags & SENDING)
|
|
|
|
next_ptr = proc_addr(next_ptr->p_sendto);
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2005-06-07 14:34:25 +02:00
|
|
|
#endif
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2005-05-26 15:17:57 +02:00
|
|
|
/* Check if 'dst' is blocked waiting for this message. The destination's
|
2005-05-30 13:05:42 +02:00
|
|
|
* SENDING flag may be set when its SENDREC call blocked while sending.
|
2005-05-26 15:17:57 +02:00
|
|
|
*/
|
2005-05-24 12:06:17 +02:00
|
|
|
if ( (dst_ptr->p_flags & (RECEIVING | SENDING)) == RECEIVING &&
|
2005-05-26 15:17:57 +02:00
|
|
|
(dst_ptr->p_getfrom == ANY || dst_ptr->p_getfrom == caller_ptr->p_nr)) {
|
2005-04-21 16:53:53 +02:00
|
|
|
/* Destination is indeed waiting for this message. */
|
2005-05-26 15:17:57 +02:00
|
|
|
CopyMess(caller_ptr->p_nr, caller_ptr, m_ptr, dst_ptr,
|
2005-05-24 12:06:17 +02:00
|
|
|
dst_ptr->p_messbuf);
|
2005-05-30 13:05:42 +02:00
|
|
|
if ((dst_ptr->p_flags &= ~RECEIVING) == 0) ready(dst_ptr);
|
2005-05-27 14:44:14 +02:00
|
|
|
} else if ( ! (flags & NON_BLOCKING)) {
|
2005-04-21 16:53:53 +02:00
|
|
|
/* Destination is not waiting. Block and queue caller. */
|
|
|
|
caller_ptr->p_messbuf = m_ptr;
|
|
|
|
if (caller_ptr->p_flags == 0) unready(caller_ptr);
|
|
|
|
caller_ptr->p_flags |= SENDING;
|
2005-05-24 12:06:17 +02:00
|
|
|
caller_ptr->p_sendto = dst;
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* Process is now blocked. Put in on the destination's queue. */
|
2005-05-27 14:44:14 +02:00
|
|
|
#if OLD_SEND
|
2005-05-24 12:06:17 +02:00
|
|
|
if ( (next_ptr = dst_ptr->p_caller_q) == NIL_PROC)
|
|
|
|
dst_ptr->p_caller_q = caller_ptr;
|
2005-04-21 16:53:53 +02:00
|
|
|
else {
|
2005-05-26 15:17:57 +02:00
|
|
|
while (next_ptr->p_q_link != NIL_PROC)
|
|
|
|
next_ptr = next_ptr->p_q_link;
|
|
|
|
next_ptr->p_q_link = caller_ptr;
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
2005-05-26 15:17:57 +02:00
|
|
|
#else
|
2005-05-30 13:05:42 +02:00
|
|
|
xpp = &dst_ptr->p_caller_q; /* find end of list */
|
2005-05-26 15:17:57 +02:00
|
|
|
while (*xpp != NIL_PROC) xpp = &(*xpp)->p_q_link;
|
2005-05-30 13:05:42 +02:00
|
|
|
*xpp = caller_ptr; /* add caller to end */
|
2005-05-26 15:17:57 +02:00
|
|
|
#endif
|
2005-05-30 13:05:42 +02:00
|
|
|
caller_ptr->p_q_link = NIL_PROC; /* mark new end of list */
|
2005-04-21 16:53:53 +02:00
|
|
|
} else {
|
|
|
|
return(ENOTREADY);
|
|
|
|
}
|
|
|
|
return(OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
2005-06-07 14:34:25 +02:00
|
|
|
* mini_receive *
|
2005-04-21 16:53:53 +02:00
|
|
|
*===========================================================================*/
|
2005-06-07 14:34:25 +02:00
|
|
|
PRIVATE int mini_receive(caller_ptr, src, m_ptr, flags)
|
2005-04-21 16:53:53 +02:00
|
|
|
register struct proc *caller_ptr; /* process trying to get message */
|
|
|
|
int src; /* which message source is wanted */
|
|
|
|
message *m_ptr; /* pointer to message buffer */
|
2005-05-27 14:44:14 +02:00
|
|
|
unsigned flags; /* system call flags */
|
2005-04-21 16:53:53 +02:00
|
|
|
{
|
2005-05-30 13:05:42 +02:00
|
|
|
/* A process or task wants to get a message. If a message is already queued,
|
2005-04-21 16:53:53 +02:00
|
|
|
* acquire it and deblock the sender. If no message from the desired source
|
2005-05-30 13:05:42 +02:00
|
|
|
* is available block the caller, unless the flags don't allow blocking.
|
2005-04-21 16:53:53 +02:00
|
|
|
*/
|
2005-05-27 14:44:14 +02:00
|
|
|
#if OLD_RECV
|
2005-04-21 16:53:53 +02:00
|
|
|
register struct proc *sender_ptr;
|
|
|
|
register struct proc *previous_ptr;
|
2005-05-27 14:44:14 +02:00
|
|
|
#else
|
2005-05-26 15:17:57 +02:00
|
|
|
register struct proc **xpp;
|
2005-05-27 14:44:14 +02:00
|
|
|
#endif
|
2005-05-19 16:05:51 +02:00
|
|
|
register struct notification **ntf_q_pp;
|
2005-04-21 16:53:53 +02:00
|
|
|
message m;
|
2005-05-26 15:17:57 +02:00
|
|
|
int bit_nr;
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2005-05-26 15:17:57 +02:00
|
|
|
/* Check to see if a message from desired source is already available.
|
2005-05-27 14:44:14 +02:00
|
|
|
* The caller's SENDING flag may be set if SENDREC couldn't send. If it is
|
2005-05-26 15:17:57 +02:00
|
|
|
* set, the process should be blocked.
|
|
|
|
*/
|
2005-04-21 16:53:53 +02:00
|
|
|
if (!(caller_ptr->p_flags & SENDING)) {
|
|
|
|
|
2005-05-26 15:17:57 +02:00
|
|
|
/* Check caller queue. Use pointer pointers to keep code simple. */
|
2005-05-27 14:44:14 +02:00
|
|
|
#if OLD_RECV /* to hairy, unreadable */
|
2005-05-19 16:05:51 +02:00
|
|
|
for (sender_ptr = caller_ptr->p_caller_q; sender_ptr != NIL_PROC;
|
2005-05-26 15:17:57 +02:00
|
|
|
previous_ptr = sender_ptr, sender_ptr = sender_ptr->p_q_link) {
|
|
|
|
if (src == ANY || src == proc_nr(sender_ptr)) {
|
2005-04-21 16:53:53 +02:00
|
|
|
/* An acceptable message has been found. */
|
2005-05-26 15:17:57 +02:00
|
|
|
CopyMess(sender_ptr->p_nr, sender_ptr,
|
2005-04-21 16:53:53 +02:00
|
|
|
sender_ptr->p_messbuf, caller_ptr, m_ptr);
|
2005-05-19 16:05:51 +02:00
|
|
|
if (sender_ptr == caller_ptr->p_caller_q)
|
2005-05-26 15:17:57 +02:00
|
|
|
caller_ptr->p_caller_q = sender_ptr->p_q_link;
|
2005-04-21 16:53:53 +02:00
|
|
|
else
|
2005-05-26 15:17:57 +02:00
|
|
|
previous_ptr->p_q_link = sender_ptr->p_q_link;
|
2005-04-21 16:53:53 +02:00
|
|
|
if ((sender_ptr->p_flags &= ~SENDING) == 0)
|
|
|
|
ready(sender_ptr); /* deblock sender */
|
|
|
|
return(OK);
|
|
|
|
}
|
|
|
|
}
|
2005-05-26 15:17:57 +02:00
|
|
|
#else
|
|
|
|
xpp = &caller_ptr->p_caller_q;
|
|
|
|
while (*xpp != NIL_PROC) {
|
|
|
|
if (src == ANY || src == proc_nr(*xpp)) {
|
2005-05-30 13:05:42 +02:00
|
|
|
/* Found acceptable message. Copy it and update status. */
|
2005-05-26 15:17:57 +02:00
|
|
|
CopyMess((*xpp)->p_nr, *xpp, (*xpp)->p_messbuf, caller_ptr, m_ptr);
|
|
|
|
if (((*xpp)->p_flags &= ~SENDING) == 0) ready(*xpp);
|
|
|
|
*xpp = (*xpp)->p_q_link; /* remove from queue */
|
2005-05-30 13:05:42 +02:00
|
|
|
return(OK); /* report success */
|
2005-05-26 15:17:57 +02:00
|
|
|
}
|
|
|
|
xpp = &(*xpp)->p_q_link; /* proceed to next */
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-05-30 13:05:42 +02:00
|
|
|
/* Check if there are pending notifications, except for SENDREC. */
|
|
|
|
if (! (flags & FRESH_ANSWER)) {
|
2005-05-27 14:44:14 +02:00
|
|
|
|
2005-05-30 13:05:42 +02:00
|
|
|
ntf_q_pp = &caller_ptr->p_ntf_q; /* get pointer pointer */
|
|
|
|
while (*ntf_q_pp != NULL) {
|
|
|
|
if (src == ANY || src == (*ntf_q_pp)->n_source) {
|
2005-05-19 16:05:51 +02:00
|
|
|
/* Found notification. Assemble and copy message. */
|
2005-05-26 15:17:57 +02:00
|
|
|
BuildMess(m, *ntf_q_pp);
|
2005-05-19 16:05:51 +02:00
|
|
|
CopyMess((*ntf_q_pp)->n_source, proc_addr(HARDWARE), &m,
|
|
|
|
caller_ptr, m_ptr);
|
2005-05-26 15:17:57 +02:00
|
|
|
/* Remove notification from queue and bit map. */
|
2005-05-27 14:44:14 +02:00
|
|
|
bit_nr = (int) (*ntf_q_pp - ¬ify_buffer[0]);
|
2005-05-19 16:05:51 +02:00
|
|
|
*ntf_q_pp = (*ntf_q_pp)->n_next;/* remove from queue */
|
2005-05-24 12:06:17 +02:00
|
|
|
free_bit(bit_nr, notify_bitmap, NR_NOTIFY_BUFS);
|
2005-05-19 16:05:51 +02:00
|
|
|
return(OK); /* report success */
|
2005-05-30 13:05:42 +02:00
|
|
|
}
|
|
|
|
ntf_q_pp = &(*ntf_q_pp)->n_next; /* proceed to next */
|
|
|
|
}
|
2005-05-19 16:05:51 +02:00
|
|
|
}
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|
2005-05-27 14:44:14 +02:00
|
|
|
/* No suitable message is available or the caller couldn't send in SENDREC.
|
2005-05-26 15:17:57 +02:00
|
|
|
* Block the process trying to receive, unless the flags tell otherwise.
|
2005-04-21 16:53:53 +02:00
|
|
|
*/
|
2005-05-27 14:44:14 +02:00
|
|
|
if ( ! (flags & NON_BLOCKING)) {
|
2005-05-30 13:05:42 +02:00
|
|
|
caller_ptr->p_getfrom = src;
|
2005-04-21 16:53:53 +02:00
|
|
|
caller_ptr->p_messbuf = m_ptr;
|
|
|
|
if (caller_ptr->p_flags == 0) unready(caller_ptr);
|
2005-05-30 13:05:42 +02:00
|
|
|
caller_ptr->p_flags |= RECEIVING;
|
2005-04-21 16:53:53 +02:00
|
|
|
return(OK);
|
|
|
|
} else {
|
|
|
|
return(ENOTREADY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-24 12:06:17 +02:00
|
|
|
|
2005-05-18 12:36:23 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* mini_notify *
|
|
|
|
*===========================================================================*/
|
|
|
|
PRIVATE int mini_notify(caller_ptr, dst, m_ptr)
|
2005-05-19 16:05:51 +02:00
|
|
|
register struct proc *caller_ptr; /* process trying to notify */
|
2005-05-18 12:36:23 +02:00
|
|
|
int dst; /* which process to notify */
|
|
|
|
message *m_ptr; /* pointer to message buffer */
|
|
|
|
{
|
2005-05-24 12:06:17 +02:00
|
|
|
register struct proc *dst_ptr = proc_addr(dst);
|
2005-05-19 16:05:51 +02:00
|
|
|
register struct notification *ntf_p ;
|
|
|
|
register struct notification **ntf_q_pp;
|
|
|
|
int ntf_index;
|
|
|
|
message ntf_mess;
|
|
|
|
|
2005-05-26 15:17:57 +02:00
|
|
|
/* Check to see if target is blocked waiting for this message. A process
|
2005-05-27 14:44:14 +02:00
|
|
|
* can be both sending and receiving during a SENDREC system call.
|
2005-05-26 15:17:57 +02:00
|
|
|
*/
|
2005-05-27 14:44:14 +02:00
|
|
|
if ( (dst_ptr->p_flags & (RECEIVING|SENDING)) == RECEIVING &&
|
2005-05-26 15:17:57 +02:00
|
|
|
(dst_ptr->p_getfrom == ANY || dst_ptr->p_getfrom == caller_ptr->p_nr)) {
|
2005-05-24 12:06:17 +02:00
|
|
|
|
2005-05-19 16:05:51 +02:00
|
|
|
/* Destination is indeed waiting for this message. */
|
2005-05-26 15:17:57 +02:00
|
|
|
CopyMess(proc_nr(caller_ptr), caller_ptr, m_ptr,
|
|
|
|
dst_ptr, dst_ptr->p_messbuf);
|
2005-05-24 12:06:17 +02:00
|
|
|
dst_ptr->p_flags &= ~RECEIVING; /* deblock destination */
|
|
|
|
if (dst_ptr->p_flags == 0) ready(dst_ptr);
|
2005-05-27 14:44:14 +02:00
|
|
|
return(OK);
|
2005-05-24 12:06:17 +02:00
|
|
|
}
|
2005-05-19 16:05:51 +02:00
|
|
|
|
2005-05-27 14:44:14 +02:00
|
|
|
/* Destination is not ready. Add the notification to the pending queue.
|
2005-05-30 13:05:42 +02:00
|
|
|
* Get pointer to notification message. Don't copy if already in kernel.
|
2005-05-27 14:44:14 +02:00
|
|
|
*/
|
2005-06-07 14:34:25 +02:00
|
|
|
if (! istaskp(caller_ptr)) {
|
2005-05-27 14:44:14 +02:00
|
|
|
CopyMess(proc_nr(caller_ptr), caller_ptr, m_ptr,
|
|
|
|
proc_addr(HARDWARE), &ntf_mess);
|
|
|
|
m_ptr = &ntf_mess;
|
|
|
|
}
|
2005-05-19 16:05:51 +02:00
|
|
|
|
2005-05-27 14:44:14 +02:00
|
|
|
/* Enqueue the message. Existing notifications with the same source
|
|
|
|
* and type are overwritten with newer ones. New notifications that
|
|
|
|
* are not yet on the list are added to the end.
|
|
|
|
*/
|
|
|
|
ntf_q_pp = &dst_ptr->p_ntf_q;
|
|
|
|
while (*ntf_q_pp != NULL) {
|
|
|
|
/* Replace notifications with same source and type. */
|
|
|
|
if ((*ntf_q_pp)->n_type == m_ptr->NOTIFY_TYPE &&
|
|
|
|
(*ntf_q_pp)->n_source == proc_nr(caller_ptr)) {
|
|
|
|
(*ntf_q_pp)->n_flags = m_ptr->NOTIFY_FLAGS;
|
|
|
|
(*ntf_q_pp)->n_arg = m_ptr->NOTIFY_ARG;
|
|
|
|
return(OK);
|
|
|
|
}
|
|
|
|
ntf_q_pp = &(*ntf_q_pp)->n_next;
|
2005-05-19 16:05:51 +02:00
|
|
|
}
|
2005-05-27 14:44:14 +02:00
|
|
|
|
|
|
|
/* Add to end of queue (found above). Get a free notification buffer. */
|
|
|
|
if ((ntf_index = alloc_bit(notify_bitmap, NR_NOTIFY_BUFS)) < 0)
|
|
|
|
return(ENOSPC);
|
2005-05-30 13:05:42 +02:00
|
|
|
ntf_p = ¬ify_buffer[ntf_index]; /* get pointer to buffer */
|
|
|
|
ntf_p->n_source = proc_nr(caller_ptr);/* store notification data */
|
2005-05-27 14:44:14 +02:00
|
|
|
ntf_p->n_type = m_ptr->NOTIFY_TYPE;
|
|
|
|
ntf_p->n_flags = m_ptr->NOTIFY_FLAGS;
|
|
|
|
ntf_p->n_arg = m_ptr->NOTIFY_ARG;
|
2005-05-30 13:05:42 +02:00
|
|
|
*ntf_q_pp = ntf_p; /* add to end of queue */
|
|
|
|
ntf_p->n_next = NULL; /* mark new end of queue */
|
2005-05-18 12:36:23 +02:00
|
|
|
return(OK);
|
|
|
|
}
|
|
|
|
|
2005-05-24 12:06:17 +02:00
|
|
|
/*==========================================================================*
|
|
|
|
* lock_notify *
|
|
|
|
*==========================================================================*/
|
2005-05-24 16:35:58 +02:00
|
|
|
PUBLIC int lock_notify(dst, m_ptr)
|
2005-05-24 12:06:17 +02:00
|
|
|
int dst; /* to whom is message being sent? */
|
|
|
|
message *m_ptr; /* pointer to message buffer */
|
|
|
|
{
|
2005-05-24 16:35:58 +02:00
|
|
|
/* Safe gateway to mini_notify() for tasks and interrupt handlers. This
|
2005-05-30 13:05:42 +02:00
|
|
|
* function checks if it is called from an interrupt handler and ensures
|
2005-05-26 15:17:57 +02:00
|
|
|
* that the correct message source is put on the notification.
|
2005-05-24 16:35:58 +02:00
|
|
|
*/
|
2005-05-24 12:06:17 +02:00
|
|
|
int result;
|
2005-05-24 16:35:58 +02:00
|
|
|
struct proc *caller_ptr;
|
|
|
|
|
2005-06-01 11:37:52 +02:00
|
|
|
lock(0, "notify");
|
2005-05-26 15:17:57 +02:00
|
|
|
caller_ptr = (k_reenter >= 0) ? proc_addr(HARDWARE) : proc_ptr;
|
2005-05-24 16:35:58 +02:00
|
|
|
result = mini_notify(caller_ptr, dst, m_ptr);
|
2005-06-01 11:37:52 +02:00
|
|
|
unlock(0);
|
2005-05-24 12:06:17 +02:00
|
|
|
return(result);
|
|
|
|
}
|
2005-05-18 12:36:23 +02:00
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* pick_proc *
|
|
|
|
*===========================================================================*/
|
|
|
|
PRIVATE void pick_proc()
|
|
|
|
{
|
2005-05-24 16:35:58 +02:00
|
|
|
/* Decide who to run now. A new process is selected by setting 'next_ptr'.
|
2005-04-21 16:53:53 +02:00
|
|
|
* When a fresh user (or idle) process is selected, record it in 'bill_ptr',
|
|
|
|
* so the clock task can tell who to bill for system time.
|
|
|
|
*/
|
|
|
|
register struct proc *rp; /* process to run */
|
|
|
|
int q; /* iterate over queues */
|
|
|
|
|
|
|
|
/* Check each of the scheduling queues for ready processes. The number of
|
|
|
|
* queues is defined in proc.h, and priorities are set in the task table.
|
|
|
|
* The lowest queue contains IDLE, which is always ready.
|
|
|
|
*/
|
|
|
|
for (q=0; q < NR_SCHED_QUEUES; q++) {
|
|
|
|
if ( (rp = rdy_head[q]) != NIL_PROC) {
|
2005-05-24 16:35:58 +02:00
|
|
|
next_ptr = rp; /* run process 'rp' next */
|
2005-04-21 16:53:53 +02:00
|
|
|
if (isuserp(rp) || isidlep(rp)) /* possible bill 'rp' */
|
|
|
|
bill_ptr = rp;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* ready *
|
|
|
|
*===========================================================================*/
|
|
|
|
PRIVATE void ready(rp)
|
|
|
|
register struct proc *rp; /* this process is now runnable */
|
|
|
|
{
|
|
|
|
/* Add 'rp' to one of the queues of runnable processes. */
|
2005-05-30 13:05:42 +02:00
|
|
|
register int q = rp->p_priority; /* scheduling queue to use */
|
|
|
|
register struct proc **xpp; /* iterate over queue */
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2005-05-24 14:32:34 +02:00
|
|
|
#if ENABLE_K_DEBUGGING
|
|
|
|
if(rp->p_ready) {
|
|
|
|
kprintf("ready() already ready process\n", NO_NUM);
|
|
|
|
}
|
|
|
|
rp->p_ready = 1;
|
|
|
|
#endif
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
/* Processes, in principle, are added to the end of the queue. However,
|
|
|
|
* user processes are added in front of the queue, because this is a bit
|
|
|
|
* fairer to I/O bound processes.
|
|
|
|
*/
|
2005-05-26 15:17:57 +02:00
|
|
|
#if NEW_SCHED_Q
|
2005-05-30 13:05:42 +02:00
|
|
|
if (isuserp(rp)) { /* add to front of queue */
|
|
|
|
rp->p_nextready = rdy_head[q]; /* chain current front */
|
|
|
|
rdy_head[q] = rp; /* rp becomes new front */
|
2005-05-26 15:17:57 +02:00
|
|
|
}
|
2005-05-30 13:05:42 +02:00
|
|
|
else { /* add to end of queue */
|
|
|
|
xpp = &rdy_head[q]; /* find pointer to end */
|
2005-05-26 15:17:57 +02:00
|
|
|
while (*xpp != NIL_PROC) xpp = &(*xpp)->p_nextready;
|
2005-05-30 13:05:42 +02:00
|
|
|
*xpp = rp; /* replace end with rp */
|
|
|
|
rp->p_nextready = NIL_PROC; /* mark end of queue */
|
2005-05-26 15:17:57 +02:00
|
|
|
}
|
|
|
|
#else
|
2005-04-21 16:53:53 +02:00
|
|
|
if (isuserp(rp)) { /* add to front of queue */
|
|
|
|
if (rdy_head[q] == NIL_PROC)
|
|
|
|
rdy_tail[q] = rp;
|
|
|
|
rp->p_nextready = rdy_head[q]; /* add to front of queue */
|
|
|
|
rdy_head[q] = rp;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (rdy_head[q] != NIL_PROC)
|
|
|
|
rdy_tail[q]->p_nextready = rp; /* add to end of queue */
|
|
|
|
else
|
|
|
|
rdy_head[q] = rp; /* add to empty queue */
|
|
|
|
rdy_tail[q] = rp;
|
|
|
|
rp->p_nextready = NIL_PROC;
|
|
|
|
}
|
2005-05-26 15:17:57 +02:00
|
|
|
#endif
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2005-05-24 16:35:58 +02:00
|
|
|
/* Run 'rp' next if it has a higher priority than 'proc_ptr' or 'next_ptr'.
|
|
|
|
* This actually should be done via pick_proc(), but the message passing
|
|
|
|
* functions rely on this side-effect. High priorities have a lower number.
|
2005-04-21 16:53:53 +02:00
|
|
|
*/
|
2005-05-24 16:35:58 +02:00
|
|
|
if (next_ptr && next_ptr->p_priority > rp->p_priority) next_ptr = rp;
|
|
|
|
else if (proc_ptr->p_priority > rp->p_priority) next_ptr = rp;
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* unready *
|
|
|
|
*===========================================================================*/
|
|
|
|
PRIVATE void unready(rp)
|
|
|
|
register struct proc *rp; /* this process is no longer runnable */
|
|
|
|
{
|
|
|
|
/* A process has blocked. See ready for a description of the queues. */
|
|
|
|
|
2005-05-30 13:05:42 +02:00
|
|
|
register int q = rp->p_priority; /* queue to use */
|
2005-05-26 15:17:57 +02:00
|
|
|
#if NEW_SCHED_Q
|
2005-05-30 13:05:42 +02:00
|
|
|
register struct proc **xpp; /* iterate over queue */
|
2005-05-26 15:17:57 +02:00
|
|
|
#else
|
2005-05-30 13:05:42 +02:00
|
|
|
register struct proc **qtail; /* queue's rdy_tail */
|
2005-05-26 15:17:57 +02:00
|
|
|
register struct proc *xp;
|
|
|
|
#endif
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2005-05-24 14:32:34 +02:00
|
|
|
#if ENABLE_K_DEBUGGING
|
|
|
|
if(!rp->p_ready) {
|
|
|
|
kprintf("unready() already unready process\n", NO_NUM);
|
|
|
|
}
|
|
|
|
rp->p_ready = 0;
|
|
|
|
#endif
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
/* Side-effect for tasks: check if the task's stack still is ok? */
|
|
|
|
if (istaskp(rp)) {
|
|
|
|
if (*rp->p_stguard != STACK_GUARD)
|
2005-05-26 15:17:57 +02:00
|
|
|
panic("stack overrun by task", proc_nr(rp));
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Now make sure that the process is not in its ready queue. Remove the
|
2005-05-20 11:37:43 +02:00
|
|
|
* process if it is found. A process can be made unready even if it is not
|
|
|
|
* running by being sent a signal that kills it.
|
2005-04-21 16:53:53 +02:00
|
|
|
*/
|
2005-05-26 15:17:57 +02:00
|
|
|
#if NEW_SCHED_Q
|
|
|
|
xpp = &rdy_head[q];
|
|
|
|
while (*xpp != NIL_PROC) { /* check entire queue */
|
|
|
|
if (*xpp == rp) { /* lookup unready process */
|
|
|
|
*xpp = (*xpp)->p_nextready; /* replace it with next */
|
|
|
|
if (rp == proc_ptr || rp == next_ptr) /* current process removed */
|
|
|
|
pick_proc(); /* pick new process to run */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
xpp = &(*xpp)->p_nextready; /* proceed to next */
|
|
|
|
}
|
|
|
|
#else
|
2005-05-20 11:37:43 +02:00
|
|
|
if ( (xp = rdy_head[q]) != NIL_PROC) { /* ready queue is empty */
|
|
|
|
if (xp == rp) { /* check head of queue */
|
|
|
|
rdy_head[q] = xp->p_nextready; /* new head of queue */
|
2005-05-24 16:35:58 +02:00
|
|
|
if (rp == proc_ptr || rp == next_ptr) /* current process removed */
|
2005-05-20 11:37:43 +02:00
|
|
|
pick_proc(); /* pick new process to run */
|
2005-05-24 14:32:34 +02:00
|
|
|
if(rp == rdy_tail[q])
|
|
|
|
rdy_tail[q] = NIL_PROC;
|
|
|
|
}
|
2005-05-20 11:37:43 +02:00
|
|
|
else { /* check body of queue */
|
|
|
|
while (xp->p_nextready != rp) /* stop if process is next */
|
|
|
|
if ( (xp = xp->p_nextready) == NIL_PROC)
|
|
|
|
return;
|
|
|
|
xp->p_nextready = xp->p_nextready->p_nextready;
|
|
|
|
if (rdy_tail[q] == rp) /* possibly update tail */
|
2005-05-24 14:32:34 +02:00
|
|
|
rdy_tail[q] = xp;
|
2005-05-20 11:37:43 +02:00
|
|
|
}
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
2005-05-26 15:17:57 +02:00
|
|
|
#endif
|
2005-05-24 14:32:34 +02:00
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* sched *
|
|
|
|
*===========================================================================*/
|
2005-05-26 15:17:57 +02:00
|
|
|
PRIVATE void sched(queue)
|
|
|
|
int queue;
|
2005-04-21 16:53:53 +02:00
|
|
|
{
|
|
|
|
/* The current process has run too long. If another low priority (user)
|
|
|
|
* process is runnable, put the current process on the end of the user queue,
|
|
|
|
* possibly promoting another user to head of the queue.
|
|
|
|
*/
|
2005-05-26 15:17:57 +02:00
|
|
|
register struct proc **xpp;
|
|
|
|
register struct proc *xp;
|
|
|
|
|
|
|
|
if (rdy_head[queue] == NIL_PROC) return;
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* One or more user processes queued. */
|
2005-05-26 15:17:57 +02:00
|
|
|
#if NEW_SCHED_Q
|
|
|
|
|
2005-05-30 13:05:42 +02:00
|
|
|
xp = rdy_head[queue]; /* save expired process */
|
|
|
|
rdy_head[queue] = xp->p_nextready; /* advance to next process */
|
2005-05-26 15:17:57 +02:00
|
|
|
xpp = &rdy_head[queue]; /* find end of queue */
|
|
|
|
while (*xpp != NIL_PROC) xpp = &(*xpp)->p_nextready;
|
|
|
|
*xpp = xp; /* add expired to end */
|
2005-05-30 13:05:42 +02:00
|
|
|
xp->p_nextready = NIL_PROC; /* mark new end of queue */
|
2005-05-26 15:17:57 +02:00
|
|
|
|
|
|
|
#else
|
|
|
|
rdy_tail[queue]->p_nextready = rdy_head[queue];
|
|
|
|
rdy_tail[queue] = rdy_head[queue];
|
|
|
|
rdy_head[queue] = rdy_head[queue]->p_nextready;
|
|
|
|
rdy_tail[queue]->p_nextready = NIL_PROC;
|
|
|
|
#endif
|
2005-04-21 16:53:53 +02:00
|
|
|
pick_proc();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*==========================================================================*
|
|
|
|
* lock_pick_proc *
|
|
|
|
*==========================================================================*/
|
|
|
|
PUBLIC void lock_pick_proc()
|
|
|
|
{
|
|
|
|
/* Safe gateway to pick_proc() for tasks. */
|
2005-06-01 11:37:52 +02:00
|
|
|
lock(1, "pick_proc");
|
2005-04-21 16:53:53 +02:00
|
|
|
pick_proc();
|
2005-06-01 11:37:52 +02:00
|
|
|
unlock(1);
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|
2005-05-18 12:36:23 +02:00
|
|
|
|
|
|
|
/*==========================================================================*
|
|
|
|
* lock_send *
|
|
|
|
*==========================================================================*/
|
2005-05-24 16:35:58 +02:00
|
|
|
PUBLIC int lock_send(dst, m_ptr)
|
2005-05-24 12:06:17 +02:00
|
|
|
int dst; /* to whom is message being sent? */
|
|
|
|
message *m_ptr; /* pointer to message buffer */
|
2005-05-18 12:36:23 +02:00
|
|
|
{
|
|
|
|
/* Safe gateway to mini_send() for tasks. */
|
|
|
|
int result;
|
2005-06-01 11:37:52 +02:00
|
|
|
lock(2, "send");
|
2005-05-27 14:44:14 +02:00
|
|
|
result = mini_send(proc_ptr, dst, m_ptr, NON_BLOCKING);
|
2005-06-01 11:37:52 +02:00
|
|
|
unlock(2);
|
2005-05-18 12:36:23 +02:00
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
/*==========================================================================*
|
|
|
|
* lock_ready *
|
|
|
|
*==========================================================================*/
|
|
|
|
PUBLIC void lock_ready(rp)
|
|
|
|
struct proc *rp; /* this process is now runnable */
|
|
|
|
{
|
|
|
|
/* Safe gateway to ready() for tasks. */
|
2005-06-01 11:37:52 +02:00
|
|
|
lock(3, "ready");
|
2005-04-21 16:53:53 +02:00
|
|
|
ready(rp);
|
2005-06-01 11:37:52 +02:00
|
|
|
unlock(3);
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*==========================================================================*
|
|
|
|
* lock_unready *
|
|
|
|
*==========================================================================*/
|
|
|
|
PUBLIC void lock_unready(rp)
|
|
|
|
struct proc *rp; /* this process is no longer runnable */
|
|
|
|
{
|
|
|
|
/* Safe gateway to unready() for tasks. */
|
2005-06-01 11:37:52 +02:00
|
|
|
lock(4, "unready");
|
2005-04-21 16:53:53 +02:00
|
|
|
unready(rp);
|
2005-06-01 11:37:52 +02:00
|
|
|
unlock(4);
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*==========================================================================*
|
|
|
|
* lock_sched *
|
|
|
|
*==========================================================================*/
|
2005-05-26 15:17:57 +02:00
|
|
|
PUBLIC void lock_sched(queue)
|
|
|
|
int queue;
|
2005-04-21 16:53:53 +02:00
|
|
|
{
|
|
|
|
/* Safe gateway to sched() for tasks. */
|
2005-06-01 11:37:52 +02:00
|
|
|
lock(5, "sched");
|
2005-05-26 15:17:57 +02:00
|
|
|
sched(queue);
|
2005-06-01 11:37:52 +02:00
|
|
|
unlock(5);
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|