semaphore.h revision 273604
1201546Sdavidxu/* 2201546Sdavidxu * Copyright (c) 2010 David Xu <davidxu@freebsd.org> 3201546Sdavidxu * 4201546Sdavidxu * All rights reserved. 5201546Sdavidxu * 6201546Sdavidxu * Redistribution and use in source and binary forms, with or without 7201546Sdavidxu * modification, are permitted provided that the following conditions 8201546Sdavidxu * are met: 9201546Sdavidxu * 1. Redistributions of source code must retain the above copyright 10201546Sdavidxu * notice unmodified, this list of conditions, and the following 11201546Sdavidxu * disclaimer. 12201546Sdavidxu * 2. Redistributions in binary form must reproduce the above copyright 13201546Sdavidxu * notice, this list of conditions and the following disclaimer in the 14201546Sdavidxu * documentation and/or other materials provided with the distribution. 15201546Sdavidxu * 16201546Sdavidxu * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17201546Sdavidxu * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18201546Sdavidxu * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19201546Sdavidxu * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20201546Sdavidxu * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21201546Sdavidxu * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22201546Sdavidxu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23201546Sdavidxu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24201546Sdavidxu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25201546Sdavidxu * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26201546Sdavidxu * 27201546Sdavidxu * $FreeBSD: head/include/semaphore.h 273604 2014-10-24 20:02:44Z jhb $ 28201546Sdavidxu */ 29201546Sdavidxu 30201546Sdavidxu/* semaphore.h: POSIX 1003.1b semaphores */ 31201546Sdavidxu 32201546Sdavidxu#ifndef _SEMAPHORE_H_ 33201546Sdavidxu#define _SEMAPHORE_H_ 34201546Sdavidxu 35201546Sdavidxu#include <sys/cdefs.h> 36201546Sdavidxu#include <sys/_types.h> 37201546Sdavidxu#include <sys/_umtx.h> 38201546Sdavidxu 39201546Sdavidxustruct _sem { 40201546Sdavidxu __uint32_t _magic; 41273604Sjhb struct _usem2 _kern; 42273604Sjhb __uint32_t _padding; /* Preserve structure size */ 43201546Sdavidxu}; 44201546Sdavidxu 45201546Sdavidxutypedef struct _sem sem_t; 46201546Sdavidxu 47201546Sdavidxu#define SEM_FAILED ((sem_t *)0) 48201546Sdavidxu#define SEM_VALUE_MAX __INT_MAX 49201546Sdavidxu 50201546Sdavidxustruct timespec; 51201546Sdavidxu 52201546Sdavidxu__BEGIN_DECLS 53201546Sdavidxuint sem_close(sem_t *); 54201546Sdavidxuint sem_destroy(sem_t *); 55201546Sdavidxuint sem_getvalue(sem_t * __restrict, int * __restrict); 56201546Sdavidxuint sem_init(sem_t *, int, unsigned int); 57201546Sdavidxusem_t *sem_open(const char *, int, ...); 58201546Sdavidxuint sem_post(sem_t *); 59201546Sdavidxuint sem_timedwait(sem_t * __restrict, const struct timespec * __restrict); 60201546Sdavidxuint sem_trywait(sem_t *); 61201546Sdavidxuint sem_unlink(const char *); 62201546Sdavidxuint sem_wait(sem_t *); 63201546Sdavidxu__END_DECLS 64201546Sdavidxu 65201546Sdavidxu#endif /* !_SEMAPHORE_H_ */ 66