thr_sem.c revision 201546
186231Stmm/* 286231Stmm * Copyright (C) 2005 David Xu <davidxu@freebsd.org>. 386231Stmm * Copyright (C) 2000 Jason Evans <jasone@freebsd.org>. 486231Stmm * All rights reserved. 586231Stmm * 686231Stmm * Redistribution and use in source and binary forms, with or without 786231Stmm * modification, are permitted provided that the following conditions 886231Stmm * are met: 986231Stmm * 1. Redistributions of source code must retain the above copyright 1086231Stmm * notice(s), this list of conditions and the following disclaimer as 1186231Stmm * the first lines of this file unmodified other than the possible 1286231Stmm * addition of one or more copyright notices. 1386231Stmm * 2. Redistributions in binary form must reproduce the above copyright 1486231Stmm * notice(s), this list of conditions and the following disclaimer in 1586231Stmm * the documentation and/or other materials provided with the 1686231Stmm * distribution. 1786231Stmm * 1886231Stmm * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY 1986231Stmm * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2086231Stmm * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 2186231Stmm * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE 2286231Stmm * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2386231Stmm * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2486231Stmm * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 2586231Stmm * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 2686231Stmm * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 2786231Stmm * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 2886231Stmm * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2986231Stmm * 3086231Stmm * $FreeBSD: head/lib/libthr/thread/thr_sem.c 201546 2010-01-05 02:37:59Z davidxu $ 3186231Stmm */ 3286231Stmm 3386231Stmm#include "namespace.h" 3486231Stmm#include <sys/types.h> 3586231Stmm#include <sys/queue.h> 3686231Stmm#include <errno.h> 3786231Stmm#include <fcntl.h> 3886231Stmm#include <pthread.h> 3986231Stmm#include <stdlib.h> 4086231Stmm#include <time.h> 4186231Stmm#include <_semaphore.h> 4286231Stmm#include "un-namespace.h" 4386231Stmm 4486231Stmm#include "thr_private.h" 4586231Stmm 4686231StmmFB10_COMPAT(_sem_init_compat, sem_init); 4786231StmmFB10_COMPAT(_sem_destroy_compat, sem_destroy); 4886231StmmFB10_COMPAT(_sem_getvalue_compat, sem_getvalue); 4986231StmmFB10_COMPAT(_sem_trywait_compat, sem_trywait); 5086231StmmFB10_COMPAT(_sem_wait_compat, sem_wait); 5186231StmmFB10_COMPAT(_sem_timedwait_compat, sem_timedwait); 5286231StmmFB10_COMPAT(_sem_post_compat, sem_post); 5386231Stmm 5486231Stmmtypedef struct sem *sem_t; 5586231Stmm 5686231Stmmextern int _libc_sem_init_compat(sem_t *sem, int pshared, unsigned int value); 5786231Stmmextern int _libc_sem_destroy_compat(sem_t *sem); 5886231Stmmextern int _libc_sem_getvalue_compat(sem_t * __restrict sem, int * __restrict sval); 5986231Stmmextern int _libc_sem_trywait_compat(sem_t *sem); 6086231Stmmextern int _libc_sem_wait_compat(sem_t *sem); 6186231Stmmextern int _libc_sem_timedwait_compat(sem_t * __restrict sem, 6286231Stmm const struct timespec * __restrict abstime); 6386231Stmmextern int _libc_sem_post_compat(sem_t *sem); 6486231Stmm 6586231Stmmint _sem_init_compat(sem_t *sem, int pshared, unsigned int value); 6686231Stmmint _sem_destroy_compat(sem_t *sem); 6786231Stmmint _sem_getvalue_compat(sem_t * __restrict sem, int * __restrict sval); 6886231Stmmint _sem_trywait_compat(sem_t *sem); 6986231Stmmint _sem_wait_compat(sem_t *sem); 7086231Stmmint _sem_timedwait_compat(sem_t * __restrict sem, 7186231Stmm const struct timespec * __restrict abstime); 7286231Stmmint _sem_post_compat(sem_t *sem); 7386231Stmm 7486231Stmmint 7586231Stmm_sem_init_compat(sem_t *sem, int pshared, unsigned int value) 7686231Stmm{ 7786231Stmm return _libc_sem_init_compat(sem, pshared, value); 7886231Stmm} 7986231Stmm 8086231Stmmint 8186231Stmm_sem_destroy_compat(sem_t *sem) 8286231Stmm{ 8386231Stmm return _libc_sem_destroy_compat(sem); 8486231Stmm} 8586231Stmm 8686231Stmmint 8786231Stmm_sem_getvalue_compat(sem_t * __restrict sem, int * __restrict sval) 8886231Stmm{ 8986231Stmm return _libc_sem_getvalue_compat(sem, sval); 9086231Stmm} 9186231Stmm 9286231Stmmint 93_sem_trywait_compat(sem_t *sem) 94{ 95 return _libc_sem_trywait_compat(sem); 96} 97 98int 99_sem_wait_compat(sem_t *sem) 100{ 101 return _libc_sem_wait_compat(sem); 102} 103 104int 105_sem_timedwait_compat(sem_t * __restrict sem, 106 const struct timespec * __restrict abstime) 107{ 108 return _libc_sem_timedwait_compat(sem, abstime); 109} 110 111int 112_sem_post_compat(sem_t *sem) 113{ 114 return _libc_sem_post_compat(sem); 115} 116