home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / MAILBOX.ZIP / BYTEPROC.TXT < prev    next >
Encoding:
Text File  |  1988-05-12  |  5.1 KB  |  148 lines

  1. Michael B. Parker, MIT '89
  2.  
  3. MIT Address: (to 5/19)                Home Address: (5/20-6/2)
  4. East Campus - Mun. 303                Lucy V. Parker
  5. 3 Ames Street                    721 E. Walnut Ave.
  6. Cambridge, MA 02139                Orange, CA 92667-6833
  7. (617) 225-6303                    (714) 639-9497
  8.  
  9.  
  10. Jane Tazelaar, Editorial
  11. Byte Magazine
  12.  
  13. One Phoenix Mill Lane
  14. Peterborough, NH 03458
  15. 603-924-9281
  16.  
  17.  
  18. Dear Jane,                    Monday, 16 May 1988
  19. ---------
  20.  
  21. Hope things are going well with you.  I called Friday to update you
  22. on my progress with the multitasking code and left a message with Ken
  23. Sheldon.
  24.  
  25. A few weeks ago you asked me to send you both the final multitasking
  26. package (for BIX distribution) and listing of the mpthd_switch() and
  27. mpthd_xfer() functions (for printing in BYTE).
  28.  
  29. Right now is finals weeks at MIT.  It is the busiest time of the year
  30. for me.  It is impossible for me to complete the entire package now.
  31. However, I have finished the two procedures you requested and sent
  32. them to you (see below).
  33.  
  34. In a few days, I will be returning home to California.  There, I will
  35. finish the package and send it to you by the end of the month.
  36.  
  37. I hope this arrangement will work with your schedule.  If it doesn't,
  38. please give me a call.  Well, either way it works out, I'd enjoy
  39. hearing from you again!
  40.  
  41. Thank you for all your support and encouragement.  It is an honor to
  42. be writing for your magazine.
  43.  
  44.  
  45.         Sincerely,
  46.  
  47.                 Mike Parker
  48.  
  49.  
  50.  
  51. Encl:    Code for mpthd_switch() and mptsk_xfer() functions.  Tab stops
  52. are at every 8th column (standard ASCII).  All lines are less than 80 chars.
  53.  
  54. /****************************************************************************/
  55. /* THE mpthd_switch() FUNCTION    - FOR SWITCHING BETWEEN THREADS OF EXECUTION*/
  56. /****************************************************************************/
  57. MPTHDID    mpthd_switch(newmpthd)
  58.     MPTHDID    newmpthd;
  59. {
  60.     if (newmpthd->stackoverflow)    return((MPTHDID)0);
  61.     if (newmpthd!=mpthd_me()) {
  62.         mpsem_critsect(&(newmpthd->mpsem),{
  63.             if (!setjmp(mpthd_me()->state)) {
  64.                 newmpthd->oldmpthd=    mpthd_me();
  65.                 mpthd_me()=        newmpthd;
  66.                 longjmp(mpthd_me()->state,1);
  67.             }
  68.             newmpthd=    mpthd_me()->oldmpthd;
  69.         });
  70.     }
  71.     return(newmpthd);    /* RETURN OLD THREAD SWITCHED FROM */
  72. }
  73. /****************************************************************************/
  74.  
  75.  
  76.  
  77.  
  78. /****************************************************************************/
  79. /* THE mptsk_xfer() FUNCTION    - FOR TRANSFERING MSGS & CTRL BETWEEN TASKS */
  80. /****************************************************************************/
  81. MPMSGID    mptsk_xfer(MPBOXID mpbox, MPMSGID mpmsg, BOOL block, MPBOXID sched)
  82. {
  83. mpsig_critsect(do {  /* DISABLE INTERRUPTS */
  84.  
  85. /*SEND*/ if (mpmsg) {    /* IF SENDING A MESSAGE */
  86.         MPTSKID    mptsk;
  87.         mptsk=    mpbox_xfer(mpbox,    /* QUEUE MSG <XOR> GET TSK */
  88.                 mptsk_sendside, block?mpmsg:(MPMSGID)0);
  89.         if (mptsk) {    /* A TASK WAS WAITING */
  90.             /* TRANSFER MESSAGE */
  91.              mptsk_mpmsg(mptsk)= mpmsg;    mpmsg= 0;
  92.             /* SCHEDULE BOTH TASKS */
  93.             mpbox_xfer(mptsk_sched(mptsk),mptsk_recvside,mptsk);
  94.             mpbox_xfer(mptsk_mysched(),mptsk_recvside,mptsk_me());
  95.         } else {
  96.             if (block) mpmsg=0;    /* MESSAGE SENT */
  97.             break;            /* RETURN IMMEDIATELY */
  98.         }
  99.  
  100. /*RECV*/} else {    /* IF RECEIVING A MESSAGE */
  101.         mpmsg=    mpbox_xfer(mpbox,    /* GET MSG <XOR> QUEUE TSK */
  102.                 mptsk_recvside, block?mptsk_me():(MPMSGID)0);
  103.         if (mpmsg)    break;    /* MESSAGE RECVED: RET IMMEDIATELY */
  104.         if (!block)    break;    /* DON'T WAIT FOR MSG: RET IMMDLY */
  105.     }
  106. /*SCHD*/{    /* SCHEDULE A NEW TASK TO RUN */
  107.         MPTSKID    mptsk;
  108.         MPBOXID    cursched=    sched;    /* USE USER SCHED LIST */
  109.         /* SEARCH FROM HIGHEST TO LOWEST PRIORITY 'TILL TASK FOUND */
  110.         while (!(mptsk= mpbox_xfer(cursched,mptsk_recvside,
  111.                                 (MPMSGID)0))){
  112.             cursched=    mprng_next(cursched);
  113.             if (cursched==sched)    /* IF END OF USER SCHED LIST*/
  114.                 cursched=  mptsk_topsched(); /* USE SYS LST */
  115.         }
  116.         mptsk_mympmsg()=mpmsg;    /* SAVE MESSAGE BETWEEN SWITCHES */
  117.         mpthd_switch(str2fld(mptsk,mpthd));
  118.         mpmsg=        mptsk_mympmsg();/* RETURN RESULT MESSAGE */
  119.     }
  120. } while (0););
  121. return(mpmsg);
  122. }
  123. /****************************************************************************/
  124.  
  125.  
  126.  
  127. /****************************************************************************/
  128. /*     MACROS FOR TYPICAL USES OF THE mptsk_xfer() FUNCTION            */
  129. /****************************************************************************/
  130. #define    mptsk_send(mpbox,mpmsg)    /* SEND mpmsg TO mpbox */        \
  131.         mptsk_xfer(mpbox,mpmsg,BOOL_TRUE,mptsk_topsched())
  132.  
  133. #define    mptsk_csend(mpbox,mpmsg)/* SEND mpmsg TO mpbox IFF HAS A RECVR */ \
  134.         mptsk_xfer(mpbox,mpmsg,BOOL_FALSE,mptsk_topsched())
  135.  
  136. #define    mptsk_recv(mpbox)    /* RECV A MPMSG FROM mpbox */        \
  137.         mptsk_xfer(mpbox,(MPMSGID)0,BOOL_TRUE,mptsk_topsched())
  138.  
  139. #define    mptsk_crecv(mpbox)      /* RECV A MPMSG FROM mpbox IFF HAS A MSG */ \
  140.         mptsk_xfer(mpbox,(MPMSGID)0,BOOL_FALSE,mptsk_topsched())
  141.  
  142. #define    mptsk_yield()        /* TEMPORARILY YIELD CTRL TO OTHER TASKS */ \
  143.             mptsk_recv(mpbox_mysched())
  144.  
  145. #define    mptsk_yieldto(sched)    /* TEMPORARILY YIELD CTRL TO sched TSK LST */\
  146.             mptsk_xfer(mpbox_mysched(),(MPMSGID)0,BOOL_TRUE,sched)
  147. /****************************************************************************/
  148.