Add librt, which provides POSIX 1003.1b Real-time extensions not
present in libc. Currently includes 1003.1b semaphores.
This commit is contained in:
parent
68d5821c1b
commit
37946878c4
@ -1,4 +1,4 @@
|
||||
# $NetBSD: Makefile,v 1.81 2003/01/19 16:05:46 christos Exp $
|
||||
# $NetBSD: Makefile,v 1.82 2003/01/24 01:52:42 thorpej Exp $
|
||||
# from: @(#)Makefile 5.25.1.1 (Berkeley) 5/7/91
|
||||
|
||||
.include <bsd.own.mk>
|
||||
@ -6,7 +6,7 @@
|
||||
SUBDIR= csu libc .WAIT libarch libbz2 libcdk libcompat libcrypt libcurses \
|
||||
libedit libform libintl libkvm libl libm libmenu libossaudio libpcap \
|
||||
libpci libpmc libposix libpthread libpthread_dbg libresolv librmt \
|
||||
librpcsvc libterm libusbhid libutil libwrap liby libz
|
||||
librpcsvc librt libterm libusbhid libutil libwrap liby libz
|
||||
|
||||
.if (${MKSKEY} != "no")
|
||||
SUBDIR+= libskey
|
||||
|
16
lib/librt/Makefile
Normal file
16
lib/librt/Makefile
Normal file
@ -0,0 +1,16 @@
|
||||
# $NetBSD: Makefile,v 1.1 2003/01/24 01:52:43 thorpej Exp $
|
||||
#
|
||||
|
||||
WARNS= 2
|
||||
|
||||
LIB= rt
|
||||
SRCS= sem.c
|
||||
|
||||
MAN+= sem_destroy.3 sem_getvalue.3 sem_init.3 sem_open.3 sem_post.3 \
|
||||
sem_wait.3
|
||||
|
||||
MLINKS+= sem_open.3 sem_close.3
|
||||
MLINKS+= sem_open.3 sem_unlink.3
|
||||
MLINKS+= sem_wait.3 sem_trywait.3
|
||||
|
||||
.include <bsd.lib.mk>
|
321
lib/librt/sem.c
Normal file
321
lib/librt/sem.c
Normal file
@ -0,0 +1,321 @@
|
||||
/* $NetBSD: sem.c,v 1.1 2003/01/24 01:52:44 thorpej Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2003 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Jason R. Thorpe.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the NetBSD
|
||||
* Foundation, Inc. and its contributors.
|
||||
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2000 Jason Evans <jasone@freebsd.org>.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice(s), this list of conditions and the following disclaimer as
|
||||
* the first lines of this file unmodified other than the possible
|
||||
* addition of one or more copyright notices.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice(s), this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* If an application is linked against both librt and libpthread, the
|
||||
* libpthread versions must be used. Provide weak aliases to cause
|
||||
* this behavior.
|
||||
*/
|
||||
#define sem_init _librt_sem_init
|
||||
#define sem_destroy _librt_sem_destroy
|
||||
#define sem_open _librt_sem_open
|
||||
#define sem_close _librt_sem_close
|
||||
#define sem_unlink _librt_sem_unlink
|
||||
#define sem_wait _librt_sem_wait
|
||||
#define sem_trywait _librt_sem_trywait
|
||||
#define sem_post _librt_sem_post
|
||||
#define sem_getvalue _librt_sem_getvalue
|
||||
|
||||
#define _LIBC /* XXX to get semid_t type */
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/ksem.h>
|
||||
#include <sys/queue.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <semaphore.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
struct _sem_st {
|
||||
unsigned int ksem_magic;
|
||||
#define KSEM_MAGIC 0x90af0421U
|
||||
|
||||
LIST_ENTRY(_sem_st) ksem_list;
|
||||
semid_t ksem_semid; /* 0 -> user (non-shared) */
|
||||
sem_t *ksem_identity;
|
||||
};
|
||||
|
||||
static int sem_alloc(unsigned int value, semid_t semid, sem_t *semp);
|
||||
static void sem_free(sem_t sem);
|
||||
|
||||
static LIST_HEAD(, _sem_st) named_sems = LIST_HEAD_INITIALIZER(&named_sems);
|
||||
|
||||
__weak_alias(sem_init,_librt_sem_init)
|
||||
__weak_alias(sem_destroy,_librt_sem_destroy)
|
||||
__weak_alias(sem_open,_librt_sem_open)
|
||||
__weak_alias(sem_close,_librt_sem_close)
|
||||
__weak_alias(sem_unlink,_librt_sem_unlink)
|
||||
__weak_alias(sem_wait,_librt_sem_wait)
|
||||
__weak_alias(sem_trywait,_librt_sem_trywait)
|
||||
__weak_alias(sem_post,_librt_sem_post)
|
||||
__weak_alias(sem_getvalue,_librt_sem_getvalue)
|
||||
|
||||
static void
|
||||
sem_free(sem_t sem)
|
||||
{
|
||||
|
||||
sem->ksem_magic = 0;
|
||||
free(sem);
|
||||
}
|
||||
|
||||
static int
|
||||
sem_alloc(unsigned int value, semid_t semid, sem_t *semp)
|
||||
{
|
||||
sem_t sem;
|
||||
|
||||
if (value > SEM_VALUE_MAX)
|
||||
return (EINVAL);
|
||||
|
||||
if ((sem = malloc(sizeof(struct _sem_st))) == NULL)
|
||||
return (ENOSPC);
|
||||
|
||||
sem->ksem_magic = KSEM_MAGIC;
|
||||
sem->ksem_semid = semid;
|
||||
|
||||
*semp = sem;
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* ARGSUSED */
|
||||
int
|
||||
sem_init(sem_t *sem, int pshared, unsigned int value)
|
||||
{
|
||||
semid_t semid;
|
||||
int error;
|
||||
|
||||
if (_ksem_init(value, &semid) == -1)
|
||||
return (-1);
|
||||
|
||||
if ((error = sem_alloc(value, semid, sem)) != 0) {
|
||||
_ksem_destroy(semid);
|
||||
errno = error;
|
||||
return (-1);
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
sem_destroy(sem_t *sem)
|
||||
{
|
||||
|
||||
#ifdef ERRORCHECK
|
||||
if (sem == NULL || *sem == NULL || (*sem)->ksem_magic != KSEM_MAGIC) {
|
||||
errno = EINVAL;
|
||||
return (-1);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (_ksem_destroy((*sem)->ksem_semid) == -1)
|
||||
return (-1);
|
||||
|
||||
sem_free(*sem);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
sem_t *
|
||||
sem_open(const char *name, int oflag, ...)
|
||||
{
|
||||
sem_t *sem, s;
|
||||
semid_t semid;
|
||||
mode_t mode;
|
||||
unsigned int value;
|
||||
int error;
|
||||
va_list ap;
|
||||
|
||||
mode = 0;
|
||||
value = 0;
|
||||
|
||||
if (oflag & O_CREAT) {
|
||||
va_start(ap, oflag);
|
||||
mode = va_arg(ap, int);
|
||||
value = va_arg(ap, unsigned int);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
/*
|
||||
* We can be lazy and let the kernel handle the oflag,
|
||||
* we'll just merge duplicate IDs into our list.
|
||||
*/
|
||||
if (_ksem_open(name, oflag, mode, value, &semid) == -1)
|
||||
return (SEM_FAILED);
|
||||
|
||||
/*
|
||||
* Search for a duplicate ID, we must return the same sem_t *
|
||||
* if we locate one.
|
||||
*/
|
||||
LIST_FOREACH(s, &named_sems, ksem_list) {
|
||||
if (s->ksem_semid == semid)
|
||||
return (s->ksem_identity);
|
||||
}
|
||||
|
||||
if ((sem = malloc(sizeof(*sem))) == NULL) {
|
||||
error = ENOSPC;
|
||||
goto bad;
|
||||
}
|
||||
if ((error = sem_alloc(value, semid, sem)) != 0)
|
||||
goto bad;
|
||||
|
||||
LIST_INSERT_HEAD(&named_sems, *sem, ksem_list);
|
||||
(*sem)->ksem_identity = sem;
|
||||
|
||||
return (sem);
|
||||
|
||||
bad:
|
||||
_ksem_close(semid);
|
||||
if (sem != NULL) {
|
||||
if (*sem != NULL)
|
||||
sem_free(*sem);
|
||||
free(sem);
|
||||
}
|
||||
errno = error;
|
||||
return (SEM_FAILED);
|
||||
}
|
||||
|
||||
int
|
||||
sem_close(sem_t *sem)
|
||||
{
|
||||
|
||||
#ifdef ERRORCHECK
|
||||
if (sem == NULL || *sem == NULL || (*sem)->ksem_magic != KSEM_MAGIC) {
|
||||
errno = EINVAL;
|
||||
return (-1);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (_ksem_close((*sem)->ksem_semid) == -1)
|
||||
return (-1);
|
||||
|
||||
LIST_REMOVE((*sem), ksem_list);
|
||||
sem_free(*sem);
|
||||
free(sem);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
sem_unlink(const char *name)
|
||||
{
|
||||
|
||||
return (_ksem_unlink(name));
|
||||
}
|
||||
|
||||
int
|
||||
sem_wait(sem_t *sem)
|
||||
{
|
||||
|
||||
#ifdef ERRORCHECK
|
||||
if (sem == NULL || *sem == NULL || (*sem)->ksem_magic != KSEM_MAGIC) {
|
||||
errno = EINVAL;
|
||||
return (-1);
|
||||
}
|
||||
#endif
|
||||
|
||||
return (_ksem_wait((*sem)->ksem_semid));
|
||||
}
|
||||
|
||||
int
|
||||
sem_trywait(sem_t *sem)
|
||||
{
|
||||
|
||||
#ifdef ERRORCHECK
|
||||
if (sem == NULL || *sem == NULL || (*sem)->ksem_magic != KSEM_MAGIC) {
|
||||
errno = EINVAL;
|
||||
return (-1);
|
||||
}
|
||||
#endif
|
||||
|
||||
return (_ksem_trywait((*sem)->ksem_semid));
|
||||
}
|
||||
|
||||
int
|
||||
sem_post(sem_t *sem)
|
||||
{
|
||||
|
||||
#ifdef ERRORCHECK
|
||||
if (sem == NULL || *sem == NULL || (*sem)->ksem_magic != KSEM_MAGIC) {
|
||||
errno = EINVAL;
|
||||
return (-1);
|
||||
}
|
||||
#endif
|
||||
|
||||
return (_ksem_post((*sem)->ksem_semid));
|
||||
}
|
||||
|
||||
int
|
||||
sem_getvalue(sem_t * __restrict sem, int * __restrict sval)
|
||||
{
|
||||
|
||||
#ifdef ERRORCHECK
|
||||
if (sem == NULL || *sem == NULL || (*sem)->ksem_magic != KSEM_MAGIC) {
|
||||
errno = EINVAL;
|
||||
return (-1);
|
||||
}
|
||||
#endif
|
||||
return (_ksem_getvalue((*sem)->ksem_semid, sval));
|
||||
}
|
82
lib/librt/sem_destroy.3
Normal file
82
lib/librt/sem_destroy.3
Normal file
@ -0,0 +1,82 @@
|
||||
.\" $NetBSD: sem_destroy.3,v 1.1 2003/01/24 01:52:44 thorpej Exp $
|
||||
.\"
|
||||
.\" Copyright (C) 2000 Jason Evans <jasone@FreeBSD.org>.
|
||||
.\" All rights reserved.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice(s), this list of conditions and the following disclaimer as
|
||||
.\" the first lines of this file unmodified other than the possible
|
||||
.\" addition of one or more copyright notices.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice(s), this list of conditions and the following disclaimer in
|
||||
.\" the documentation and/or other materials provided with the
|
||||
.\" distribution.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
|
||||
.\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
|
||||
.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
.\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
.\" OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
.\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
.\"
|
||||
.Dd January 22, 2003
|
||||
.Dt SEM_DESTROY 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm sem_destroy
|
||||
.Nd destroy an unnamed semaphore
|
||||
.Sh LIBRARY
|
||||
.Lb librt
|
||||
.Sh SYNOPSIS
|
||||
.In semaphore.h
|
||||
.Ft int
|
||||
.Fn sem_destroy "sem_t *sem"
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Fn sem_destroy
|
||||
function destroys the unnamed semaphore pointed to by
|
||||
.Fa sem .
|
||||
After a successful call to
|
||||
.Fn sem_destroy ,
|
||||
.Fa sem
|
||||
is unusable until re-initialized by another call to
|
||||
.Fn sem_init .
|
||||
.Sh RETURN VALUES
|
||||
.Rv -std sem_destroy
|
||||
.Sh ERRORS
|
||||
.Fn sem_destroy
|
||||
will fail if:
|
||||
.Bl -tag -width Er
|
||||
.It Bq Er EINVAL
|
||||
.Fa sem
|
||||
points to an invalid semaphore.
|
||||
.It Bq Er EBUSY
|
||||
There are currently threads blocked on the semaphore that
|
||||
.Fa sem
|
||||
points to.
|
||||
.El
|
||||
.Sh SEE ALSO
|
||||
.Xr sem_init 3
|
||||
.Sh STANDARDS
|
||||
.Fn sem_destroy
|
||||
conforms to
|
||||
.St -p1003.1-96 .
|
||||
.Pp
|
||||
POSIX does not define the behavior of
|
||||
.Fn sem_destroy
|
||||
if called while there are threads blocked on
|
||||
.Fa sem ,
|
||||
but this implementation is guaranteed to return \-1 and set
|
||||
.Va errno
|
||||
to
|
||||
.Er EBUSY
|
||||
if there are threads blocked on
|
||||
.Fa sem .
|
75
lib/librt/sem_getvalue.3
Normal file
75
lib/librt/sem_getvalue.3
Normal file
@ -0,0 +1,75 @@
|
||||
.\" $NetBSD: sem_getvalue.3,v 1.1 2003/01/24 01:52:44 thorpej Exp $
|
||||
.\"
|
||||
.\" Copyright (C) 2000 Jason Evans <jasone@FreeBSD.org>.
|
||||
.\" All rights reserved.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice(s), this list of conditions and the following disclaimer as
|
||||
.\" the first lines of this file unmodified other than the possible
|
||||
.\" addition of one or more copyright notices.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice(s), this list of conditions and the following disclaimer in
|
||||
.\" the documentation and/or other materials provided with the
|
||||
.\" distribution.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
|
||||
.\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
|
||||
.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
.\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
.\" OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
.\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
.\"
|
||||
.Dd January 22, 2003
|
||||
.Dt SEM_GETVALUE 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm sem_getvalue
|
||||
.Nd get the value of a semaphore
|
||||
.Sh LIBRARY
|
||||
.Lb librt
|
||||
.Sh SYNOPSIS
|
||||
.In semaphore.h
|
||||
.Ft int
|
||||
.Fn sem_getvalue "sem_t *sem" "int *sval"
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Fn sem_getvalue
|
||||
function sets the variable pointed to by
|
||||
.Fa sval
|
||||
to the current value of the semaphore pointed to by
|
||||
.Fa sem ,
|
||||
as of the time that the call to
|
||||
.Fn sem_getvalue
|
||||
is actually run.
|
||||
.Sh RETURN VALUES
|
||||
.Rv -std sem_getvalue
|
||||
.Sh ERRORS
|
||||
.Fn sem_getvalue
|
||||
will fail if:
|
||||
.Bl -tag -width Er
|
||||
.It Bq Er EINVAL
|
||||
.Fa sem
|
||||
points to an invalid semaphore.
|
||||
.El
|
||||
.Sh SEE ALSO
|
||||
.Xr sem_post 3 ,
|
||||
.Xr sem_trywait 3 ,
|
||||
.Xr sem_wait 3
|
||||
.Sh STANDARDS
|
||||
.Fn sem_getvalue
|
||||
conforms to
|
||||
.St -p1003.1-96 .
|
||||
.Pp
|
||||
The value of the semaphore is never negative, even if there are threads blocked
|
||||
on the semaphore.
|
||||
POSIX is somewhat ambiguous in its wording with regard to
|
||||
what the value of the semaphore should be if there are blocked waiting threads,
|
||||
but this behavior is conformant, given the wording of the specification.
|
99
lib/librt/sem_init.3
Normal file
99
lib/librt/sem_init.3
Normal file
@ -0,0 +1,99 @@
|
||||
.\" $NetBSD: sem_init.3,v 1.1 2003/01/24 01:52:44 thorpej Exp $
|
||||
.\"
|
||||
.\" Copyright (C) 2000 Jason Evans <jasone@FreeBSD.org>.
|
||||
.\" All rights reserved.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice(s), this list of conditions and the following disclaimer as
|
||||
.\" the first lines of this file unmodified other than the possible
|
||||
.\" addition of one or more copyright notices.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice(s), this list of conditions and the following disclaimer in
|
||||
.\" the documentation and/or other materials provided with the
|
||||
.\" distribution.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
|
||||
.\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
|
||||
.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
.\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
.\" OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
.\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
.\"
|
||||
.Dd January 22, 2003
|
||||
.Dt SEM_INIT 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm sem_init
|
||||
.Nd initialize an unnamed semaphore
|
||||
.Sh LIBRARY
|
||||
.Lb librt
|
||||
.Sh SYNOPSIS
|
||||
.In semaphore.h
|
||||
.Ft int
|
||||
.Fn sem_init "sem_t *sem" "int pshared" "unsigned int value"
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Fn sem_init
|
||||
function initializes the unnamed semaphore pointed to by
|
||||
.Fa sem
|
||||
to have the value
|
||||
.Fa value .
|
||||
A non-zero value for
|
||||
.Fa pshared
|
||||
specifies a shared semaphore that can be used by multiple processes, which this
|
||||
implementation is not capable of.
|
||||
.Pp
|
||||
Following a successful call to
|
||||
.Fn sem_init ,
|
||||
.Fa sem
|
||||
can be used as an argument in subsequent calls to
|
||||
.Fa sem_wait ,
|
||||
.Fa sem_trywait ,
|
||||
.Fa sem_post ,
|
||||
and
|
||||
.Fa sem_destroy .
|
||||
.Fa sem
|
||||
is no longer valid after a successful call to
|
||||
.Fa sem_destroy .
|
||||
.Sh RETURN VALUES
|
||||
.Rv -std sem_init
|
||||
.Sh ERRORS
|
||||
.Fn sem_init
|
||||
will fail if:
|
||||
.Bl -tag -width Er
|
||||
.It Bq Er EINVAL
|
||||
.Fa value
|
||||
exceeds SEM_VALUE_MAX.
|
||||
.It Bq Er ENOSPC
|
||||
Memory allocation error.
|
||||
.It Bq Er EPERM
|
||||
Unable to initialize a shared semaphore.
|
||||
.El
|
||||
.Sh SEE ALSO
|
||||
.Xr sem_destroy 3 ,
|
||||
.Xr sem_post 3 ,
|
||||
.Xr sem_trywait 3 ,
|
||||
.Xr sem_wait 3
|
||||
.Sh STANDARDS
|
||||
.Fn sem_init
|
||||
conforms to
|
||||
.St -p1003.1-96 .
|
||||
.Pp
|
||||
This implementation does not support shared semaphores, and reports this fact
|
||||
by setting
|
||||
.Va errno
|
||||
to
|
||||
.Er EPERM .
|
||||
This is perhaps a stretch of the intention of POSIX, but is
|
||||
compliant, with the caveat that
|
||||
.Fn sem_init
|
||||
always reports a permissions error when an attempt to create a shared semaphore
|
||||
is made.
|
82
lib/librt/sem_open.3
Normal file
82
lib/librt/sem_open.3
Normal file
@ -0,0 +1,82 @@
|
||||
.\" $NetBSD: sem_open.3,v 1.1 2003/01/24 01:52:44 thorpej Exp $
|
||||
.\"
|
||||
.\" Copyright (C) 2000 Jason Evans <jasone@FreeBSD.org>.
|
||||
.\" All rights reserved.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice(s), this list of conditions and the following disclaimer as
|
||||
.\" the first lines of this file unmodified other than the possible
|
||||
.\" addition of one or more copyright notices.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice(s), this list of conditions and the following disclaimer in
|
||||
.\" the documentation and/or other materials provided with the
|
||||
.\" distribution.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
|
||||
.\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
|
||||
.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
.\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
.\" OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
.\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
.\"
|
||||
.Dd January 22, 2003
|
||||
.Dt SEM_OPEN 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm sem_open ,
|
||||
.Nm sem_close ,
|
||||
.Nm sem_unlink
|
||||
.Nd named semaphore operations
|
||||
.Sh LIBRARY
|
||||
.Lb librt
|
||||
.Sh SYNOPSIS
|
||||
.In semaphore.h
|
||||
.Ft sem_t *
|
||||
.Fn sem_open "const char *name" "int oflag" "..."
|
||||
.Ft int
|
||||
.Fn sem_close "sem_t *sem"
|
||||
.Ft int
|
||||
.Fn sem_unlink "const char *name"
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Fn sem_open ,
|
||||
.Fn sem_close ,
|
||||
and
|
||||
.Fn sem_unlink
|
||||
functions are not supported by this implementation.
|
||||
.Sh RETURN VALUES
|
||||
.Fn sem_open
|
||||
returns SEM_FAILED and sets
|
||||
.Va errno
|
||||
to indicate an error.
|
||||
.Fn sem_close
|
||||
and
|
||||
.Fn sem_unlink
|
||||
return \-1 and set
|
||||
.Va errno
|
||||
to indicate an error.
|
||||
.Sh ERRORS
|
||||
.Fn sem_open ,
|
||||
.Fn sem_close ,
|
||||
and
|
||||
.Fn sem_unlink
|
||||
will fail:
|
||||
.Bl -tag -width Er
|
||||
.It Bq Er ENOSYS
|
||||
Function not supported by this implementation.
|
||||
.El
|
||||
.Sh STANDARDS
|
||||
.Fn sem_open ,
|
||||
.Fn sem_close ,
|
||||
and
|
||||
.Fn sem_unlink
|
||||
conform to
|
||||
.St -p1003.1-96 .
|
71
lib/librt/sem_post.3
Normal file
71
lib/librt/sem_post.3
Normal file
@ -0,0 +1,71 @@
|
||||
.\" $NetBSD: sem_post.3,v 1.1 2003/01/24 01:52:44 thorpej Exp $
|
||||
.\"
|
||||
.\" Copyright (C) 2000 Jason Evans <jasone@FreeBSD.org>.
|
||||
.\" All rights reserved.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice(s), this list of conditions and the following disclaimer as
|
||||
.\" the first lines of this file unmodified other than the possible
|
||||
.\" addition of one or more copyright notices.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice(s), this list of conditions and the following disclaimer in
|
||||
.\" the documentation and/or other materials provided with the
|
||||
.\" distribution.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
|
||||
.\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
|
||||
.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
.\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
.\" OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
.\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
.\"
|
||||
.Dd January 22, 2003
|
||||
.Dt SEM_POST 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm sem_post
|
||||
.Nd increment (unlock) a semaphore
|
||||
.Sh LIBRARY
|
||||
.Lb librt
|
||||
.Sh SYNOPSIS
|
||||
.In semaphore.h
|
||||
.Ft int
|
||||
.Fn sem_post "sem_t *sem"
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Fn sem_post
|
||||
function increments (unlocks) the semaphore pointed to by
|
||||
.Fa sem .
|
||||
If there are threads blocked on the semaphore when
|
||||
.Fn sem_post
|
||||
is called, then the highest priority thread that has been blocked the longest on
|
||||
the semaphore will be allowed to return from
|
||||
.Fn sem_wait .
|
||||
.Pp
|
||||
.Fn sem_post
|
||||
is signal-reentrant and may be called within signal handlers.
|
||||
.Sh RETURN VALUES
|
||||
.Rv -std sem_post
|
||||
.Sh ERRORS
|
||||
.Fn sem_post
|
||||
will fail if:
|
||||
.Bl -tag -width Er
|
||||
.It Bq Er EINVAL
|
||||
.Fa sem
|
||||
points to an invalid semaphore.
|
||||
.El
|
||||
.Sh SEE ALSO
|
||||
.Xr sem_trywait 3 ,
|
||||
.Xr sem_wait 3
|
||||
.Sh STANDARDS
|
||||
.Fn sem_post
|
||||
conforms to
|
||||
.St -p1003.1-96 .
|
87
lib/librt/sem_wait.3
Normal file
87
lib/librt/sem_wait.3
Normal file
@ -0,0 +1,87 @@
|
||||
.\" $NetBSD: sem_wait.3,v 1.1 2003/01/24 01:52:45 thorpej Exp $
|
||||
.\"
|
||||
.\" Copyright (C) 2000 Jason Evans <jasone@FreeBSD.org>.
|
||||
.\" All rights reserved.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice(s), this list of conditions and the following disclaimer as
|
||||
.\" the first lines of this file unmodified other than the possible
|
||||
.\" addition of one or more copyright notices.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice(s), this list of conditions and the following disclaimer in
|
||||
.\" the documentation and/or other materials provided with the
|
||||
.\" distribution.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
|
||||
.\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
|
||||
.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
.\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
.\" OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
.\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
.\"
|
||||
.Dd January 22, 2003
|
||||
.Dt SEM_WAIT 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm sem_wait ,
|
||||
.Nm sem_trywait
|
||||
.Nd decrement (lock) a semaphore
|
||||
.Sh LIBRARY
|
||||
.Lb librt
|
||||
.Sh SYNOPSIS
|
||||
.In semaphore.h
|
||||
.Ft int
|
||||
.Fn sem_wait "sem_t *sem"
|
||||
.Ft int
|
||||
.Fn sem_trywait "sem_t *sem"
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Fn sem_wait
|
||||
function decrements (locks) the semaphore pointed to by
|
||||
.Fa sem ,
|
||||
but blocks if the value of
|
||||
.Fa sem
|
||||
is zero, until the value is non-zero and the value can be decremented.
|
||||
.Pp
|
||||
The
|
||||
.Fn sem_trywait
|
||||
function decrements (locks) the semaphore pointed to by
|
||||
.Fa sem
|
||||
only if the value is non-zero.
|
||||
Otherwise, the semaphore is not decremented and an error is returned.
|
||||
.Sh RETURN VALUES
|
||||
.Rv -std sem_wait
|
||||
.Sh ERRORS
|
||||
.Fn sem_wait
|
||||
and
|
||||
.Fn sem_trywait
|
||||
will fail if:
|
||||
.Bl -tag -width Er
|
||||
.It Bq Er EINVAL
|
||||
.Fa sem
|
||||
points to an invalid semaphore.
|
||||
.El
|
||||
.Pp
|
||||
Additionally,
|
||||
.Fn sem_trywait
|
||||
will fail if:
|
||||
.Bl -tag -width Er
|
||||
.It Bq Er EAGAIN
|
||||
The semaphore value was zero, and thus could not be decremented.
|
||||
.El
|
||||
.Sh SEE ALSO
|
||||
.Xr sem_post 3
|
||||
.Sh STANDARDS
|
||||
.Fn sem_wait
|
||||
and
|
||||
.Fn sem_trywait
|
||||
conform to
|
||||
.St -p1003.1-96 .
|
5
lib/librt/shlib_version
Normal file
5
lib/librt/shlib_version
Normal file
@ -0,0 +1,5 @@
|
||||
# $NetBSD: shlib_version,v 1.1 2003/01/24 01:52:45 thorpej Exp $
|
||||
# Remember to update distrib/sets/lists/base/shl.* when changing
|
||||
#
|
||||
major=0
|
||||
minor=0
|
Loading…
Reference in New Issue
Block a user