|
|
1.1 root 1: #ifndef _XPSEM_H_
2: #define _XPSEM_H_
3:
4: /*
5: * $Id: xpsem.h,v 1.5 2004/11/22 20:57:46 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 SEM_FAILED ((xp_sem_t *)0)
55: #define SEM_VALUE_MAX UINT_MAX
56:
57: #ifdef __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 *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_timedwait (xp_sem_t *sem, const struct timespec *abs_timeout);
74: #if defined(__cplusplus)
75: }
76: #endif
77:
78: /*
79: * $Id: xpsem.h,v 1.5 2004/11/22 20:57:46 deuce Exp $
80: */
81:
82: /* Begin thread_private.h kluge */
83: /*
84: * These come out of (or should go into) thread_private.h - rather than have
85: * to copy (or symlink) the files from the source tree these definitions are
86: * inlined here. Obviously these go away when this module is part of libc.
87: */
88:
89: struct xp_sem {
90: #define SEM_MAGIC ((u_int32_t) 0x09fa4012)
91: u_int32_t magic;
92: pthread_mutex_t lock;
93: pthread_cond_t gtzero;
94: u_int32_t count;
95: u_int32_t nwaiters;
96: };
97:
98: extern pthread_once_t _thread_init_once;
99: extern int _threads_initialized;
100: extern void _thread_init (void);
101: #define THREAD_INIT() \
102: (void) pthread_once(&_thread_init_once, _thread_init)
103: #define THREAD_SAFE() \
104: (_threads_initialized != 0)
105:
106: #define _SEM_CHECK_VALIDITY(sem) \
107: if (sem==NULL || (*(sem))->magic != SEM_MAGIC) { \
108: errno = EINVAL; \
109: retval = -1; \
110: goto RETURN; \
111: }
112:
113: struct pthread_rwlockattr {
114: int pshared;
115: };
116:
117: /* End thread_private.h kluge */
118:
119: #endif /* _XPSEM_H_ */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.