home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************************/
- /* mpbox.c -- MAIL BOX CLUSTER (IMPLEMENTATION) */
- /* Created: 12/12/87 Release: 0.7 Version: 06/27/88 */
- /****************************************************************************
- (c) Copyright 1987, 1988 by Michael Benjamin Parker (USA SS# 557-49-4130)
-
- All Rights Reserved unless specified in the following include files: */
- #include "mptsk.cpy" /*
-
- DO NOT REMOVE OR ALTER THIS NOTICE AND ITS PROVISIONS.
- ****************************************************************************/
- /* OVERVIEW: See mptsk.h */
- /****************************************************************************/
- /****************************************************************************/
- #include "mpbox.h"
- /****************************************************************************/
- /****************************************************************************/
- /****************************************************************************/
- MPBOXID mpbox_init(buf)
- void PTR buf;
- {
- MPBOXID mpbox= (MPBOXID)buf;
-
- mprng_init(str2fld(mpbox,mprng));
- mpsem_init(str2fld(mpbox,mpsem));
- mpbox->msgcnt= 0;
- mprng_init(str2fld(mpbox,msgs));
- return(mpbox);
- }
- /****************************************************************************/
- void PTR mpbox_dinit(mpbox)
- MPBOXID mpbox;
- {
- mprng_dinit(mpbox);
- mpsem_dinit(str2fld(mpbox,mpsem));
- mprng_dinit(str2fld(mpbox,msgs));
- return((void PTR)mpbox);
- }
- /****************************************************************************/
- /****************************************************************************/
- MPRNGID mpbox_xfer(mpbox,next,msg)
- MPBOXID mpbox;
- BOOL next;
- MPRNGID msg;
- {
- mpsem_critsect(str2fld(mpbox,mpsem), {});
- {
- if (next) { /* SEND A MESSAGE */
- if (++(mpbox->msgcnt) > 0) { /* NO RECEIVERS */
- if (!msg) (mpbox->msgcnt)--;
- else mprng_addn(str2fld(mpbox,msgs),msg);
- msg=0;
- } else { /* RECEIVERS WAITING*/
- msg= mprng_subn(str2fld(mpbox,msgs));
- }
- } else { /* RECEIVE A MESSAGE */
- if ((mpbox->msgcnt)-- > 0) { /* MESSAGES WAITING */
- msg= mprng_subp(str2fld(mpbox,msgs));
- } else { /* NO MESSAGES */
- if (!msg) ++(mpbox->msgcnt);
- else mprng_addp(str2fld(mpbox,msgs),msg);
- msg= 0;
- }
- }
- }
- return(msg);
- }
- /****************************************************************************/
- void mpbox_print(MPBOXID mpbox)
- {
- printf("\tmpbox %lX (mpsem %ld, msgcnt %ld, msgs ",
- ptr_2int(mpbox),(INT)(mpbox->mpsem),mpbox->msgcnt);
- mprng_printall(str2fld(mpbox,msgs));
- printf(")");
- }
-
- void mpbox_printall(MPBOXID mpbox)
- {
- MPBOXID cur= mpbox;
- printf("(");
- do {
- printf("\n");
- mpbox_print(cur);
- cur= mprng_next(cur);
- } while (cur!=mpbox);
- printf("\n)");
- }
- /*
- /****************************************************************************/
- MPRNGID mpbox_xfer0(MPBOXID mpbox, MPRNGID msg, BOOL block)
- {
- mpsem_critsect(str2fld(mpbox,mpsem), {
- mptsk_me()->msg= msg;
- do {
- if (msg) { /* SEND A MESSAGE */
- if ((mpbox->msgcnt) >= 0) { /* NO RECEIVERS */
- if (!block) break;
- mprng_addp(str2fld(mpbox,msgs),msg);
- ++(mpbox->msgcnt);
- /* MAYBE RETURN */
- if (msg!=mptsk_me()) {msg= 0; break;}
- } else { /* RECEIVERS WAITING*/
- MPTSKID mptsk=
- mprng_subp(
- str2fld(mpbox->msgs));
- ++(mpbox->msgcnt);
- mptsk->msg= msg;
- msg= 0;
- /* COULD RETURN */
- mptsk_schedule(mptsk);
- mpbox_scheduleme()
- break;
- }
- } else { /* RECEIVE A MESSAGE */
- if ((mpbox->msgcnt) > 0) { /* MESSAGES WAITING */
- msg= mprng_subn(
- str2fld(mpbox,msgs));
- (mpbox->msgcnt)--;
- break;
- } else { /* NO MESSAGES */
- if (!block) break;
- mprng_addn( str2fld(mpbox,msgs),
- mptsk_me());
- (mpbox->msgcnt)--;
- }
- }
- { /* FIND AND SWITCH TO A NEW TASK */
- MPBOXID cursched= headsched;
- MPTSKID mptsk;
- while (!(mptsk= mpbox_recv(cursched,BOOL_FALSE)))
- cursched= mpbox_next(cursched);
- mpthd_switch(str2fld(mptsk,mpthd));
- }
- } while (BOOL_FALSE);
- msg= mptsk_me()->recvmsg; mptsk_me()->recvmsg= 0;
- });
- return(msg);
- }
- */
- /****************************************************************************/
- /****************************************************************************/
- /****************************************************************************/
- /****************************************************************************/
-
-