NetBSD/lib/libpthread/cnd.3

183 lines
4.1 KiB
Groff

.\" $NetBSD: cnd.3,v 1.2 2019/04/27 10:57:11 wiz Exp $
.\"
.\" Copyright (c) 2016 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" This code is derived from software contributed to The NetBSD Foundation
.\" by Kamil Rytarowski.
.\"
.\" 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.
.\"
.\" 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.
.\"
.Dd October 16, 2016
.Dt CND 3
.Os
.Sh NAME
.Nm cnd
.Nd condition variable functions
.Sh LIBRARY
.Lb libpthread
.Sh SYNOPSIS
.In threads.h
.Ft int
.Fn cnd_broadcast "cnd_t *cond"
.Ft void
.Fn cnd_destroy "cnd_t *cond"
.Ft int
.Fn cnd_init "cnd_t *cond"
.Ft int
.Fn cnd_signal "cnd_t *cond"
.Ft int
.Fo cnd_timedwait
.Fa "cnd_t * __restrict cond"
.Fa "mtx_t * __restrict mtx"
.Fa "const struct timespec * __restrict ts"
.Fc
.Ft int
.Fn cnd_wait "cnd_t *cond" "mtx_t *mtx"
.Sh DESCRIPTION
The
.Fn cnd_broadcast
function unblocks all threads that are blocked on a condition variable
.Fa cond
at the time of the call.
If no thread is blocked on the
.Fa cond
condition variable at the time of the call,
the function does nothing and returns success.
.Pp
The
.Fn cnd_destroy
function destroys the
.Fa cond
condition variable.
.Pp
The
.Fn cnd_init
function initializes a new
.Fa cond
variable.
.Pp
The
.Fn cnd_signal
function unblock one thread that currently waits on the
.Fa cond
variable.
If there are no threads blocked,
.Fn cnd_signal
does nothing and returns success.
.Pp
The
.Fn cnd_timedwait
function atomically unlocks the mutex
.Fa mtx
and blocks on the condition variable
.Fa cond
until a thread is signalled by a call to
.Fn cnd_signal
or
.Fn cnd_broadcast
or timeout
.Fa ts
has been reached.
The
.Fa ts
parameter is specified as
.Dv TIME_UTC
based calendar time.
If the mutex is not locked by the calling thread then behavior is undefined.
.Pp
The
.Fn cnd_wait
function atomically unlocks the mutex
.Fa mtx
and tries to block on the conditional variable
.Fa cond
until a thread is signalled by a call to
.Fn cnd_signal
or
.Fn cnd_broadcast .
The
.Fa mtx
mutex is locked again before the function returns.
If the mutex is not locked by the calling thread then behavior is undefined.
.Sh RETURN VALUES
The
.Fn cnd_broadcast
function returns
.Dv thrd_success
on success or
.Dv thrd_error
on failure.
.Pp
The
.Fn cnd_destroy
function returns no value.
.Pp
The
.Fn cnd_init
function returns
.Dv thrd_success
on success or
.Dv thrd_error
on failure.
.Pp
The
.Fn cnd_signal
function returns
.Dv thrd_success
on success or
.Dv thrd_error
on failure.
.Pp
The
.Fn cnd_timedwait
function returns
.Dv thrd_success
on success, otherwise
.Dv thrd_timedout
to indicate that system time has reached or exceeded the time specified in
.Dv ts ,
or
.Dv thrd_error
on failure.
.Pp
The
.Fn cnd_wait
function returns
.Dv thrd_success
on success or
.Dv thrd_error
on failure.
.Sh SEE ALSO
.Xr pthread_cond 3 ,
.Xr threads 3
.Sh STANDARDS
The
.Nm
interface conforms to
.St -isoC-2011 .
.Sh HISTORY
This interface first appeared in
.Nx 9 .
.Sh AUTHORS
.An Kamil Rytarowski Aq Mt kamil@NetBSD.org