xref: /freebsd/include/semaphore.h (revision 9b0f1823b59d52c97a3ee8ee92d81d9d084ca52c)
19b0f1823SDavid Xu /*
29b0f1823SDavid Xu  * Copyright (c) 2010 David Xu <davidxu@freebsd.org>
39b0f1823SDavid Xu  *
49b0f1823SDavid Xu  * All rights reserved.
59b0f1823SDavid Xu  *
69b0f1823SDavid Xu  * Redistribution and use in source and binary forms, with or without
79b0f1823SDavid Xu  * modification, are permitted provided that the following conditions
89b0f1823SDavid Xu  * are met:
99b0f1823SDavid Xu  * 1. Redistributions of source code must retain the above copyright
109b0f1823SDavid Xu  *    notice unmodified, this list of conditions, and the following
119b0f1823SDavid Xu  *    disclaimer.
129b0f1823SDavid Xu  * 2. Redistributions in binary form must reproduce the above copyright
139b0f1823SDavid Xu  *    notice, this list of conditions and the following disclaimer in the
149b0f1823SDavid Xu  *    documentation and/or other materials provided with the distribution.
159b0f1823SDavid Xu  *
169b0f1823SDavid Xu  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
179b0f1823SDavid Xu  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
189b0f1823SDavid Xu  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
199b0f1823SDavid Xu  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
209b0f1823SDavid Xu  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
219b0f1823SDavid Xu  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
229b0f1823SDavid Xu  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
239b0f1823SDavid Xu  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
249b0f1823SDavid Xu  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
259b0f1823SDavid Xu  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
269b0f1823SDavid Xu  *
279b0f1823SDavid Xu  * $FreeBSD$
289b0f1823SDavid Xu  */
299b0f1823SDavid Xu 
309b0f1823SDavid Xu /* semaphore.h: POSIX 1003.1b semaphores */
319b0f1823SDavid Xu 
329b0f1823SDavid Xu #ifndef _SEMAPHORE_H_
339b0f1823SDavid Xu #define _SEMAPHORE_H_
349b0f1823SDavid Xu 
359b0f1823SDavid Xu #include <sys/cdefs.h>
369b0f1823SDavid Xu #include <sys/_types.h>
379b0f1823SDavid Xu #include <sys/_umtx.h>
389b0f1823SDavid Xu 
399b0f1823SDavid Xu struct _sem {
409b0f1823SDavid Xu 	__uint32_t	_magic;
419b0f1823SDavid Xu 	struct _usem	_kern;
429b0f1823SDavid Xu };
439b0f1823SDavid Xu 
449b0f1823SDavid Xu typedef	struct _sem	sem_t;
459b0f1823SDavid Xu 
469b0f1823SDavid Xu #define	SEM_FAILED	((sem_t *)0)
479b0f1823SDavid Xu #define	SEM_VALUE_MAX	__INT_MAX
489b0f1823SDavid Xu 
499b0f1823SDavid Xu struct timespec;
509b0f1823SDavid Xu 
519b0f1823SDavid Xu __BEGIN_DECLS
529b0f1823SDavid Xu int	 sem_close(sem_t *);
539b0f1823SDavid Xu int	 sem_destroy(sem_t *);
549b0f1823SDavid Xu int	 sem_getvalue(sem_t * __restrict, int * __restrict);
559b0f1823SDavid Xu int	 sem_init(sem_t *, int, unsigned int);
569b0f1823SDavid Xu sem_t	*sem_open(const char *, int, ...);
579b0f1823SDavid Xu int	 sem_post(sem_t *);
589b0f1823SDavid Xu int	 sem_timedwait(sem_t * __restrict, const struct timespec * __restrict);
599b0f1823SDavid Xu int	 sem_trywait(sem_t *);
609b0f1823SDavid Xu int	 sem_unlink(const char *);
619b0f1823SDavid Xu int	 sem_wait(sem_t *);
629b0f1823SDavid Xu __END_DECLS
639b0f1823SDavid Xu 
649b0f1823SDavid Xu #endif /* !_SEMAPHORE_H_ */
65