Print this page
remove support for non-ANSI compilation


   3  *
   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 /*

  23  * Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved.
  24  */
  25 
  26 #ifndef _SYNCH_H
  27 #define _SYNCH_H
  28 
  29 /*
  30  * synch.h:
  31  * definitions needed to use the thread synchronization interface
  32  */
  33 
  34 #ifndef _ASM
  35 #include <sys/machlock.h>
  36 #include <sys/time_impl.h>
  37 #include <sys/synch.h>
  38 #endif /* _ASM */
  39 
  40 #ifdef __cplusplus
  41 extern "C" {
  42 #endif


  69 typedef lwp_mutex_t mutex_t;
  70 typedef lwp_cond_t cond_t;
  71 
  72 /*
  73  * Readers/writer locks
  74  *
  75  * NOTE: The layout of this structure should be kept in sync with the layout
  76  * of the correponding structure of pthread_rwlock_t in sys/types.h.
  77  * Also, there is an identical structure for lwp_rwlock_t in <sys/synch.h>.
  78  * Because we have to deal with C++, we cannot redefine this one as that one.
  79  */
  80 typedef struct _rwlock {
  81         int32_t         readers;        /* rwstate word */
  82         uint16_t        type;
  83         uint16_t        magic;
  84         mutex_t         mutex;          /* used with process-shared rwlocks */
  85         cond_t          readercv;       /* used only to indicate ownership */
  86         cond_t          writercv;       /* used only to indicate ownership */
  87 } rwlock_t;
  88 
  89 #ifdef  __STDC__
  90 int     _lwp_mutex_lock(lwp_mutex_t *);
  91 int     _lwp_mutex_unlock(lwp_mutex_t *);
  92 int     _lwp_mutex_trylock(lwp_mutex_t *);
  93 int     _lwp_cond_wait(lwp_cond_t *, lwp_mutex_t *);
  94 int     _lwp_cond_timedwait(lwp_cond_t *, lwp_mutex_t *, timespec_t *);
  95 int     _lwp_cond_reltimedwait(lwp_cond_t *, lwp_mutex_t *, timespec_t *);
  96 int     _lwp_cond_signal(lwp_cond_t *);
  97 int     _lwp_cond_broadcast(lwp_cond_t *);
  98 int     _lwp_sema_init(lwp_sema_t *, int);
  99 int     _lwp_sema_wait(lwp_sema_t *);
 100 int     _lwp_sema_trywait(lwp_sema_t *);
 101 int     _lwp_sema_post(lwp_sema_t *);
 102 int     cond_init(cond_t *, int, void *);
 103 int     cond_destroy(cond_t *);
 104 int     cond_wait(cond_t *, mutex_t *);
 105 int     cond_timedwait(cond_t *, mutex_t *, const timespec_t *);
 106 int     cond_reltimedwait(cond_t *, mutex_t *, const timespec_t *);
 107 int     cond_signal(cond_t *);
 108 int     cond_broadcast(cond_t *);
 109 int     mutex_init(mutex_t *, int, void *);
 110 int     mutex_destroy(mutex_t *);
 111 int     mutex_consistent(mutex_t *);
 112 int     mutex_lock(mutex_t *);
 113 int     mutex_trylock(mutex_t *);
 114 int     mutex_unlock(mutex_t *);
 115 int     rwlock_init(rwlock_t *, int, void *);
 116 int     rwlock_destroy(rwlock_t *);
 117 int     rw_rdlock(rwlock_t *);
 118 int     rw_wrlock(rwlock_t *);
 119 int     rw_unlock(rwlock_t *);
 120 int     rw_tryrdlock(rwlock_t *);
 121 int     rw_trywrlock(rwlock_t *);
 122 int     sema_init(sema_t *, unsigned int, int, void *);
 123 int     sema_destroy(sema_t *);
 124 int     sema_wait(sema_t *);
 125 int     sema_timedwait(sema_t *, const timespec_t *);
 126 int     sema_reltimedwait(sema_t *, const timespec_t *);
 127 int     sema_post(sema_t *);
 128 int     sema_trywait(sema_t *);
 129 
 130 #else   /* __STDC__ */
 131 
 132 int     _lwp_mutex_lock();
 133 int     _lwp_mutex_unlock();
 134 int     _lwp_mutex_trylock();
 135 int     _lwp_cond_wait();
 136 int     _lwp_cond_timedwait();
 137 int     _lwp_cond_reltimedwait();
 138 int     _lwp_cond_signal();
 139 int     _lwp_cond_broadcast();
 140 int     _lwp_sema_init();
 141 int     _lwp_sema_wait();
 142 int     _lwp_sema_trywait();
 143 int     _lwp_sema_post();
 144 int     cond_init();
 145 int     cond_destroy();
 146 int     cond_wait();
 147 int     cond_timedwait();
 148 int     cond_reltimedwait();
 149 int     cond_signal();
 150 int     cond_broadcast();
 151 int     mutex_init();
 152 int     mutex_destroy();
 153 int     mutex_consistent();
 154 int     mutex_lock();
 155 int     mutex_trylock();
 156 int     mutex_unlock();
 157 int     rwlock_init();
 158 int     rwlock_destroy();
 159 int     rw_rdlock();
 160 int     rw_wrlock();
 161 int     rw_unlock();
 162 int     rw_tryrdlock();
 163 int     rw_trywrlock();
 164 int     sema_init();
 165 int     sema_destroy();
 166 int     sema_wait();
 167 int     sema_timedwait();
 168 int     sema_reltimedwait();
 169 int     sema_post();
 170 int     sema_trywait();
 171 
 172 #endif  /* __STDC__ */
 173 
 174 #endif /* _ASM */
 175 
 176 /* "Magic numbers" tagging synchronization object types */
 177 #define MUTEX_MAGIC     _MUTEX_MAGIC
 178 #define SEMA_MAGIC      _SEMA_MAGIC
 179 #define COND_MAGIC      _COND_MAGIC
 180 #define RWL_MAGIC       _RWL_MAGIC
 181 
 182 /*
 183  * POSIX.1c Note:
 184  * DEFAULTMUTEX is defined same as PTHREAD_MUTEX_INITIALIZER in <pthread.h>.
 185  * DEFAULTCV is defined same as PTHREAD_COND_INITIALIZER in <pthread.h>.
 186  * DEFAULTRWLOCK is defined same as PTHREAD_RWLOCK_INITIALIZER in <pthread.h>.
 187  * Any changes to these macros should be reflected in <pthread.h>
 188  */
 189 #define DEFAULTMUTEX    \
 190         {{0, 0, 0, {USYNC_THREAD}, MUTEX_MAGIC}, \
 191         {{{0, 0, 0, 0, 0, 0, 0, 0}}}, 0}
 192 #define SHAREDMUTEX     \
 193         {{0, 0, 0, {USYNC_PROCESS}, MUTEX_MAGIC}, \


 221 #define RW_READ_HELD(x)         _rw_read_held(x)
 222 #define RW_WRITE_HELD(x)        _rw_write_held(x)
 223 #define RW_LOCK_HELD(x)         (RW_READ_HELD(x) || RW_WRITE_HELD(x))
 224 #define MUTEX_HELD(x)           _mutex_held(x)
 225 
 226 /*
 227  * The following definitions are for assertions which can be checked
 228  * statically by tools like lock_lint.  You can also define your own
 229  * run-time test for each.  If you don't, we define them to 1 so that
 230  * such assertions simply pass.
 231  */
 232 #ifndef NO_LOCKS_HELD
 233 #define NO_LOCKS_HELD   1
 234 #endif
 235 #ifndef NO_COMPETING_THREADS
 236 #define NO_COMPETING_THREADS    1
 237 #endif
 238 
 239 #ifndef _ASM
 240 
 241 #ifdef  __STDC__
 242 
 243 /*
 244  * The *_held() functions apply equally well to Solaris threads
 245  * and to Posix threads synchronization objects, but the formal
 246  * type declarations are different, so we just declare the argument
 247  * to each *_held() function to be a void *, expecting that they will
 248  * be called with the proper type of argument in each case.
 249  */
 250 int _sema_held(void *);                 /* sema_t or sem_t */
 251 int _rw_read_held(void *);              /* rwlock_t or pthread_rwlock_t */
 252 int _rw_write_held(void *);             /* rwlock_t or pthread_rwlock_t */
 253 int _mutex_held(void *);                /* mutex_t or pthread_mutex_t */
 254 
 255 #else   /* __STDC__ */
 256 
 257 int _sema_held();
 258 int _rw_read_held();
 259 int _rw_write_held();
 260 int _mutex_held();
 261 
 262 #endif  /* __STDC__ */
 263 
 264 /* Pause API */
 265 #ifdef  __STDC__
 266 void smt_pause(void);
 267 #else   /* __STDC__ */
 268 void smt_pause();
 269 #endif  /* __STDC__ */
 270 
 271 #endif /* _ASM */
 272 
 273 #ifdef  __cplusplus
 274 }
 275 #endif
 276 
 277 #endif  /* _SYNCH_H */


   3  *
   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 /*
  23  * Copyright 2014 Garrett D'Amore <garrett@damore.org>
  24  * Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved.
  25  */
  26 
  27 #ifndef _SYNCH_H
  28 #define _SYNCH_H
  29 
  30 /*
  31  * synch.h:
  32  * definitions needed to use the thread synchronization interface
  33  */
  34 
  35 #ifndef _ASM
  36 #include <sys/machlock.h>
  37 #include <sys/time_impl.h>
  38 #include <sys/synch.h>
  39 #endif /* _ASM */
  40 
  41 #ifdef __cplusplus
  42 extern "C" {
  43 #endif


  70 typedef lwp_mutex_t mutex_t;
  71 typedef lwp_cond_t cond_t;
  72 
  73 /*
  74  * Readers/writer locks
  75  *
  76  * NOTE: The layout of this structure should be kept in sync with the layout
  77  * of the correponding structure of pthread_rwlock_t in sys/types.h.
  78  * Also, there is an identical structure for lwp_rwlock_t in <sys/synch.h>.
  79  * Because we have to deal with C++, we cannot redefine this one as that one.
  80  */
  81 typedef struct _rwlock {
  82         int32_t         readers;        /* rwstate word */
  83         uint16_t        type;
  84         uint16_t        magic;
  85         mutex_t         mutex;          /* used with process-shared rwlocks */
  86         cond_t          readercv;       /* used only to indicate ownership */
  87         cond_t          writercv;       /* used only to indicate ownership */
  88 } rwlock_t;
  89 

  90 int     _lwp_mutex_lock(lwp_mutex_t *);
  91 int     _lwp_mutex_unlock(lwp_mutex_t *);
  92 int     _lwp_mutex_trylock(lwp_mutex_t *);
  93 int     _lwp_cond_wait(lwp_cond_t *, lwp_mutex_t *);
  94 int     _lwp_cond_timedwait(lwp_cond_t *, lwp_mutex_t *, timespec_t *);
  95 int     _lwp_cond_reltimedwait(lwp_cond_t *, lwp_mutex_t *, timespec_t *);
  96 int     _lwp_cond_signal(lwp_cond_t *);
  97 int     _lwp_cond_broadcast(lwp_cond_t *);
  98 int     _lwp_sema_init(lwp_sema_t *, int);
  99 int     _lwp_sema_wait(lwp_sema_t *);
 100 int     _lwp_sema_trywait(lwp_sema_t *);
 101 int     _lwp_sema_post(lwp_sema_t *);
 102 int     cond_init(cond_t *, int, void *);
 103 int     cond_destroy(cond_t *);
 104 int     cond_wait(cond_t *, mutex_t *);
 105 int     cond_timedwait(cond_t *, mutex_t *, const timespec_t *);
 106 int     cond_reltimedwait(cond_t *, mutex_t *, const timespec_t *);
 107 int     cond_signal(cond_t *);
 108 int     cond_broadcast(cond_t *);
 109 int     mutex_init(mutex_t *, int, void *);
 110 int     mutex_destroy(mutex_t *);
 111 int     mutex_consistent(mutex_t *);
 112 int     mutex_lock(mutex_t *);
 113 int     mutex_trylock(mutex_t *);
 114 int     mutex_unlock(mutex_t *);
 115 int     rwlock_init(rwlock_t *, int, void *);
 116 int     rwlock_destroy(rwlock_t *);
 117 int     rw_rdlock(rwlock_t *);
 118 int     rw_wrlock(rwlock_t *);
 119 int     rw_unlock(rwlock_t *);
 120 int     rw_tryrdlock(rwlock_t *);
 121 int     rw_trywrlock(rwlock_t *);
 122 int     sema_init(sema_t *, unsigned int, int, void *);
 123 int     sema_destroy(sema_t *);
 124 int     sema_wait(sema_t *);
 125 int     sema_timedwait(sema_t *, const timespec_t *);
 126 int     sema_reltimedwait(sema_t *, const timespec_t *);
 127 int     sema_post(sema_t *);
 128 int     sema_trywait(sema_t *);
 129 












































 130 #endif /* _ASM */
 131 
 132 /* "Magic numbers" tagging synchronization object types */
 133 #define MUTEX_MAGIC     _MUTEX_MAGIC
 134 #define SEMA_MAGIC      _SEMA_MAGIC
 135 #define COND_MAGIC      _COND_MAGIC
 136 #define RWL_MAGIC       _RWL_MAGIC
 137 
 138 /*
 139  * POSIX.1c Note:
 140  * DEFAULTMUTEX is defined same as PTHREAD_MUTEX_INITIALIZER in <pthread.h>.
 141  * DEFAULTCV is defined same as PTHREAD_COND_INITIALIZER in <pthread.h>.
 142  * DEFAULTRWLOCK is defined same as PTHREAD_RWLOCK_INITIALIZER in <pthread.h>.
 143  * Any changes to these macros should be reflected in <pthread.h>
 144  */
 145 #define DEFAULTMUTEX    \
 146         {{0, 0, 0, {USYNC_THREAD}, MUTEX_MAGIC}, \
 147         {{{0, 0, 0, 0, 0, 0, 0, 0}}}, 0}
 148 #define SHAREDMUTEX     \
 149         {{0, 0, 0, {USYNC_PROCESS}, MUTEX_MAGIC}, \


 177 #define RW_READ_HELD(x)         _rw_read_held(x)
 178 #define RW_WRITE_HELD(x)        _rw_write_held(x)
 179 #define RW_LOCK_HELD(x)         (RW_READ_HELD(x) || RW_WRITE_HELD(x))
 180 #define MUTEX_HELD(x)           _mutex_held(x)
 181 
 182 /*
 183  * The following definitions are for assertions which can be checked
 184  * statically by tools like lock_lint.  You can also define your own
 185  * run-time test for each.  If you don't, we define them to 1 so that
 186  * such assertions simply pass.
 187  */
 188 #ifndef NO_LOCKS_HELD
 189 #define NO_LOCKS_HELD   1
 190 #endif
 191 #ifndef NO_COMPETING_THREADS
 192 #define NO_COMPETING_THREADS    1
 193 #endif
 194 
 195 #ifndef _ASM
 196 


 197 /*
 198  * The *_held() functions apply equally well to Solaris threads
 199  * and to Posix threads synchronization objects, but the formal
 200  * type declarations are different, so we just declare the argument
 201  * to each *_held() function to be a void *, expecting that they will
 202  * be called with the proper type of argument in each case.
 203  */
 204 int _sema_held(void *);                 /* sema_t or sem_t */
 205 int _rw_read_held(void *);              /* rwlock_t or pthread_rwlock_t */
 206 int _rw_write_held(void *);             /* rwlock_t or pthread_rwlock_t */
 207 int _mutex_held(void *);                /* mutex_t or pthread_mutex_t */
 208 









 209 /* Pause API */

 210 void smt_pause(void);



 211 
 212 #endif /* _ASM */
 213 
 214 #ifdef  __cplusplus
 215 }
 216 #endif
 217 
 218 #endif  /* _SYNCH_H */