home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_08_04 / 8n04115a < prev    next >
Text File  |  1990-03-20  |  2KB  |  88 lines

  1. ***************
  2. ** Listing 2 **
  3. ***************
  4.  
  5. /*
  6.  
  7.   fork_driver(routine, param)
  8.   void (*routine)();
  9.   unsigned long param;
  10.  
  11.   This routine places the passed routine onto the fork
  12.   queue.  The driver is allowed to pass up to four bytes
  13.   to the target routine.
  14.  
  15.   The driver's action is considered complete, and it will
  16.   not be reentered until another interrupt occurs.
  17.  
  18. */
  19.  
  20. void fork_driver(routine, param)
  21. void (*routine)();
  22. unsigned long param;
  23.   {
  24.   FORK_PARAM *current_fork;
  25.   DSS *current_dcb;
  26.   unsigned char current_name[NAME_SIZE + 1];
  27.  
  28.   /* Get address of driver's TSS. */
  29.   current_dcb = get_tss(NULL);
  30.  
  31.   /* Make sure we are allowed to fork this device again. */
  32.   if (current_dcb -> current_fork_count >= current_dcb ->
  33.       max_fork_count && current_dcb -> max_fork_count)
  34.     {
  35.     /* Can't fork another entry on this device.  Throw
  36.        away interrupt.  (Serious Problem Here!)        */
  37.     if (in_executive || fork_in_process)
  38.       resume_last();
  39.     else
  40.       resume(scheduler_task);
  41.     return;
  42.     }
  43.  
  44.   /* Get next entry. */
  45.   if (!(current_fork = fork_free))
  46.     {
  47.     /* Out of fork space. Throw away interrupt.
  48.        (Serious Problem Here!)             */
  49.     if (in_executive || fork_in_process)
  50.       resume_last();
  51.     else
  52.       resume(scheduler_task);
  53.     return;
  54.     }
  55.  
  56.   /* Get the next free fork queue entry link */
  57.   fork_free = fork_free -> link;
  58.  
  59.   /* Fill the entry with the address of the driver's TSS,
  60.      the interrupt-enabled routine address, the passed
  61.      parameter, and clear the link.            */
  62.  
  63.   current_fork -> tcb = current_dcb;
  64.   current_fork -> routine = routine;
  65.   current_fork -> param1 = param;
  66.   current_fork -> link = NULL;
  67.  
  68.   /* Add one to the count of fork entries for this
  69.      device.                       */
  70.  
  71.   ++current_dcb -> current_fork_count;
  72.  
  73.   /* Link it onto the end of the fork queue */
  74.   if (fork_queue)
  75.     fork_queue_tail = fork_queue_tail -> link = current_fork;
  76.   else
  77.     fork_queue = fork_queue_tail = current_fork;
  78.  
  79.   /* If in a system service call, or currently executing
  80.      the fork, resume what we were last doing. Otherwise
  81.      else start up the fork queue.            */
  82.  
  83.   if (in_executive || fork_in_process)
  84.     resume_last();
  85.   else
  86.     resume(fork_queue_task);
  87.   }
  88.