4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  */
  25 
  26 #ifndef _SYS_MACHLOCK_H
  27 #define _SYS_MACHLOCK_H
  28 
  29 #pragma ident   "%Z%%M% %I%     %E% SMI"
  30 
  31 #ifndef _ASM
  32 #include <sys/types.h>
  33 #include <sys/time.h>
  34 #endif /* _ASM */
  35 
  36 #ifdef  __cplusplus
  37 extern "C" {
  38 #endif
  39 
  40 #ifndef _ASM
  41 
  42 #ifdef _KERNEL
  43 
  44 extern void     lock_set(lock_t *lp);
  45 extern int      lock_try(lock_t *lp);
  46 extern int      lock_spin_try(lock_t *lp);
  47 extern int      ulock_try(lock_t *lp);
  48 extern void     lock_clear(lock_t *lp);
  49 extern void     ulock_clear(lock_t *lp);
  50 extern void     lock_set_spl(lock_t *lp, int new_pil, ushort_t *old_pil);
 
  59 
  60 typedef lock_t  disp_lock_t;            /* dispatcher lock type */
  61 
  62 /*
  63  * SPIN_LOCK() macro indicates whether lock is implemented as a spin lock or
  64  * an adaptive mutex, depending on what interrupt levels use it.
  65  */
  66 #define SPIN_LOCK(pl)   ((pl) > ipltospl(LOCK_LEVEL))
  67 
  68 /*
  69  * Macro to control loops which spin on a lock and then check state
  70  * periodically.  Its passed an integer, and returns a boolean value
  71  * that if true indicates its a good time to get the scheduler lock and
  72  * check the state of the current owner of the lock.
  73  */
  74 #define LOCK_SAMPLE_INTERVAL(i) (((i) & 0xff) == 0)
  75 
  76 /*
  77  * Externs for CLOCK_LOCK and clock resolution
  78  */
  79 extern volatile int hres_lock;
  80 extern hrtime_t hrtime_base;
  81 extern int clock_res;
  82 
  83 #endif  /* _ASM */
  84 
  85 /*
  86  * The definitions of the symbolic interrupt levels:
  87  *
  88  *   CLOCK_LEVEL =>  The level at which one must be to block the clock.
  89  *
  90  *   LOCK_LEVEL  =>  The highest level at which one may block (and thus the
  91  *                   highest level at which one may acquire adaptive locks)
  92  *                   Also the highest level at which one may be preempted.
  93  *
  94  *   DISP_LEVEL  =>  The level at which one must be to perform dispatcher
  95  *                   operations.
  96  *
  97  * The constraints on the platform:
  98  *
  99  *  - CLOCK_LEVEL must be less than or equal to LOCK_LEVEL
  
 | 
 
 
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  * Copyright 2016 Joyent, Inc.
  25  */
  26 
  27 #ifndef _SYS_MACHLOCK_H
  28 #define _SYS_MACHLOCK_H
  29 
  30 #ifndef _ASM
  31 #include <sys/types.h>
  32 #include <sys/time.h>
  33 #endif /* _ASM */
  34 
  35 #ifdef  __cplusplus
  36 extern "C" {
  37 #endif
  38 
  39 #ifndef _ASM
  40 
  41 #ifdef _KERNEL
  42 
  43 extern void     lock_set(lock_t *lp);
  44 extern int      lock_try(lock_t *lp);
  45 extern int      lock_spin_try(lock_t *lp);
  46 extern int      ulock_try(lock_t *lp);
  47 extern void     lock_clear(lock_t *lp);
  48 extern void     ulock_clear(lock_t *lp);
  49 extern void     lock_set_spl(lock_t *lp, int new_pil, ushort_t *old_pil);
 
  58 
  59 typedef lock_t  disp_lock_t;            /* dispatcher lock type */
  60 
  61 /*
  62  * SPIN_LOCK() macro indicates whether lock is implemented as a spin lock or
  63  * an adaptive mutex, depending on what interrupt levels use it.
  64  */
  65 #define SPIN_LOCK(pl)   ((pl) > ipltospl(LOCK_LEVEL))
  66 
  67 /*
  68  * Macro to control loops which spin on a lock and then check state
  69  * periodically.  Its passed an integer, and returns a boolean value
  70  * that if true indicates its a good time to get the scheduler lock and
  71  * check the state of the current owner of the lock.
  72  */
  73 #define LOCK_SAMPLE_INTERVAL(i) (((i) & 0xff) == 0)
  74 
  75 /*
  76  * Externs for CLOCK_LOCK and clock resolution
  77  */
  78 extern volatile uint32_t hres_lock;
  79 extern hrtime_t hrtime_base;
  80 extern int clock_res;
  81 
  82 #endif  /* _ASM */
  83 
  84 /*
  85  * The definitions of the symbolic interrupt levels:
  86  *
  87  *   CLOCK_LEVEL =>  The level at which one must be to block the clock.
  88  *
  89  *   LOCK_LEVEL  =>  The highest level at which one may block (and thus the
  90  *                   highest level at which one may acquire adaptive locks)
  91  *                   Also the highest level at which one may be preempted.
  92  *
  93  *   DISP_LEVEL  =>  The level at which one must be to perform dispatcher
  94  *                   operations.
  95  *
  96  * The constraints on the platform:
  97  *
  98  *  - CLOCK_LEVEL must be less than or equal to LOCK_LEVEL
  
 |