The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/sqt/sema.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /* 
    2  * Mach Operating System
    3  * Copyright (c) 1993,1992,1991 Carnegie Mellon University
    4  * Copyright (c) 1992,1991 Sequent Computer Systems
    5  * All Rights Reserved.
    6  * 
    7  * Permission to use, copy, modify and distribute this software and its
    8  * documentation is hereby granted, provided that both the copyright
    9  * notice and this permission notice appear in all copies of the
   10  * software, derivative works or modified versions, and any portions
   11  * thereof, and that both notices appear in supporting documentation.
   12  * 
   13  * CARNEGIE MELLON AND SEQUENT COMPUTER SYSTEMS ALLOW FREE USE OF
   14  * THIS SOFTWARE IN ITS "AS IS" CONDITION.  CARNEGIE MELLON AND
   15  * SEQUENT COMPUTER SYSTEMS DISCLAIM ANY LIABILITY OF ANY KIND FOR
   16  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
   17  * 
   18  * Carnegie Mellon requests users of this software to return to
   19  * 
   20  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
   21  *  School of Computer Science
   22  *  Carnegie Mellon University
   23  *  Pittsburgh PA 15213-3890
   24  * 
   25  * any improvements or extensions that they make and grant Carnegie Mellon 
   26  * the rights to redistribute these changes.
   27  */
   28 
   29 /*
   30  * HISTORY
   31  * $Log:        sema.c,v $
   32  * Revision 2.5  93/11/17  18:46:37  dbg
   33  *      Removed lint.
   34  *      [93/06/17            dbg]
   35  * 
   36  * Revision 2.4  93/01/14  17:56:09  danner
   37  *      Fix calls to sched_prim functions.
   38  *      [92/12/31            dbg]
   39  * 
   40  * Revision 2.3  91/07/31  18:03:32  dbg
   41  *      Changed copyright.
   42  *      [91/07/31            dbg]
   43  * 
   44  * Revision 2.2  91/05/08  12:58:36  dbg
   45  *      Created.
   46  *      [91/04/26  14:56:44  dbg]
   47  * 
   48  */
   49 
   50 /*
   51  * Dynix semaphores.
   52  */
   53 #include <kern/sched_prim.h>
   54 
   55 #include <sqt/mutex.h>
   56 
   57 #define sema_lock(sema)         (bit_lock(0, &(sema)->lock))
   58 
   59 #define sema_unlock(sema)       (bit_unlock(0, &(sema)->lock))
   60 
   61 /*ARGSUSED*/
   62 init_sema(sema, val, flags, gate)
   63         register sema_t *sema;
   64         int             val;
   65 {
   66         sema->lock = 0;
   67         sema->waiting = 0;
   68         sema->count = val;
   69 }
   70 
   71 /*ARGUSED*/
   72 p_sema(sema, pri)
   73         register sema_t *sema;
   74         int     pri;
   75 {
   76         sema_lock(sema);
   77 
   78         if (--sema->count >= 0) {
   79             sema_unlock(sema);
   80             return;
   81         }
   82         sema->waiting = TRUE;
   83         assert_wait(sema, FALSE);
   84         sema_unlock(sema);
   85         thread_block(CONTINUE_NULL);
   86 }
   87 
   88 p_sema_v_lock(sema, pri, l, spl)
   89         register sema_t *sema;
   90         int             pri;
   91         simple_lock_t   l;
   92         int             spl;
   93 {
   94         sema_lock(sema);
   95 
   96         if (--sema->count >= 0) {
   97             sema_unlock(sema);
   98             v_lock(l,spl);
   99             return;
  100         }
  101         sema->waiting = TRUE;
  102         assert_wait(sema, FALSE);
  103         sema_unlock(sema);
  104         v_lock(l,spl);
  105         thread_block(CONTINUE_NULL);
  106 }
  107 
  108 cp_sema(sema)
  109         register sema_t *sema;
  110 {
  111         sema_lock(sema);
  112         if (--sema->count >= 0) {
  113             sema_unlock(sema);
  114             return (TRUE);
  115         }
  116         sema_unlock(sema);
  117         return (FALSE);
  118 }
  119 
  120 v_sema(sema)
  121         register sema_t *sema;
  122 {
  123         sema_lock(sema);
  124         if (++sema->count >= 0) {
  125             if (sema->waiting) {
  126                 thread_wakeup(sema);
  127                 sema->waiting = 0;
  128             }
  129         }
  130         sema_unlock(sema);
  131 }
  132 
  133 cv_sema(sema)
  134         register sema_t *sema;
  135 {
  136         v_sema(sema);
  137 }
  138 
  139 vall_sema(sema)
  140         register sema_t *sema;
  141 {
  142         sema_lock(sema);
  143         while (++sema->count <= 0) {
  144             if (sema->waiting) {
  145                 thread_wakeup(sema);
  146                 sema->waiting = 0;
  147             }
  148         }
  149         sema_unlock(sema);
  150 }
  151 

Cache object: fddf2b42017c83613ce5735dd301b481


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.