xref: /freebsd/include/semaphore.h (revision b3e76948)
1e58eb3c4SPedro F. Giffuni /*-
24d846d26SWarner 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 
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 
39b90eeb5fSJilles Tjoelker #include <machine/_limits.h>
40b90eeb5fSJilles Tjoelker 
419b0f1823SDavid Xu struct _sem {
429b0f1823SDavid Xu 	__uint32_t	_magic;
4353e1ffbbSJohn Baldwin 	struct _usem2	_kern;
4453e1ffbbSJohn Baldwin 	__uint32_t	_padding;	/* Preserve structure size */
459b0f1823SDavid Xu };
469b0f1823SDavid Xu 
479b0f1823SDavid Xu typedef	struct _sem	sem_t;
489b0f1823SDavid Xu 
499b0f1823SDavid Xu #define	SEM_FAILED	((sem_t *)0)
509b0f1823SDavid Xu #define	SEM_VALUE_MAX	__INT_MAX
519b0f1823SDavid Xu 
529b0f1823SDavid Xu struct timespec;
539b0f1823SDavid Xu 
549b0f1823SDavid Xu __BEGIN_DECLS
5581027fa5SEric van Gyzen #if __BSD_VISIBLE
5681027fa5SEric van Gyzen int	 sem_clockwait_np(sem_t * __restrict, __clockid_t, int,
5781027fa5SEric van Gyzen 	    const struct timespec *, struct timespec *);
5881027fa5SEric van Gyzen #endif
599b0f1823SDavid Xu int	 sem_close(sem_t *);
609b0f1823SDavid Xu int	 sem_destroy(sem_t *);
619b0f1823SDavid Xu int	 sem_getvalue(sem_t * __restrict, int * __restrict);
629b0f1823SDavid Xu int	 sem_init(sem_t *, int, unsigned int);
639b0f1823SDavid Xu sem_t	*sem_open(const char *, int, ...);
649b0f1823SDavid Xu int	 sem_post(sem_t *);
659b0f1823SDavid Xu int	 sem_timedwait(sem_t * __restrict, const struct timespec * __restrict);
669b0f1823SDavid Xu int	 sem_trywait(sem_t *);
679b0f1823SDavid Xu int	 sem_unlink(const char *);
689b0f1823SDavid Xu int	 sem_wait(sem_t *);
699b0f1823SDavid Xu __END_DECLS
709b0f1823SDavid Xu 
719b0f1823SDavid Xu #endif /* !_SEMAPHORE_H_ */
72