diff options
Diffstat (limited to 'usr/src/man/man3c')
-rw-r--r-- | usr/src/man/man3c/Makefile | 57 | ||||
-rw-r--r-- | usr/src/man/man3c/aligned_alloc.3c | 74 | ||||
-rw-r--r-- | usr/src/man/man3c/call_once.3c | 89 | ||||
-rw-r--r-- | usr/src/man/man3c/cnd.3c | 183 | ||||
-rw-r--r-- | usr/src/man/man3c/mtx.3c | 216 | ||||
-rw-r--r-- | usr/src/man/man3c/nanosleep.3c | 57 | ||||
-rw-r--r-- | usr/src/man/man3c/quick_exit.3c | 92 | ||||
-rw-r--r-- | usr/src/man/man3c/thrd_create.3c | 90 | ||||
-rw-r--r-- | usr/src/man/man3c/thrd_current.3c | 46 | ||||
-rw-r--r-- | usr/src/man/man3c/thrd_detach.3c | 56 | ||||
-rw-r--r-- | usr/src/man/man3c/thrd_equal.3c | 56 | ||||
-rw-r--r-- | usr/src/man/man3c/thrd_exit.3c | 64 | ||||
-rw-r--r-- | usr/src/man/man3c/thrd_join.3c | 81 | ||||
-rw-r--r-- | usr/src/man/man3c/thrd_yield.3c | 38 | ||||
-rw-r--r-- | usr/src/man/man3c/timespec_get.3c | 81 | ||||
-rw-r--r-- | usr/src/man/man3c/tss.3c | 151 |
16 files changed, 1410 insertions, 21 deletions
diff --git a/usr/src/man/man3c/Makefile b/usr/src/man/man3c/Makefile index 5348d83bf8..67861882e4 100644 --- a/usr/src/man/man3c/Makefile +++ b/usr/src/man/man3c/Makefile @@ -14,7 +14,7 @@ # Copyright 2013 Nexenta Systems, Inc. All rights reserved. # Copyright 2013, OmniTI Computer Consulting, Inc. All rights reserved. # Copyright 2014 Garrett D'Amore <garrett@damore.org> -# Copyright (c) 2015, Joyent, Inc. All rights reserved. +# Copyright 2016 Joyent, Inc. # include $(SRC)/Makefile.master @@ -40,6 +40,7 @@ MANFILES= __fbufsize.3c \ aiocancel.3c \ aioread.3c \ aiowait.3c \ + aligned_alloc.3c \ arc4random.3c \ assert.3c \ atexit.3c \ @@ -58,6 +59,7 @@ MANFILES= __fbufsize.3c \ bsearch.3c \ bstring.3c \ btowc.3c \ + call_once.3c \ catgets.3c \ catopen.3c \ cfgetispeed.3c \ @@ -68,6 +70,7 @@ MANFILES= __fbufsize.3c \ clock_settime.3c \ closedir.3c \ closefrom.3c \ + cnd.3c \ cond_init.3c \ confstr.3c \ crypt.3c \ @@ -249,6 +252,7 @@ MANFILES= __fbufsize.3c \ mq_setattr.3c \ mq_unlink.3c \ msync.3c \ + mtx.3c \ mutex_init.3c \ nanosleep.3c \ ndbm.3c \ @@ -362,6 +366,7 @@ MANFILES= __fbufsize.3c \ putspent.3c \ putws.3c \ qsort.3c \ + quick_exit.3c \ raise.3c \ rand.3c \ random.3c \ @@ -471,11 +476,19 @@ MANFILES= __fbufsize.3c \ thr_stksegment.3c \ thr_suspend.3c \ thr_yield.3c \ + thrd_create.3c \ + thrd_current.3c \ + thrd_detach.3c \ + thrd_equal.3c \ + thrd_exit.3c \ + thrd_join.3c \ + thrd_yield.3c \ timer_create.3c \ timer_delete.3c \ timer_settime.3c \ timeradd.3c \ timerfd_create.3c \ + timespec_get.3c \ tmpfile.3c \ tmpnam.3c \ toascii.3c \ @@ -485,6 +498,7 @@ MANFILES= __fbufsize.3c \ towupper.3c \ truncate.3c \ tsearch.3c \ + tss.3c \ ttyname.3c \ ttyslot.3c \ u8_strcmp.3c \ @@ -565,6 +579,7 @@ MANLINKS= FD_CLR.3c \ asctime.3c \ asctime_r.3c \ asprintf.3c \ + at_quick_exit.3c \ atof.3c \ atoi.3c \ atol.3c \ @@ -696,6 +711,12 @@ MANLINKS= FD_CLR.3c \ clock_getres.3c \ clock_gettime.3c \ closelog.3c \ + cnd_broadcast.3c \ + cnd_destroy.3c \ + cnd_init.3c \ + cnd_signal.3c \ + cnd_timedwait.3c \ + cnd_wait.3c \ cond_broadcast.3c \ cond_destroy.3c \ cond_reltimedwait.3c \ @@ -954,6 +975,12 @@ MANLINKS= FD_CLR.3c \ mq_timedreceive.3c \ mq_timedsend.3c \ mrand48.3c \ + mtx_destroy.3c \ + mtx_init.3c \ + mtx_lock.3c \ + mtx_timedlock.3c \ + mtx_trylock.3c \ + mtx_unlock.3c \ munlock.3c \ munlockall.3c \ mutex_consistent.3c \ @@ -1210,6 +1237,7 @@ MANLINKS= FD_CLR.3c \ thr_setconcurrency.3c \ thr_setprio.3c \ thr_setspecific.3c \ + thrd_sleep.3c \ timegm.3c \ timer_getoverrun.3c \ timer_gettime.3c \ @@ -1226,6 +1254,10 @@ MANLINKS= FD_CLR.3c \ towctrans_l.3c \ towlower_l.3c \ towupper_l.3c \ + tss_create.3c \ + tss_delete.3c \ + tss_get.3c \ + tss_set.3c \ ttyname_r.3c \ twalk.3c \ tzset.3c \ @@ -1366,6 +1398,8 @@ aiowrite.3c := LINKSRC = aioread.3c arc4random_buf.3c := LINKSRC = arc4random.3c arc4random_uniform.3c := LINKSRC = arc4random.3c +at_quick_exit.3c := LINKSRC = quick_exit.3c + atomic_add_16.3c := LINKSRC = atomic_add.3c atomic_add_16_nv.3c := LINKSRC = atomic_add.3c atomic_add_32.3c := LINKSRC = atomic_add.3c @@ -1499,6 +1533,13 @@ clock_gettime.3c := LINKSRC = clock_settime.3c fdwalk.3c := LINKSRC = closefrom.3c +cnd_broadcast.3c := LINKSRC = cnd.3c +cnd_destroy.3c := LINKSRC = cnd.3c +cnd_init.3c := LINKSRC = cnd.3c +cnd_signal.3c := LINKSRC = cnd.3c +cnd_timedwait.3c := LINKSRC = cnd.3c +cnd_wait.3c := LINKSRC = cnd.3c + cond_broadcast.3c := LINKSRC = cond_init.3c cond_destroy.3c := LINKSRC = cond_init.3c cond_reltimedwait.3c := LINKSRC = cond_init.3c @@ -1891,12 +1932,21 @@ mq_timedreceive.3c := LINKSRC = mq_receive.3c mq_reltimedsend_np.3c := LINKSRC = mq_send.3c mq_timedsend.3c := LINKSRC = mq_send.3c +mtx_destroy.3c := LINKSRC = mtx.3c +mtx_init.3c := LINKSRC = mtx.3c +mtx_lock.3c := LINKSRC = mtx.3c +mtx_timedlock.3c := LINKSRC = mtx.3c +mtx_trylock.3c := LINKSRC = mtx.3c +mtx_unlock.3c := LINKSRC = mtx.3c + mutex_consistent.3c := LINKSRC = mutex_init.3c mutex_destroy.3c := LINKSRC = mutex_init.3c mutex_lock.3c := LINKSRC = mutex_init.3c mutex_trylock.3c := LINKSRC = mutex_init.3c mutex_unlock.3c := LINKSRC = mutex_init.3c +thrd_sleep.3c := LINKSRC = nanosleep.3c + dbm_clearerr.3c := LINKSRC = ndbm.3c dbm_close.3c := LINKSRC = ndbm.3c dbm_delete.3c := LINKSRC = ndbm.3c @@ -2278,6 +2328,11 @@ tdelete.3c := LINKSRC = tsearch.3c tfind.3c := LINKSRC = tsearch.3c twalk.3c := LINKSRC = tsearch.3c +tss_create.3c := LINKSRC = tss.3c +tss_delete.3c := LINKSRC = tss.3c +tss_get.3c := LINKSRC = tss.3c +tss_set.3c := LINKSRC = tss.3c + ttyname_r.3c := LINKSRC = ttyname.3c uconv_u16tou8.3c := LINKSRC = uconv_u16tou32.3c diff --git a/usr/src/man/man3c/aligned_alloc.3c b/usr/src/man/man3c/aligned_alloc.3c new file mode 100644 index 0000000000..d3c6f43c32 --- /dev/null +++ b/usr/src/man/man3c/aligned_alloc.3c @@ -0,0 +1,74 @@ +.\" +.\" This file and its contents are supplied under the terms of the +.\" Common Development and Distribution License ("CDDL"), version 1.0. +.\" You may only use this file in accordance with the terms of version +.\" 1.0 of the CDDL. +.\" +.\" A full copy of the text of the CDDL should have accompanied this +.\" source. A copy of the CDDL is also available via the Internet at +.\" http://www.illumos.org/license/CDDL. +.\" +.\" +.\" Copyright 2016 Joyent, Inc. +.\" +.Dd "Mar 26, 2016" +.Dt ALIGNED_ALLOC 3C +.Os +.Sh NAME +.Nm aligned_alloc +.Nd aligned memory allocation +.Sh SYNOPSIS +.In stdlib.h +.Ft "void *" +.Fo aligned_alloc +.Fa "size_t alignment" +.Fa "size_t size" +.Fc +.Sh DESCRIPTION +The +.Fn aligned_alloc +function allocates +.Fa size +bytes aligned on the specified alignment boundary +.Fa alignment . +The value of +.Fa alignment +is constrained, it must be a power of two and it must be greater than or +equal to the size of a word on the platform. +.Sh RETURN VALUES +Upon successful completion, the +.Fn aligned_alloc +function returns a pointer to suitably aligned memory at least +.Fa size +bytes large. Otherwise, a +.Sy NULL +pointer is returned and +.Sy errno +is set to indicate the error. +.Sh ERRORS +The +.Fn aligned_alloc +function will fail if: +.Bl -tag -width Er +.It Er ENOMEM +The physical limits of the system are exceeded by +.Fa size +bytes of memory which cannot be allocated. +.It Er EAGAIN +There is not enough memory available to allocate +.Fa size +bytes of memory; but the application could try again later. +.It Er EINVAL +An invalid value for +.Fa alignment +was passed in. It is not a power of two multiple of the word size. +.El +.Sh INTERFACE STABILITY +.Sy STANDARD +.Sh MT-LEVEL +.Sy MT-Safe +.Sh SEE ALSO +.Xr malloc 3C , +.Xr memalgin 3C , +.Xr posix_memalign 3C , +.Xr attributes 5 diff --git a/usr/src/man/man3c/call_once.3c b/usr/src/man/man3c/call_once.3c new file mode 100644 index 0000000000..5cc1ba56a9 --- /dev/null +++ b/usr/src/man/man3c/call_once.3c @@ -0,0 +1,89 @@ +.\" +.\" This file and its contents are supplied under the terms of the +.\" Common Development and Distribution License ("CDDL"), version 1.0. +.\" You may only use this file in accordance with the terms of version +.\" 1.0 of the CDDL. +.\" +.\" A full copy of the text of the CDDL should have accompanied this +.\" source. A copy of the CDDL is also available via the Internet at +.\" http://www.illumos.org/license/CDDL. +.\" +.\" +.\" Copyright 2016 Joyent, Inc. +.\" +.Dd "Jan 11, 2015" +.Dt CALL_ONCE 3C +.Os +.Sh NAME +.Nm call_once +.Nd ensure function is only called once +.Sh SYNOPSIS +.In treads.h +.Vt "once_flag once = ONCE_FLAG_INIT;" +.Ft void +.Fo call_once +.Fa "once_flag *once" +.Fa "void (*func)(void)" +.Fc +.Sh DESCRIPTION +The +.Fn call_once +function is used to ensure that an operation occurs only once, even +across multiple threads. Each instance of a properly initialized +.Ft once_flag +can be pased to the +.Ft call_once +function; however, only a single caller will successfully execute the +specified function, +.Fa func . +This ensures that the argument +.Fa func +is called only once. Note, the argument +.Fa once +is the only thing used as a point of synchronization. If multiple +callers use the same pointer for +.Fa once , +but use different values for +.Fa func , +then only one of the functions will be successfully called. +.Pp +The argument +.Fn once +should always be initialized to the symbol +.Sy ONCE_FLAG_INIT +before calling +.Fn call_once . +Failure to do so will result in undefined behavior. +.Pp +Like +.Xr pthread_once 3C , +the +.Fn call_once +function is not itself a cancellation point; however, if the thread +calling +.Fn func +encounters a cancellation point and is cancelled, then the value pointed +to by +.Fa once +will be as though +.Fn call_once +had not been called, as +.Fn func +had not completed successfully. +.Sh RETURN VALUES +The +.Fn call_once +function does not return any values. Upon its completion, it is guaranteed that +.Fa func +will have been called at most once across the liftime of the +.Fa once +argument . +.Sh INTERFACE STABILITY +.Sy Standard +.Sh MT-LEVEL +.Sy MT-Safe +.Sh SEE ALSO +.Xr pthread_once 3C , +.Xr threads.h 3HEAD , +.Xr attributes 5 , +.Xr threads 5 diff --git a/usr/src/man/man3c/cnd.3c b/usr/src/man/man3c/cnd.3c new file mode 100644 index 0000000000..7e2ce29d66 --- /dev/null +++ b/usr/src/man/man3c/cnd.3c @@ -0,0 +1,183 @@ +.\" +.\" This file and its contents are supplied under the terms of the +.\" Common Development and Distribution License ("CDDL"), version 1.0. +.\" You may only use this file in accordance with the terms of version +.\" 1.0 of the CDDL. +.\" +.\" A full copy of the text of the CDDL should have accompanied this +.\" source. A copy of the CDDL is also available via the Internet at +.\" http://www.illumos.org/license/CDDL. +.\" +.\" +.\" Copyright 2016 Joyent, Inc. +.\" +.Dd "Jan 11, 2015" +.Dt CND 3C +.Os +.Sh NAME +.Nm cnd +.Nm cnd_broadcast , +.Nm cnd_destroy , +.Nm cnd_init , +.Nm cnd_signal , +.Nm cnd_timedwait , +.Nm cnd_wait +.Nd C11 condition variable functions +.Sh SYNOPSIS +.In threads.h +.Ft int +.Fo cnd_init +.Fa "cnd_t *cnd" +.Fc +.Ft void +.Fo cnd_destroy +.Fa "cnd_t *cnd" +.Fc +.Ft int +.Fo cnd_broadcast +.Fa "cnd_t *cnd" +.Fc +.Ft int +.Fo cnd_signal +.Fa "cnd_t *cnd" +.Fc +.Ft int +.Fo cnd_timedwait +.Fa "cnd_t *restrict cnd" +.Fa "mtx_t *restrict mtx" +.Fa "const struct timespec *abstime" +.Fc +.Ft int +.Fo cnd_wait +.Fa "cnd_t *restrict cnd" +.Fa "mtx_t *restrict mtx" +.Fc +.Sh DESCRIPTION +The +.Sy cnd +family of functions implement condition variables which allow threads +within a process to wait until a condition occurs and be signaled when +it does. These functions behave similar to both the POSIX threads and +illumos threads; however, they have slightly different call signatures +and return values. For more information, see +.Xr threads 5 . +Importantly, they do not allow for inter-process synchronization. +.Ss Creating and Destroy Condition Variables +The function +.Fn cnd_init +initializes the condition variable referred to by +.Fa cnd . +The condition variable is suitable for intra-process use. Initializing +an already initialized condition variable results in undefined behavior. +.Pp +The function +.Fn cnd_destroy +destroys an initialized condition variable at which point it is illegal +to use it, though it may be initialized again. +.Ss Condition Waiting +The function +.Fn cond_wait +can be used to wait on a condition variable. A thread that waits on a +condition variable blocks until another thread signals that the +condition has changed, generally after making the condition that was +false, true. +.Pp +The function +.Fn cond_wait +atomically release the mutex pointed to by +.Fa mtx +and blocks on the condition variable +.Fa cond . +When the thread returns, it will once again be holding +.Fa mtx +and must check the current state of the condition. There is no +guarantee that another thread has not gotten in and changed the value +before being woken. In addition, a thread blocking on a condition +variable, may be woken spuriously, such as when a signal is received or +.Fn fork +is called . +.Pp +The function +.Fn cond_timedwait +allows a thread to block in a similar fashion to +.Fn cond_wait , +except that when the absolute time specified in seconds since the epoch +(based on +.Sy CLOCK_REALTIME ) +in UTC, expires, then the thread will be woken up. The timeout is +specified in +.Fa abstime . +.Ss Conditional Signaling +The +.Fn cnd_signal +and +.Fn cnd_broadcast +functions can be used to signal threads waiting on the condition variable +.Fa cnd +that they should be woken up and check the variable again. The +.Fn cnd_signal +function will only wake a single thread that is blocked on the +condition variable +.Fa cnd ; +while +.Fn cnd_broadcast +will wake up every thread waiting on the condition variable +.Fa cnd . +.Pp +A thread calling either +.Fn cnd_signal +or +.Fn cnd_broadcast +is not required to hold any of the mutexes that are associated with the +condition variable. +.Pp +If there are no threads currently blocked in the condition variable +.Fa cnd +then neither function has an effect. +.Sh RETURN VALUES +Upon successful completion, the +.Fn cond_init +function returns +.Sy thrd_success. +If insufficient memory was available, then +.Sy thrd_nomem +is returned; otherwise, if any other error occurred, +.Sy thrd_error +is returned. +.Pp +Upon successful completion, the +.Fn cond_broadcast , +.Fn cond_signal , +and +.Fn cond_wait +functions return +.Sy thrd_success . +Otherwise, they return +.Sy thrd_error +to indicate that an error occurred and they were unable to complete. +.Pp +Upon successful completion, the +.Fn cond_timedwait +function returns +.Sy thrd_success . +If +.Fa abstime +expires without being signaled, it instead returns +.Sy thrd_timedout . +Otherwise, +.Sy thrd_error +is returned to indicate an error. +.Sh INTERFACE STABILITY +.Sy Standard +.Sh MT-LEVEL +.Sy MT-Safe +.Sh SEE ALSO +.Xr cond_braodcast 3C , +.Xr cond_destroy 3C , +.Xr cond_init 3C , +.Xr cond_signal 3C , +.Xr cond_timedwait 3C , +.Xr cond_wait 3C , +.Xr threads 3HEAD , +.Xr attributes 5 , +.Xr threads 5 diff --git a/usr/src/man/man3c/mtx.3c b/usr/src/man/man3c/mtx.3c new file mode 100644 index 0000000000..7a2a89b11e --- /dev/null +++ b/usr/src/man/man3c/mtx.3c @@ -0,0 +1,216 @@ +.\" +.\" This file and its contents are supplied under the terms of the +.\" Common Development and Distribution License ("CDDL"), version 1.0. +.\" You may only use this file in accordance with the terms of version +.\" 1.0 of the CDDL. +.\" +.\" A full copy of the text of the CDDL should have accompanied this +.\" source. A copy of the CDDL is also available via the Internet at +.\" http://www.illumos.org/license/CDDL. +.\" +.\" +.\" Copyright 2016 Joyent, Inc. +.\" +.Dd "Jan 11, 2015" +.Dt MTX 3C +.Os +.Sh NAME +.Nm mtx , +.Nm mtx_destroy , +.Nm mtx_init , +.Nm mtx_lock , +.Nm mtx_timedlock , +.Nm mtx_trylock , +.Nm mtx_unlock +.Nd C11 mutex operations +.Sh SYNOPSIS +.In threads.h +.Ft int +.Fo mtx_init +.Fa "mtx_t *mtx" +.Fa "int type" +.Fc +.Ft void +.Fo mtx_destroy +.Fa "mtx_t *mtx" +.Fc +.Ft int +.Fo mtx_lock +.Fa "mtx_t *mtx" +.Fc +.Ft int +.Fo mtx_timedlock +.Fa "mtx_t *mtx" +.Fa "const struct timespec *restrict ts" +.Fc +.Ft int +.Fo mtx_trylock +.Fa "mtx_t *mtx" +.Fc +.Ft int +.Fo mtx_unlock +.Fa "mtx_t *mtx" +.Fc +.Sh DESCRIPTION +The +.Sy mtx +family of functions implement mutual exclusion locks (mutexes) and behave +similarly to both POSIX threads and illumos threads; however, they have +slightly different call signatures and return values. For more +information, see +.Xr threads 5 . +Importantly, they do not allow for inter-process synchronization. +.Ss Creating and Destroying Mutexes +The +.Fn mtx_init +function initializes the mutex specified by +.Fa mtx . +The following types of mutexes are valid and may be specified by the +.Fa type +argument: +.Bl -tag -width Dv +.It Sy mtx_plain +A simple, intra-process mutex. +.It Sy mtx_timed +A simple, intra-process mutex, which allows timed locking operations. +.It Sy mtx_plain | mtx_recursive +An intra-process mutex that may be acquired recursively by the same +thread. It must be unlocked an equal number of times that it is locked. +.It Sy mtx_timed | mtx_recursive +An intra-process mutex that supports timed locking operations and may be +acquired recursively by the same thread. It must be unlocked an equal +number of times that it is locked. +.El +For more information on the different kind of mutexes, see +.Xr mutex_init 3C . +.Pp +The +.Fn mtx_destroy +function destroys the mutex pointed to by +.Fa mtx . +It is illegal for threads to be blocked waiting for +.Fa mtx +when +.Fn mtx_destroy +is called . +.Ss Locking and Unlocking Mutexes +The +.Fn mtx_lock +function attempts to lock the mutex +.Fa mtx . +When the function returns, it will be the sole owner of the mutex and +must call +.Fn mtx_unlock +when it is done, or risk inducing a deadlock in the process. Other +threads that make calls to +.Fn mtx_lock +after another thread has successfully completed its call to +.Fn mtx_lock +will block. +When they finally return, then they will have obtained the mutex +.Fa mtx . +.Pp +Unless a lock of type +.Sy mtx_recursive +was created, a thread calling +.Fn mtx_lock +when it already holds +.Fa mtx +will cause the thread to deadlock. Othewrise, the lock will be +successfully taken again. However, a thread must call +.Fn mtx_unlock +for each time that it has acquried +.Fa mtx . +.Pp +The +.Fn mtx_trylock +function will attempt to obtain the mutex pointed to by +.Fa mtx . +However, unlike +.Fn mtx_lock , +if +.Fa mtx +is locked, then it will not block and wait for +.Fa mtx +and instead return +.Sy thrd_busy +to indicate that the lock is currently held. +.Pp +The +.Fn mtx_timedlock +function attempts to obtain the mutex pointed to by +.Fa mtx . +If it is unable to obtain it, then it will block for a set amount of +time dictated by +.Fa ts . +The timeout in +.Fa ts +is treated as an absolute time in UTC to block until, measured based on +the +.Sy CLOCK_REALTIME +clock. +.Pp +The +.Fn mtx_unlock +function unlocks the mutex pointed to by +.Fa mtx , +which allows another thread the opportunity to obtain it. If any threads +are actively blocking on the mutex, one of them will obtain it and be +woken up. It is an error to call +.Fn mtx_unlock +on a mutex which the calling thread does not currently own. +.Sh RETURN VALUES +Upon successful completion, the function +.Fn mtx_init returns +.Sy thrd_success. +If there was insufficient memory to create the thread, +it instead returns +.Sy thrd_nomem . +If any other error occurred, it returns +.Sy thrd_error . +.Pp +The functions +.Fn mtx_lock , +and +.Fn mtx_unlock +return +.Sy thrd_success . +If they were unable to successfully complete the operation, they instead +return +.Sy thrd_error . +.Pp +Upon sucessful completion, the +.Fn mtx_timedlock +function returns +.Sy thrd_success . +If the timeout is reached and the calling thread is unable to obtain the +mutex, then +.Sy thrd_timedout +is returned . +If any other error occurs, then +.Sy thrd_error is returned. +.Pp +Upon successful completion, the +.Fn mtx_trylock +function returns +.Sy thrd_success . +If the thread was unable to obtain the mutex because another thread owns +it, then it returns +.Sy thrd_busy . +Otherwise, an error will have occurred and +.Sy thrd_error +is returned. +.Sh INTERFACE STABILITY +.Sy Standard +.Sh MT-LEVEL +.Sy MT-Safe +.Sh SEE ALSO +.Xr mutex_init 3C , +.Xr pthread_mutex_destroy 3C , +.Xr pthread_mutex_init 3C , +.Xr pthread_mutex_lock 3C , +.Xr pthread_mutex_timedlock 3C , +.Xr pthread_mutex_trylock 3C , +.Xr pthread_mutex_unlock 3C , +.Xr threads.h 3HEAD , +.Xr attributes 5 diff --git a/usr/src/man/man3c/nanosleep.3c b/usr/src/man/man3c/nanosleep.3c index fbfc47dd45..617cc35555 100644 --- a/usr/src/man/man3c/nanosleep.3c +++ b/usr/src/man/man3c/nanosleep.3c @@ -1,5 +1,6 @@ '\" te .\" Copyright (c) 2008, Sun Microsystems, Inc. All Rights Reserved. +.\" Copyright 2016 Joyent, Inc. .\" Copyright 1989 AT&T .\" Portions Copyright (c) 1992, X/Open Company Limited All Rights Reserved .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at @@ -9,9 +10,9 @@ .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License. .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner] -.TH NANOSLEEP 3C "Feb 5, 2008" +.TH NANOSLEEP 3C "Mar 27, 2016" .SH NAME -nanosleep \- high resolution sleep +nanosleep, thrd_sleep \- high resolution sleep .SH SYNOPSIS .LP .nf @@ -21,27 +22,32 @@ nanosleep \- high resolution sleep \fBstruct timespec *\fR\fIrmtp\fR); .fi +.nf +#include <threads.h> + +\fBint\fR \fBthrd_sleep\fR(\fBconst struct timespec *\fR\fIrqtp\fR, + \fBstruct timespec *\fR\fIrmtp\fR); + .SH DESCRIPTION -.sp .LP -The \fBnanosleep()\fR function causes the current thread to be suspended from -execution until either the time interval specified by the \fIrqtp\fR argument -has elapsed or a signal is delivered to the calling thread and its action is to -invoke a signal-catching function or to terminate the process. The suspension -time may be longer than requested because the argument value is rounded up to -an integer multiple of the sleep resolution or because of the scheduling of -other activity by the system. But, except for the case of being interrupted by -a signal, the suspension time will not be less than the time specified by -\fIrqtp\fR, as measured by the system clock, \fBCLOCK_REALTIME\fR. +The \fBnanosleep()\fR and \fBthrd_sleep()\fR functions cause the current thread +to be suspended from execution until either the time interval specified by the +\fIrqtp\fR argument has elapsed or a signal is delivered to the calling thread +and its action is to invoke a signal-catching function or to terminate the +process. The suspension time may be longer than requested because the argument +value is rounded up to an integer multiple of the sleep resolution or because of +the scheduling of other activity by the system. But, except for the case of +being interrupted by a signal, the suspension time will not be less than the +time specified by \fIrqtp\fR, as measured by the system clock, +\fBCLOCK_REALTIME\fR. .sp .LP -The use of the \fBnanosleep()\fR function has no effect on the action or -blockage of any signal. +The use of the \fBnanosleep()\fR and \fBthrd_sleep()\fR functions has no effect +on the action or blockage of any signal. .SH RETURN VALUES -.sp .LP -If the \fBnanosleep()\fR function returns because the requested time has -elapsed, its return value is \fB0\fR. +If the \fBnanosleep()\fR or \fBthrd_sleep()\fR function returns because the +requested time has elapsed, its return value is \fB0\fR. .sp .LP If the \fBnanosleep()\fR function returns because it has been interrupted by a @@ -55,9 +61,22 @@ returned. .LP If \fBnanosleep()\fR fails, it returns \fB\(mi1\fR and sets \fBerrno\fR to indicate the error. -.SH ERRORS .sp .LP + +The +.B thrd_sleep() +function may fail for identical reasons as the +.B nanosleep() +function and returns \(mi1; however, the C11 standard does not define that +.B errno +should be set, therefore callers of \fBthrd_sleep()\fR cannot rely on +.B errno +being set or staying the same across a call to +.B thrd_sleep() . + +.SH ERRORS +.LP The \fBnanosleep()\fR function will fail if: .sp .ne 2 @@ -88,7 +107,6 @@ The \fBnanosleep()\fR function is not supported by this implementation. .RE .SH ATTRIBUTES -.sp .LP See \fBattributes\fR(5) for descriptions of the following attributes: .sp @@ -108,6 +126,5 @@ Standard See \fBstandards\fR(5). .TE .SH SEE ALSO -.sp .LP \fBsleep\fR(3C), \fBtime.h\fR(3HEAD), \fBattributes\fR(5), \fBstandards\fR(5) diff --git a/usr/src/man/man3c/quick_exit.3c b/usr/src/man/man3c/quick_exit.3c new file mode 100644 index 0000000000..e3e17603b4 --- /dev/null +++ b/usr/src/man/man3c/quick_exit.3c @@ -0,0 +1,92 @@ +.\" +.\" This file and its contents are supplied under the terms of the +.\" Common Development and Distribution License ("CDDL"), version 1.0. +.\" You may only use this file in accordance with the terms of version +.\" 1.0 of the CDDL. +.\" +.\" A full copy of the text of the CDDL should have accompanied this +.\" source. A copy of the CDDL is also available via the Internet at +.\" http://www.illumos.org/license/CDDL. +.\" +.\" +.\" Copyright 2016 Joyent, Inc. +.\" +.Dd "Mar 26, 2016" +.Dt QUICK_EXIT 3C +.Os +.Sh NAME +.Nm at_quick_exit , +.Nm quick_exit +.Nd terminate a running process with minimal teardown +.Sh SYNOPSIS +.In stdlib.h +.Ft int +.Fo at_quick_exit +.Fa "void (*func)(void)" +.Fc +.Ft _Noreturn void +.Fo quick_exit +.Fa "int status" +.Fc +.Sh DESCRIPTION +The +.Fn quick_exit +and +.Fn at_quick_exit +functions provide a veneer around +.Xr _Exit 3C +that allows for registered functions to be called before terminating. +Like +.Xr _Exit 3C , +standard library termination is not done. +.Xr atexit 3C +functions are not called and various standard termination that occurs +when calling +.Xr exit 3C +may not occur. +.Pp +Functions that are registered with +.Fn at_quick_exit +will be called in reverse order upon calling +.Fn quick_exit . +Functions registered with +.Fn at_quick_exit +will not be called at any other time. Functions that are registered with +.Fn at_quick_exit +should not make use of +.Xr longjump 3C +and related functions. +.Pp +After calling all registered functions, the +.Fn quick_exit +function will terminate the calling program and its exit status will be +.Fa status . +.Sh RETURN VALUES +The +.Fn quick_exit +function does not return. +.Pp +The +.Fn at_quick_exit +function returns +.Sy 0 +on success. Otherwise, a non-zero error value is returned to indicate +failure. +.Sh ERRORS +The +.Fn at_quick_exit +function may fail if: +.Bl -tag -width Er +.It Er ENOMEM +Insufficient storage space is available. +.El +.Sh INTERFACE STABILITY +.Sy Standard +.Sh MT-LEVEL +.Sy Safe +.Sh SEE ALSO +.Xr _Exit 3C , +.Xr atexit 3C , +.Xr exit 3C , +.Xr attributes 5 , +.Xr standards 5 diff --git a/usr/src/man/man3c/thrd_create.3c b/usr/src/man/man3c/thrd_create.3c new file mode 100644 index 0000000000..ffaf9bf11c --- /dev/null +++ b/usr/src/man/man3c/thrd_create.3c @@ -0,0 +1,90 @@ +.\" +.\" This file and its contents are supplied under the terms of the +.\" Common Development and Distribution License ("CDDL"), version 1.0. +.\" You may only use this file in accordance with the terms of version +.\" 1.0 of the CDDL. +.\" +.\" A full copy of the text of the CDDL should have accompanied this +.\" source. A copy of the CDDL is also available via the Internet at +.\" http://www.illumos.org/license/CDDL. +.\" +.\" +.\" Copyright 2016 Joyent, Inc. +.\" +.Dd "Jan 13, 2015" +.Dt THRD_CREATE 3C +.Os +.Sh NAME +.Nm thrd_create +.Nd create a thread +.Sh SYNOPSIS +.In threads.h +.Vt "typedef int (*thrd_start_t)(void *);" +.Ft int +.Fo thrd_create +.Fa "thrd_t *thrdp" +.Fa "thrd_start_t func" +.Fa "void *arg" +.Fc +.Sh DESCRIPTION +The +.Fn thrd_create +function creates a new thread of execution inside of the current +process and stores its identifier in +.Fa thrdp . +Each thread operates concurrently within the process. +.Pp +When a thread is created, it begins its execution at the function +.Fa func +with the argument +.Fa arg . +A created thread has access to all global data within a process; +however, it has its own private stack. Currently 32-bit processes have a +default stack of 1 megabyte, while 64-bit systems have a default stack +size of 2 megabytes. In addition, newly created threads inherit the +signal mask of the thread which created them; however, they do not +inherit any pending signals. +.Pp +Once created, a thread will continue to execute until either, it returns +from its initial function, the thread explicitly calls +.Xr thrd_exit 3C , +or the process itself terminates, such as with a call to +.Xr exit 2 . +When the initial function returns, it behaves as though a call to +.Xr thrd_exit +was made, and, if the thread has not been detached with a call to +.Xr thrd_detach, +the exit status remains available and the corresponding thread ID will +not be reused until a process calls +.Xr thrd_join 3C . +This is similar to how a parent must call +.Xr wait 2 , +to clean up a child process that has terminated. +.Pp +For a richer interface interface with more control over aspects of the +newly created thread, such as stack size, stack placement, and the like, +see +.Xr thr_create 3C +and +.Xr pthread_create 3C . +.Sh RETURN VALUES +Upon successful completion, the +.Fn thrd_create +function returns +.Sy thrd_success . +If insufficient memory was available, then +.Sy thrd_nomem +is returned. Otherwise, +.Sy thrd_error +is returned, indicating that a non-memory related error. +.Sh INTERFACE STABILITY +.Sy Standard +.Sh MT-LEVEL +.Sy MT-Safe +.Sh SEE ALSO +.Xr pthread_create 3C , +.Xr thr_create 3C , +.Xr thrd_detach 3C , +.Xr thrd_join 3C , +.Xr attributes 5 , +.Xr threads 5 diff --git a/usr/src/man/man3c/thrd_current.3c b/usr/src/man/man3c/thrd_current.3c new file mode 100644 index 0000000000..9cc41795ab --- /dev/null +++ b/usr/src/man/man3c/thrd_current.3c @@ -0,0 +1,46 @@ +.\" +.\" This file and its contents are supplied under the terms of the +.\" Common Development and Distribution License ("CDDL"), version 1.0. +.\" You may only use this file in accordance with the terms of version +.\" 1.0 of the CDDL. +.\" +.\" A full copy of the text of the CDDL should have accompanied this +.\" source. A copy of the CDDL is also available via the Internet at +.\" http://www.illumos.org/license/CDDL. +.\" +.\" +.\" Copyright 2016 Joyent, Inc. +.\" +.Dd "Jan 11, 2015" +.Dt THRD_CURRENT 3C +.Os +.Sh NAME +.Nm thrd_current +.Nd obtain current thread's ID +.Sh SYNOPSIS +.In threads.h +.Ft thrd_t +.Fo thrd_current +.Fa void +.Fc +.Sh DESCRIPTION +The +.Fn thrd_current +function returns the thread ID of the current calling thread. Note, this +ID may be different from the thread ID returned when using +.Xr thr_self 3C +or +.Xr pthread_self 3C ; +however, it still uniquely identifies the thread. +.Sh ERRORS +No errors are defined. +.Sh INTERFACE STABILITY +.Sy Standard +.Sh MT-Level +.Sy MT-Safe +.Sh SEE ALSO +.Xr pthread_self 3C , +.Xr thr_self 3C , +.Xr thrd_create 3C , +.Xr attributes 5 , +.Xr threads 5 diff --git a/usr/src/man/man3c/thrd_detach.3c b/usr/src/man/man3c/thrd_detach.3c new file mode 100644 index 0000000000..8749b53c1b --- /dev/null +++ b/usr/src/man/man3c/thrd_detach.3c @@ -0,0 +1,56 @@ +.\" +.\" This file and its contents are supplied under the terms of the +.\" Common Development and Distribution License ("CDDL"), version 1.0. +.\" You may only use this file in accordance with the terms of version +.\" 1.0 of the CDDL. +.\" +.\" A full copy of the text of the CDDL should have accompanied this +.\" source. A copy of the CDDL is also available via the Internet at +.\" http://www.illumos.org/license/CDDL. +.\" +.\" +.\" Copyright (c) 2015, Joyent, Inc. +.\" Copyright 2016 Joyent, Inc. +.\" +.Dd "Jan 13, 2015" +.Dt THRD_DETACH 3C +.Os +.Sh NAME +.Nm thrd_detach +.Nd detach a thread +.Sh SYNOPSIS +.In threads.h +.Ft int +.Fo thrd_detach +.Fa "thrd_t thrd" +.Fc +.Sh DESCRIPTION +The +.Fn thrd_detach +function causes a thread to be considered detached from the rest of the +execution environment. While detached threads are still fully +observable, they cannot be joined with, calls to +.Fn thrd_join +will fail. In addition, if all non-detached +threads have terminated, the program will terminate; detached threads +cannot keep a program running. The act of calling +.Fn thrd_detach +on a thread does not cause it to terminate. +.Sh RETURN VALUES +Upon successful completion, the +.Xr thrd_detach +function returns +.Sy thrd_success . +Otherwise, it returns +.Sy thrd_error , +indicating that an error has occurred. +.Sh INTERFACE STABILITY +.Sy Standard +.Sh MT-LEVEL +.Sy MT-safe +.Sh SEE ALSO +.Xr pthread_detach 3C , +.Xr thrd_create 3C , +.Xr thrd_join 3C , +.Xr attributes 5 , +.Xr threads 5 diff --git a/usr/src/man/man3c/thrd_equal.3c b/usr/src/man/man3c/thrd_equal.3c new file mode 100644 index 0000000000..6c77a72138 --- /dev/null +++ b/usr/src/man/man3c/thrd_equal.3c @@ -0,0 +1,56 @@ +.\" +.\" This file and its contents are supplied under the terms of the +.\" Common Development and Distribution License ("CDDL"), version 1.0. +.\" You may only use this file in accordance with the terms of version +.\" 1.0 of the CDDL. +.\" +.\" A full copy of the text of the CDDL should have accompanied this +.\" source. A copy of the CDDL is also available via the Internet at +.\" http://www.illumos.org/license/CDDL. +.\" +.\" +.\" Copyright 2016 Joyent, Inc. +.\" +.Dd "Jan 11, 2015" +.Dt THRD_EQUAL 3C +.Os +.Sh NAME +.Nm thrd_equal +.Nd determine if threads are equal +.Sh SYNOPSIS +.In threads.h +.Ft int +.Fo thrd_equal +.Fa "thrd_t thrd0" +.Fa "thrd_t thrd1" +.Fc +.Sh DESCRIPTION +The +.Fn thrd_equal +function compares +.Fa thrd0 +and +.Fa thrd1 +and determines whether or not they refer to the same thread. +.Sh RETURN VALUES +The +.Fn thrd_equal +function returns +.Sy 0 +if +.Fa thrd0 +and +.Fa thrd1 +refer to the same thread. Otherwise, a non-zero value is returned, +indicating that +.Fa thrd0 +and +.Fa thrd1 +are different threads. +.Sh INTERFACE STABILITY +.Sy Standard +.Sh MT-LEVEL +.Sy MT-Safe +.Sh SEE ALSO +.Xr attributes 5 , +.Xr threads 5 diff --git a/usr/src/man/man3c/thrd_exit.3c b/usr/src/man/man3c/thrd_exit.3c new file mode 100644 index 0000000000..3dcf682cd9 --- /dev/null +++ b/usr/src/man/man3c/thrd_exit.3c @@ -0,0 +1,64 @@ +.\" +.\" This file and its contents are supplied under the terms of the +.\" Common Development and Distribution License ("CDDL"), version 1.0. +.\" You may only use this file in accordance with the terms of version +.\" 1.0 of the CDDL. +.\" +.\" A full copy of the text of the CDDL should have accompanied this +.\" source. A copy of the CDDL is also available via the Internet at +.\" http://www.illumos.org/license/CDDL. +.\" +.\" +.\" Copyright 2016 Joyent, Inc. +.\" +.Dd "Jan 13, 2015" +.Dt THRD_EXIT 3C +.Os +.Sh NAME +.Nm thrd_exit +.Nd terminate a thread +.Sh SYNOPSIS +.In threads.h +.Ft "_Noreturn void" +.Fo thrd_exit +.Fa "int res" +.Fc +.Sh DESCRIPTION +The +.Fn thrd_exit +function terminates the calling thread, in a similar way that +.Xr exit 3C +terminates the calling process. If the calling thread has not been +detached, then the exit status information provided in +.Fa res +is saved and can be retrieved by the use of the +.Xr thrd_join 3C +function. +.Pp +When the thread exits, all signals will be blocked and various +destructors and clean up handlers will be called, such as those +registered with +.Xr tss_create 3C . +The act of thread termination does not cause any process-wide resources, +such as mutexes and file descriptors to be released. +.Pp +If a thread, other than the thread in which +.Fn main +was first invoked returns from its starting routine, it will implicitly +call +.Fn thrd_exit +and set the return value to be its exit status. +.Sh RETURN VALUES +The +.Fn thrd_exit +function does not return, the calling thread is terminated. +.Sh INTERFACE STABILITY +.Sy Standard +.Sh MT-LEVEL +.Sy MT-Safe +.Sh SEE ALSO +.Xr pthread_exit 3C , +.Xr thr_exit 3C , +.Xr attributes 5 , +.Xr attributes 5 , +.Xr threads 5 diff --git a/usr/src/man/man3c/thrd_join.3c b/usr/src/man/man3c/thrd_join.3c new file mode 100644 index 0000000000..d2cb8c83ea --- /dev/null +++ b/usr/src/man/man3c/thrd_join.3c @@ -0,0 +1,81 @@ +.\" +.\" This file and its contents are supplied under the terms of the +.\" Common Development and Distribution License ("CDDL"), version 1.0. +.\" You may only use this file in accordance with the terms of version +.\" 1.0 of the CDDL. +.\" +.\" A full copy of the text of the CDDL should have accompanied this +.\" source. A copy of the CDDL is also available via the Internet at +.\" http://www.illumos.org/license/CDDL. +.\" +.\" +.\" Copyright 2016 Joyent, Inc. +.\" +.Dd "Jan 13, 2015" +.Dt THRD_JOIN 3C +.Os +.Sh NAME +.Nm thrd_join +.Nd wait for thread termination +.Sh SYNOPSIS +.In threads.h +.Ft int +.Fo thrd_join +.Fa "thrd_t thrd" +.Fa "int *res" +.Fc +.Sh DESCRIPTION +The +.Fn thrd_join +function suspends the exection of the current thread and waits for the +thread indicated by +.Fa thrd +to terminate and stores the exit status, as set by a call to +.Xr thrd_exit 3C , +for that thread in +.Fa res , +if +.Fa res +is non-null. The +.Fa thrd +argument must be a member of the current process and it cannot be +detached. If +.Fa thrd +has already terminated and another caller has not called +.Fn thrd_join +then the exit status will be returned to the caller without blocking +execution of the thread. +.Pp +If multiple threads call +.Fn thrd_join +on the same thread, then both will be suspended until that thread +terminates; however, only one thread will return successfully and obtain +the actual status and the other will instead return with an error. +.Pp +For additional information on the thread joining interfaces supported by +the system, see +.Xr pthread_join 3C +and +.Xr thr_join 3C . +.Sh RETURN_VALUES +Upon successful completion, the +.Fn thrd_join +function returns +.Sy thrd_success +and if +.Fa res +is a non-null pointer, it will be filled in with the exit status of +.Xr thrd . +If an error occurs, +.Sy thrd_error +will be returned. +.Sh INTERFACE STABILITY +.Sy Standard +.Sh MT-LEVEL +.Sy MT-Safe +.Sh SEE ALSO +.Xr pthread_join 3C , +.Xr thrd_create 3C , +.Xr thrd_detach 3C , +.Xr attributes 5 , +.Xr threads 5 diff --git a/usr/src/man/man3c/thrd_yield.3c b/usr/src/man/man3c/thrd_yield.3c new file mode 100644 index 0000000000..a37ca39007 --- /dev/null +++ b/usr/src/man/man3c/thrd_yield.3c @@ -0,0 +1,38 @@ +.\" +.\" This file and its contents are supplied under the terms of the +.\" Common Development and Distribution License ("CDDL"), version 1.0. +.\" You may only use this file in accordance with the terms of version +.\" 1.0 of the CDDL. +.\" +.\" A full copy of the text of the CDDL should have accompanied this +.\" source. A copy of the CDDL is also available via the Internet at +.\" http://www.illumos.org/license/CDDL. +.\" +.\" +.\" Copyright 2016 Joyent, Inc. +.\" +.Dd "Jan 11, 2015" +.Dt THRD_YIELD 3C +.Os +.Sh NAME +.Nm thrd_yield +.Nd yield the CPU to another thread +.Sh SYNOPSIS +.In threads.h +.Ft void +.Fo thrd_yield +.Fa void +.Fc +.Sh DESCRIPTION +The +.Fn thrd_yield +function causes the current thread to yield the CPU and allow other +threads with the same or greater priority to run. +.Sh INTERFACE STABILITY +.Sy Standard +.Sh MT-Level +.Sy MT-Safe +.Sh SEE ALSO +.Xr yield 2 , +.Xr attributes 5 , +.Xr threads 5 diff --git a/usr/src/man/man3c/timespec_get.3c b/usr/src/man/man3c/timespec_get.3c new file mode 100644 index 0000000000..7ae55f7b55 --- /dev/null +++ b/usr/src/man/man3c/timespec_get.3c @@ -0,0 +1,81 @@ +.\" +.\" This file and its contents are supplied under the terms of the +.\" Common Development and Distribution License ("CDDL"), version 1.0. +.\" You may only use this file in accordance with the terms of version +.\" 1.0 of the CDDL. +.\" +.\" A full copy of the text of the CDDL should have accompanied this +.\" source. A copy of the CDDL is also available via the Internet at +.\" http://www.illumos.org/license/CDDL. +.\" +.\" +.\" Copyright 2016 Joyent, Inc. +.\" +.Dd "Mar 25, 2016" +.Dt TIMESPEC_GET 3C +.Os +.Sh NAME +.Nm timespec_get +.Nd get time information +.Sh SYNOPSIS +.In time.h +.Ft int +.Fo timespec_get +.Fa "struct timespec *ts" +.Fa "int base" +.Fc +.Sh DESCRIPTION +The +.Fn timespec_get +function provides access nanosecond resolution time. The +meaning and source of time is defined by the +.Fa base +argument. The following values are defined for +.Fa base : +.Bl -tag -width Ds +.It Sy TIME_UTC +Obtain the current time of day from the realtime clock on the system. It +represents the amount of time in second and nanoseconds since the Epoch. +This is logically equivalent to calling +.Xr clock_gettime 3C +with +.Sy CLOCK_REALTIME . +.El +.Pp +For the definition of the +.Sy timespec +structure, see +.Xr time.h 3HEAD . +.Sh RETURN VALUES +Upon successful completion, the +.Fn timespec_get +function returns the passed in value of +.Fa base . +Otherwise, +.Sy 0 +is returned to represent an error. +.Sh ERRORS +Unlike other functions, the +.Fn timespec_get +function is not defined to set +.Sy errno . +However, the +.Fn timespec_get +function will fail if: +.Bl -bullet -offset indent +.It +The value of +.Fa base +does not refer to a known time specification. +.It +There was an error obtaining the time for +.Fa base . +.El +.Sh INTERFACE STABILITY +.Sy Standard +.Sh MT-LEVEL +.Sy MT-Safe +.Sh SEE ALSO +.Xr clock_gettime 3C , +.Xr time.h 3HEAD , +.Xr attributes 5 diff --git a/usr/src/man/man3c/tss.3c b/usr/src/man/man3c/tss.3c new file mode 100644 index 0000000000..37ae52bd97 --- /dev/null +++ b/usr/src/man/man3c/tss.3c @@ -0,0 +1,151 @@ +.\" +.\" This file and its contents are supplied under the terms of the +.\" Common Development and Distribution License ("CDDL"), version 1.0. +.\" You may only use this file in accordance with the terms of version +.\" 1.0 of the CDDL. +.\" +.\" A full copy of the text of the CDDL should have accompanied this +.\" source. A copy of the CDDL is also available via the Internet at +.\" http://www.illumos.org/license/CDDL. +.\" +.\" +.\" Copyright 2016 Joyent, Inc. +.\" +.Dd "Jan 11, 2015" +.Dt TSS 3C +.Os +.Sh NAME +.Nm tss , +.Nm tss_create , +.Nm tss_destroy , +.Nm tss_get , +.Nm tss_set +.Nd thread-specific storage +.Sh SYNOPSIS +.In threads.h +.Vt "typedef void (*tss_dtor_t)(void *);" +.Ft int +.Fo tss_create +.Fa "tss_t *key" +.Fa "tss_dtor_t dtor" +.Fc +.Ft void +.Fo tss_delete +.Fa "tss_t key" +.Fc +.Ft void * +.Fo tss_get +.Fa "tss_t key" +.Fc +.Ft int +.Fo tss_set +.Fa "tss_t key" +.Fa "void *val" +.Fc +.Sh DESCRIPTION +The +.Sy tss +family of functions create, get, set, and destroy thread-specific +storage. +.Ss Creating and Destorying Thread-Specific Storage +The +.Fn tss_create +function creates a new thread-specific data key. The key space is opaque +and global to all threads in the process. Each thread has its own +value-space which can be mainpulated with the +.Fn tss_get +and +.Fn tss_set +functions. A given key persists until +.Fn tss_destroy +is called. +.Pp +When a key is created, the value +.Dv NULL +is associated with all current threads. When a thread is created, the +value +.Dv NULL +is assigned as the value for the entire key-space. +.Pp +A key may optionally be created with a destructor function +.Fa dtor . +The function +.Fa dtor +will run when the thread exits (see +.Xr thrd_exit 3C ) +if the value for the key is not +.Dv NULL . +The key space's destructors may be run in any order. When the destructor +is run due to a thread exiting, all signals will be blocked. +.Pp +The +.Fn tss_delete +function deletes the key identify by +.Fa key +from the global name-space. When a key is deleted, no registered +destructor is called, it is up to the calling program to free any +storage that was associated with +.Fa key +across all threads. Because of this propety, it is legal to call +.Fn tss_delete +from inside a destructor. Any destructors that had been assocaited with +.Fa key +will no longer be called when a thread terminates. +.Ss Obtaining Values +The +.Fn tss_get +function may be used to obtain the value associated with +.Fa key +for the calling thread. Note that if the calling thread has never set a +value, then it will receive the default value, +.Dv NULL . +.Fn tss_get +may be called from a tss destructor. +.Ss Setting Values +The +.Fn tss_set +function sets the value of the key +.Fa key +for the callling thread to +.Fa value , +which may be obtained by subsequent calls to +.Fa tss_get . +To remove a value for a specific thread, one may pass +.Dv NULL +in as +.Fa value . +Changing the value of a key with +.Fn tss_set +does not cause any destructors to be invoked. This means that +.Fn tss_set +may be used in the context of a destructor, but special care must be +taken to avoid leaking storage or causing an infinite loop. +.Sh RETURN VALUES +Upon successful completion, the +.Fn tss_create +and +.Fn tss_set +functions return +.Sy thrd_success . +Otherwise, they return +.Sy thrd_error +to indicate that an error occurred. +.Pp +Upon successful completion, the +.Fn tss_get +function returns the thread-specific value associated with the given +.Fa key . +If no thread-specific value is associated with the key or an invalid key +was passed in, then +.Dv NULL +is returned. +.Sh INTERFACE STABILITY +.Sy Standard +.Sh MT-LEVEL +.Sy MT-Safe +.Sh SEE ALSO +.Xr pthread_getspecific 3C , +.Xr pthread_key_create 3C , +.Xr pthread_key_delete 3C , +.Xr pthread_setspecific 3C , +.Xr attributes 5 |