|
|
1.1 root 1: #ifndef _XPSEM_H_
2: #define _XPSEM_H_
3:
4: /*
5: * $Id: xpsem.h,v 1.9 2005/09/12 23:24:38 deuce Exp $
6: *
7: * semaphore.h: POSIX 1003.1b semaphores
8: */
9:
10: /*-
11: * Copyright (c) 1996, 1997
12: * HD Associates, Inc. All rights reserved.
13: *
14: * Redistribution and use in source and binary forms, with or without
15: * modification, are permitted provided that the following conditions
16: * are met:
17: * 1. Redistributions of source code must retain the above copyright
18: * notice, this list of conditions and the following disclaimer.
19: * 2. Redistributions in binary form must reproduce the above copyright
20: * notice, this list of conditions and the following disclaimer in the
21: * documentation and/or other materials provided with the distribution.
22: * 3. All advertising materials mentioning features or use of this software
23: * must display the following acknowledgement:
24: * This product includes software developed by HD Associates, Inc
25: * 4. Neither the name of the author nor the names of any co-contributors
26: * may be used to endorse or promote products derived from this software
27: * without specific prior written permission.
28: *
29: * THIS SOFTWARE IS PROVIDED BY HD ASSOCIATES AND CONTRIBUTORS ``AS IS'' AND
30: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32: * ARE DISCLAIMED. IN NO EVENT SHALL HD ASSOCIATES OR CONTRIBUTORS BE LIABLE
33: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39: * SUCH DAMAGE.
40: *
41: * $FreeBSD: src/sys/posix4/semaphore.h,v 1.6 2000/01/20 07:55:42 jasone Exp $
42: */
43:
44: #include <limits.h>
45:
46: #include <sys/types.h>
47: #include <fcntl.h>
48: #include <pthread.h>
49:
50: /* Opaque type definition. */
51: struct xp_sem;
52: typedef struct xp_sem *xp_sem_t;
53:
54: #define XP_SEM_FAILED ((xp_sem_t *)0)
55: #define XP_SEM_VALUE_MAX UINT_MAX
56:
57: #if defined(__solaris__)
58: typedef unsigned int u_int32_t;
59: #endif
60:
61: #if defined(__cplusplus)
62: extern "C" {
63: #endif
64: int xp_sem_init (xp_sem_t *, int, unsigned int);
65: int xp_sem_destroy (xp_sem_t *);
66: xp_sem_t *xp_sem_open (const char *, int, ...);
67: int xp_sem_close (xp_sem_t *);
68: int xp_sem_unlink (const char *);
69: int xp_sem_wait (xp_sem_t *);
70: int xp_sem_trywait (xp_sem_t *);
71: int xp_sem_post (xp_sem_t *);
72: int xp_sem_getvalue (xp_sem_t *, int *);
73: int xp_sem_setvalue (xp_sem_t *, int);
74: int xp_sem_timedwait (xp_sem_t *sem, const struct timespec *abs_timeout);
75: #if defined(__cplusplus)
76: }
77: #endif
78:
79: /*
80: * $Id: xpsem.h,v 1.9 2005/09/12 23:24:38 deuce Exp $
81: */
82:
83: /* Begin thread_private.h kluge */
84: /*
85: * These come out of (or should go into) thread_private.h - rather than have
86: * to copy (or symlink) the files from the source tree these definitions are
87: * inlined here. Obviously these go away when this module is part of libc.
88: */
89:
90: struct xp_sem {
91: #define XP_SEM_MAGIC ((u_int32_t) 0x09fa4012)
92: u_int32_t magic;
93: pthread_mutex_t lock;
94: pthread_cond_t gtzero;
95: u_int32_t count;
96: u_int32_t nwaiters;
97: };
98:
99: extern pthread_once_t _thread_init_once;
100: extern int _threads_initialized;
101: extern void _thread_init (void);
102: #define THREAD_INIT() \
103: (void) pthread_once(&_thread_init_once, _thread_init)
104: #define THREAD_SAFE() \
105: (_threads_initialized != 0)
106:
107: #define _SEM_CHECK_VALIDITY(sem) \
108: if (sem==NULL || (*(sem))->magic != XP_SEM_MAGIC) { \
109: errno = EINVAL; \
110: retval = -1; \
111: goto RETURN; \
112: }
113:
114: struct pthread_rwlockattr {
115: int pshared;
116: };
117:
118: /* End thread_private.h kluge */
119:
120: #endif /* _XPSEM_H_ */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.