Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ wakeup(K) — System V/386 Software Development System 3.2.2b

Media Vault

Software Library

Restoration Projects

Artifacts Sought



     WAKEUP(K)                 UNIX System V                 WAKEUP(K)



     Name
          wakeup - wakes up a sleeping process

     Syntax
          int
          wakeup(address)
          caddr_t address;

     Description
          wakeup causes all processes which are sleeping at a wait
          channel equal to address to be taken off the sleep queue and
          placed on the run queue.  When a process is awakened, the
          call to sleep(K) returns a value of zero.  It is still
          necessary to see whether the event being slept on has
          occurred, as there is no guarantee that the resource being
          waited for is actually free.

     Parameters
          address should be the same value used in a previous
          invocation of the sleep routine.  Since this number is not
          guaranteed to be unique and multiple processes may have have
          been awakened by any single invocation of the wakeup routine
          it is not guaranteed that the event being waited for has in
          fact occurred.

     Return Value
          wakeup does not return a useful value.

     Example
          The following code fragments demonstrate one possible use of
          sleep and wakeup.  In this instance the driver xxread
          routine allocates a temporary storage area, queues an I/O
          transfer, and then puts the process to sleep.  The xxintr
          routine is called when the device is ready to do the
          transfer.  After the transfer is complete the xxintr routine
          executes a wakeup.

          /*
           * declare variable which is used for address
           */
          char my_address;

          /*
           * First the xxread().
           */
          xxread(dev)
          int dev;
          {
          #define MYPRI   PZERO+15  /* PZERO is defined in sys/param.h */

                  /* allocate temporary storage */
                  .
                  .
                  .
                  /* set flag to indicate I/O transfer is in progress */
                  .
                  /* start I/O transfer */
                  .
                  .
                  /*
                   * flag only indicates transfer is done if wakeup() has
                   * been called by my xxintr().
                   */
                  while (/* flag indicates transfer is not done */) {

                  /*
                   * OR MYPRI with PCATCH to clean things up instead
                   * of returning directly to user space with an error.
                   * See longjmp(K) for more information.
                  /*
                  if (sleep(&my_address, MYPRI | PCATCH) == 1) {

                          /* stop I/O transfer       */
                          /* clear I/O transfer flag */
                          /* free temporary memory   */
                          u.u_error = EINTR;
                          return(-1);
                          }
                  } /* only get past here when transfer is done */
                  /* copy data from temporary storage to user address */
                  .
                  /* free temporary memory */
                  return( /* number of bytes transferred */ );
          }

          /*
           * now for the xxintr()
           */
          xxintr(interrupt)
          int interrupt;
          {
                  /* check that transfer is complete */
                  .
                  .
                  /* set flag to indicate transfer is complete */
                  .
                  /* wakeup sleeping process */
                  wakeup(&my_address);
          }

          /*
           * Note that the preceding example does not take into
           * account the possibility that multiple user processes
           * may have queued requests for a single device.
           */

     See Also
          sleep(K), timeout(K), delay(K)

                                                      (printed 7/6/89)



Typewritten Software • bear@typewritten.org • Edmonds, WA 98026