xref: /freebsd/include/semaphore.h (revision 4d846d260e2b9a3d4d0a701462568268cbfe7a5b)
1e58eb3c4SPedro F. Giffuni /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3e58eb3c4SPedro F. Giffuni  *
49b0f1823SDavid Xu  * Copyright (c) 2010 David Xu <davidxu@freebsd.org>
59b0f1823SDavid Xu  *
69b0f1823SDavid Xu  * All rights reserved.
79b0f1823SDavid Xu  *
89b0f1823SDavid Xu  * Redistribution and use in source and binary forms, with or without
99b0f1823SDavid Xu  * modification, are permitted provided that the following conditions
109b0f1823SDavid Xu  * are met:
119b0f1823SDavid Xu  * 1. Redistributions of source code must retain the above copyright
129b0f1823SDavid Xu  *    notice unmodified, this list of conditions, and the following
139b0f1823SDavid Xu  *    disclaimer.
149b0f1823SDavid Xu  * 2. Redistributions in binary form must reproduce the above copyright
159b0f1823SDavid Xu  *    notice, this list of conditions and the following disclaimer in the
169b0f1823SDavid Xu  *    documentation and/or other materials provided with the distribution.
179b0f1823SDavid Xu  *
189b0f1823SDavid Xu  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
199b0f1823SDavid Xu  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
209b0f1823SDavid Xu  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
219b0f1823SDavid Xu  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
229b0f1823SDavid Xu  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
239b0f1823SDavid Xu  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
249b0f1823SDavid Xu  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
259b0f1823SDavid Xu  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
269b0f1823SDavid Xu  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
279b0f1823SDavid Xu  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
289b0f1823SDavid Xu  *
299b0f1823SDavid Xu  * $FreeBSD$
309b0f1823SDavid Xu  */
319b0f1823SDavid Xu 
329b0f1823SDavid Xu /* semaphore.h: POSIX 1003.1b semaphores */
339b0f1823SDavid Xu 
349b0f1823SDavid Xu #ifndef _SEMAPHORE_H_
359b0f1823SDavid Xu #define _SEMAPHORE_H_
369b0f1823SDavid Xu 
379b0f1823SDavid Xu #include <sys/cdefs.h>
389b0f1823SDavid Xu #include <sys/_types.h>
399b0f1823SDavid Xu #include <sys/_umtx.h>
409b0f1823SDavid Xu 
41b90eeb5fSJilles Tjoelker #include <machine/_limits.h>
42b90eeb5fSJilles Tjoelker 
439b0f1823SDavid Xu struct _sem {
449b0f1823SDavid Xu 	__uint32_t	_magic;
4553e1ffbbSJohn Baldwin 	struct _usem2	_kern;
4653e1ffbbSJohn Baldwin 	__uint32_t	_padding;	/* Preserve structure size */
479b0f1823SDavid Xu };
489b0f1823SDavid Xu 
499b0f1823SDavid Xu typedef	struct _sem	sem_t;
509b0f1823SDavid Xu 
519b0f1823SDavid Xu #define	SEM_FAILED	((sem_t *)0)
529b0f1823SDavid Xu #define	SEM_VALUE_MAX	__INT_MAX
539b0f1823SDavid Xu 
549b0f1823SDavid Xu struct timespec;
559b0f1823SDavid Xu 
569b0f1823SDavid Xu __BEGIN_DECLS
5781027fa5SEric van Gyzen #if __BSD_VISIBLE
5881027fa5SEric van Gyzen int	 sem_clockwait_np(sem_t * __restrict, __clockid_t, int,
5981027fa5SEric van Gyzen 	    const struct timespec *, struct timespec *);
6081027fa5SEric van Gyzen #endif
619b0f1823SDavid Xu int	 sem_close(sem_t *);
629b0f1823SDavid Xu int	 sem_destroy(sem_t *);
639b0f1823SDavid Xu int	 sem_getvalue(sem_t * __restrict, int * __restrict);
649b0f1823SDavid Xu int	 sem_init(sem_t *, int, unsigned int);
659b0f1823SDavid Xu sem_t	*sem_open(const char *, int, ...);
669b0f1823SDavid Xu int	 sem_post(sem_t *);
679b0f1823SDavid Xu int	 sem_timedwait(sem_t * __restrict, const struct timespec * __restrict);
689b0f1823SDavid Xu int	 sem_trywait(sem_t *);
699b0f1823SDavid Xu int	 sem_unlink(const char *);
709b0f1823SDavid Xu int	 sem_wait(sem_t *);
719b0f1823SDavid Xu __END_DECLS
729b0f1823SDavid Xu 
739b0f1823SDavid Xu #endif /* !_SEMAPHORE_H_ */
74