Index: lib/Makefile =================================================================== RCS file: /cvsroot/src/lib/Makefile,v retrieving revision 1.248 diff -u -r1.248 Makefile --- lib/Makefile 14 Oct 2016 17:29:29 -0000 1.248 +++ lib/Makefile 29 Oct 2016 02:57:14 -0000 @@ -172,6 +172,8 @@ SUBDIR+= ../external/gpl3/${EXTERNAL_GCC_SUBDIR}/lib/libsupc++ .endif +SUBDIR+= libstdthreads # depends on libpthread + #==================== 2nd library dependency barrier ==================== SUBDIR+= .WAIT Index: distrib/sets/lists/base/shl.mi =================================================================== RCS file: /cvsroot/src/distrib/sets/lists/base/shl.mi,v retrieving revision 1.788 diff -u -r1.788 shl.mi --- distrib/sets/lists/base/shl.mi 14 Oct 2016 16:09:45 -0000 1.788 +++ distrib/sets/lists/base/shl.mi 29 Oct 2016 02:57:14 -0000 @@ -781,6 +781,9 @@ ./usr/lib/libstdc++.so.7 base-sys-shlib compatfile,gcc,cxx,libstdcxx ./usr/lib/libstdc++.so.7.3 base-sys-shlib compatfile,gcc=48,cxx,libstdcxx ./usr/lib/libstdc++.so.7.4 base-sys-shlib compatfile,gcc=53,cxx,libstdcxx +./usr/lib/libstdthreads.so base-sys-shlib compatfile +./usr/lib/libstdthreads.so.0 base-sys-shlib compatfile +./usr/lib/libstdthreads.so.0.0 base-sys-shlib compatfile ./usr/lib/libtelnet.so base-obsolete obsolete ./usr/lib/libtermcap.so base-sys-shlib compatfile ./usr/lib/libtermcap.so.0 base-sys-shlib compatfile Index: distrib/sets/lists/comp/mi =================================================================== RCS file: /cvsroot/src/distrib/sets/lists/comp/mi,v retrieving revision 1.2067 diff -u -r1.2067 mi --- distrib/sets/lists/comp/mi 15 Oct 2016 14:21:59 -0000 1.2067 +++ distrib/sets/lists/comp/mi 29 Oct 2016 02:57:16 -0000 @@ -3004,6 +3004,7 @@ ./usr/include/termcap.h comp-c-include ./usr/include/termios.h comp-c-include ./usr/include/threadlib.h comp-obsolete obsolete +./usr/include/threads.h comp-c-include ./usr/include/time.h comp-c-include ./usr/include/trousers/trousers.h comp-c-include tpm ./usr/include/trousers/tss.h comp-c-include tpm @@ -3601,6 +3602,8 @@ ./usr/lib/libssp_p.a comp-obsolete obsolete ./usr/lib/libstdc++.a comp-cxx-lib compatfile,cxx,libstdcxx,gcc ./usr/lib/libstdc++_p.a comp-cxx-proflib compatfile,cxx,libstdcxx,gcc,profile +./usr/lib/libstdthreads.a comp-c-lib compatfile +./usr/lib/libstdthreads_p.a comp-c-proflib compatfile,profile ./usr/lib/libsupc++.a comp-cxx-lib compatfile,cxx,libstdcxx,gcc ./usr/lib/libtddl.a comp-c-lib compatfile,tpm ./usr/lib/libtddl_p.a comp-c-proflib compatfile,tpm,profile @@ -4520,6 +4523,7 @@ ./usr/share/man/cat3/MD5_Init.0 comp-obsolete obsolete ./usr/share/man/cat3/MIN.0 comp-c-catman .cat ./usr/share/man/cat3/OBJ_nid2obj.0 comp-c-catman crypto,.cat +./usr/share/man/cat3/ONCE_FLAG_INIT.0 comp-c-catman .cat ./usr/share/man/cat3/OPENSSL_Applink.0 comp-c-catman crypto,.cat ./usr/share/man/cat3/OPENSSL_VERSION_NUMBER.0 comp-c-catman crypto,.cat ./usr/share/man/cat3/OPENSSL_config.0 comp-c-man crypto,.cat @@ -4830,6 +4834,7 @@ ./usr/share/man/cat3/TAILQ_REPLACE.0 comp-c-catman .cat ./usr/share/man/cat3/TIMESPEC_TO_TIMEVAL.0 comp-c-catman .cat ./usr/share/man/cat3/TIMEVAL_TO_TIMESPEC.0 comp-c-catman .cat +./usr/share/man/cat3/TSS_DTOR_ITERATIONS.0 comp-c-catman .cat ./usr/share/man/cat3/Tspi_ChangeAuth.0 comp-c-catman tpm,.cat ./usr/share/man/cat3/Tspi_ChangeAuthAsym.0 comp-c-catman tpm,.cat ./usr/share/man/cat3/Tspi_Context_Close.0 comp-c-catman tpm,.cat @@ -5450,6 +5455,7 @@ ./usr/share/man/cat3/cacoshf.0 comp-c-catman complex,.cat ./usr/share/man/cat3/cacoshl.0 comp-c-catman complex,.cat ./usr/share/man/cat3/cacosl.0 comp-c-catman complex,.cat +./usr/share/man/cat3/call_once.0 comp-c-catman .cat ./usr/share/man/cat3/calloc.0 comp-c-catman .cat ./usr/share/man/cat3/callrpc.0 comp-c-catman .cat ./usr/share/man/cat3/can_change_color.0 comp-c-catman .cat @@ -5601,6 +5607,13 @@ ./usr/share/man/cat3/clrtobot.0 comp-c-catman .cat ./usr/share/man/cat3/clrtoeol.0 comp-c-catman .cat ./usr/share/man/cat3/cmsg.0 comp-c-catman .cat +./usr/share/man/cat3/cnd.0 comp-c-catman .cat +./usr/share/man/cat3/cnd_broadcast.0 comp-c-catman .cat +./usr/share/man/cat3/cnd_destroy.0 comp-c-catman .cat +./usr/share/man/cat3/cnd_init.0 comp-c-catman .cat +./usr/share/man/cat3/cnd_signal.0 comp-c-catman .cat +./usr/share/man/cat3/cnd_timedwait.0 comp-c-catman .cat +./usr/share/man/cat3/cnd_wait.0 comp-c-catman .cat ./usr/share/man/cat3/color_content.0 comp-c-catman .cat ./usr/share/man/cat3/color_set.0 comp-c-catman .cat ./usr/share/man/cat3/com_err.0 comp-krb5-catman kerberos,.cat @@ -7853,6 +7866,13 @@ ./usr/share/man/cat3/mvwinstr.0 comp-c-catman .cat ./usr/share/man/cat3/mvwprintw.0 comp-c-catman .cat ./usr/share/man/cat3/mvwvline.0 comp-c-catman .cat +./usr/share/man/cat3/mtx.0 comp-c-catman .cat +./usr/share/man/cat3/mtx_destroy.0 comp-c-catman .cat +./usr/share/man/cat3/mtx_init.0 comp-c-catman .cat +./usr/share/man/cat3/mtx_lock.0 comp-c-catman .cat +./usr/share/man/cat3/mtx_timedlock.0 comp-c-catman .cat +./usr/share/man/cat3/mtx_trylock.0 comp-c-catman .cat +./usr/share/man/cat3/mtx_unlock.0 comp-c-catman .cat ./usr/share/man/cat3/nan.0 comp-c-catman .cat ./usr/share/man/cat3/nanf.0 comp-c-catman .cat ./usr/share/man/cat3/nanl.0 comp-c-catman .cat @@ -7905,6 +7925,7 @@ ./usr/share/man/cat3/offsetof.0 comp-c-catman .cat ./usr/share/man/cat3/offtime.0 comp-c-catman .cat ./usr/share/man/cat3/offtime_r.0 comp-c-catman .cat +./usr/share/man/cat3/once_flag.0 comp-c-catman .cat ./usr/share/man/cat3/open_memstream.0 comp-c-catman .cat ./usr/share/man/cat3/open_wmemstream.0 comp-c-catman .cat ./usr/share/man/cat3/opendir.0 comp-c-catman .cat @@ -9141,6 +9162,7 @@ ./usr/share/man/cat3/stdint.0 comp-c-catman .cat ./usr/share/man/cat3/stdio.0 comp-c-catman .cat ./usr/share/man/cat3/stdlib.0 comp-c-catman .cat +./usr/share/man/cat3/stdthreads.0 comp-c-catman .cat ./usr/share/man/cat3/stpcpy.0 comp-c-catman .cat ./usr/share/man/cat3/stpncpy.0 comp-c-catman .cat ./usr/share/man/cat3/stravis.0 comp-c-catman .cat @@ -9334,6 +9356,15 @@ ./usr/share/man/cat3/tgmath.0 comp-c-catman .cat ./usr/share/man/cat3/tgoto.0 comp-c-catman .cat ./usr/share/man/cat3/threads.0 comp-obsolete obsolete +./usr/share/man/cat3/thrd.0 comp-c-catman .cat +./usr/share/man/cat3/thrd_create.0 comp-c-catman .cat +./usr/share/man/cat3/thrd_current.0 comp-c-catman .cat +./usr/share/man/cat3/thrd_detach.0 comp-c-catman .cat +./usr/share/man/cat3/thrd_equal.0 comp-c-catman .cat +./usr/share/man/cat3/thrd_exit.0 comp-c-catman .cat +./usr/share/man/cat3/thrd_join.0 comp-c-catman .cat +./usr/share/man/cat3/thrd_sleep.0 comp-c-catman .cat +./usr/share/man/cat3/thrd_yield.0 comp-c-catman .cat ./usr/share/man/cat3/ti_getflag.0 comp-c-catman .cat ./usr/share/man/cat3/ti_getnum.0 comp-c-catman .cat ./usr/share/man/cat3/ti_getstr.0 comp-c-catman .cat @@ -9398,6 +9429,11 @@ ./usr/share/man/cat3/truncf.0 comp-c-catman .cat ./usr/share/man/cat3/truncl.0 comp-c-catman .cat ./usr/share/man/cat3/tsearch.0 comp-c-catman .cat +./usr/share/man/cat3/tss.0 comp-c-catman .cat +./usr/share/man/cat3/tss_create.0 comp-c-catman .cat +./usr/share/man/cat3/tss_delete.0 comp-c-catman .cat +./usr/share/man/cat3/tss_get.0 comp-c-catman .cat +./usr/share/man/cat3/tss_set.0 comp-c-catman .cat ./usr/share/man/cat3/ttyaction.0 comp-c-catman .cat ./usr/share/man/cat3/ttylock.0 comp-c-catman .cat ./usr/share/man/cat3/ttymsg.0 comp-c-catman .cat @@ -11895,6 +11931,7 @@ ./usr/share/man/html3/MD5Update.html comp-c-htmlman html ./usr/share/man/html3/MIN.html comp-c-htmlman html ./usr/share/man/html3/OBJ_nid2obj.html comp-c-htmlman crypto,html +./usr/share/man/html3/ONCE_FLAG_INIT.html comp-c-htmlman html ./usr/share/man/html3/OPENSSL_Applink.html comp-c-htmlman crypto,html ./usr/share/man/html3/OPENSSL_VERSION_NUMBER.html comp-c-htmlman crypto,html ./usr/share/man/html3/OPENSSL_config.html comp-c-man crypto,html @@ -12213,6 +12250,7 @@ ./usr/share/man/html3/TAILQ_REPLACE.html comp-c-htmlman html ./usr/share/man/html3/TIMESPEC_TO_TIMEVAL.html comp-c-htmlman html ./usr/share/man/html3/TIMEVAL_TO_TIMESPEC.html comp-c-htmlman html +./usr/share/man/html3/TSS_DTOR_ITERATIONS.html comp-c-htmlman html ./usr/share/man/html3/Tspi_ChangeAuth.html comp-c-htmlman tpm,html ./usr/share/man/html3/Tspi_ChangeAuthAsym.html comp-c-htmlman tpm,html ./usr/share/man/html3/Tspi_Context_Close.html comp-c-htmlman tpm,html @@ -12823,6 +12861,7 @@ ./usr/share/man/html3/cacoshf.html comp-c-htmlman complex,html ./usr/share/man/html3/cacoshl.html comp-c-htmlman complex,html ./usr/share/man/html3/cacosl.html comp-c-htmlman complex,html +./usr/share/man/html3/call_once.html comp-c-htmlman html ./usr/share/man/html3/calloc.html comp-c-htmlman html ./usr/share/man/html3/callrpc.html comp-c-htmlman html ./usr/share/man/html3/can_change_color.html comp-c-htmlman html @@ -12931,6 +12970,13 @@ ./usr/share/man/html3/clrtobot.html comp-c-htmlman html ./usr/share/man/html3/clrtoeol.html comp-c-htmlman html ./usr/share/man/html3/cmsg.html comp-c-htmlman html +./usr/share/man/html3/cnd.html comp-c-htmlman html +./usr/share/man/html3/cnd_broadcast.html comp-c-htmlman html +./usr/share/man/html3/cnd_destroy.html comp-c-htmlman html +./usr/share/man/html3/cnd_init.html comp-c-htmlman html +./usr/share/man/html3/cnd_signal.html comp-c-htmlman html +./usr/share/man/html3/cnd_timedwait.html comp-c-htmlman html +./usr/share/man/html3/cnd_wait.html comp-c-htmlman html ./usr/share/man/html3/color_content.html comp-c-htmlman html ./usr/share/man/html3/color_set.html comp-c-htmlman html ./usr/share/man/html3/com_err.html comp-krb5-htmlman kerberos,html @@ -15149,6 +15195,13 @@ ./usr/share/man/html3/mvwinstr.html comp-c-htmlman html ./usr/share/man/html3/mvwprintw.html comp-c-htmlman html ./usr/share/man/html3/mvwvline.html comp-c-htmlman html +./usr/share/man/html3/mtx.html comp-c-htmlman html +./usr/share/man/html3/mtx_destroy.html comp-c-htmlman html +./usr/share/man/html3/mtx_init.html comp-c-htmlman html +./usr/share/man/html3/mtx_lock.html comp-c-htmlman html +./usr/share/man/html3/mtx_timedlock.html comp-c-htmlman html +./usr/share/man/html3/mtx_trylock.html comp-c-htmlman html +./usr/share/man/html3/mtx_unlock.html comp-c-htmlman html ./usr/share/man/html3/nan.html comp-c-htmlman html ./usr/share/man/html3/nanf.html comp-c-htmlman html ./usr/share/man/html3/nanl.html comp-c-htmlman html @@ -15198,6 +15251,7 @@ ./usr/share/man/html3/offsetof.html comp-c-htmlman html ./usr/share/man/html3/offtime.html comp-c-htmlman html ./usr/share/man/html3/offtime_r.html comp-c-htmlman html +./usr/share/man/html3/once_flag.html comp-c-htmlman html ./usr/share/man/html3/open_memstream.html comp-c-htmlman html ./usr/share/man/html3/open_wmemstream.html comp-c-htmlman html ./usr/share/man/html3/opendir.html comp-c-htmlman html @@ -16411,6 +16465,7 @@ ./usr/share/man/html3/stdint.html comp-c-htmlman html ./usr/share/man/html3/stdio.html comp-c-htmlman html ./usr/share/man/html3/stdlib.html comp-c-htmlman html +./usr/share/man/html3/stdthreads.html comp-c-htmlman html ./usr/share/man/html3/stpcpy.html comp-c-htmlman html ./usr/share/man/html3/stpncpy.html comp-c-htmlman html ./usr/share/man/html3/stravis.html comp-c-htmlman html @@ -16588,6 +16643,15 @@ ./usr/share/man/html3/tgetstr.html comp-c-htmlman html ./usr/share/man/html3/tgmath.html comp-c-htmlman html ./usr/share/man/html3/tgoto.html comp-c-htmlman html +./usr/share/man/html3/thrd.html comp-c-htmlman html +./usr/share/man/html3/thrd_create.html comp-c-htmlman html +./usr/share/man/html3/thrd_current.html comp-c-htmlman html +./usr/share/man/html3/thrd_detach.html comp-c-htmlman html +./usr/share/man/html3/thrd_equal.html comp-c-htmlman html +./usr/share/man/html3/thrd_exit.html comp-c-htmlman html +./usr/share/man/html3/thrd_join.html comp-c-htmlman html +./usr/share/man/html3/thrd_sleep.html comp-c-htmlman html +./usr/share/man/html3/thrd_yield.html comp-c-htmlman html ./usr/share/man/html3/ti_getflag.html comp-c-htmlman html ./usr/share/man/html3/ti_getnum.html comp-c-htmlman html ./usr/share/man/html3/ti_getstr.html comp-c-htmlman html @@ -16652,6 +16716,11 @@ ./usr/share/man/html3/truncf.html comp-c-htmlman html ./usr/share/man/html3/truncl.html comp-c-htmlman html ./usr/share/man/html3/tsearch.html comp-c-htmlman html +./usr/share/man/html3/tss.html comp-c-htmlman html +./usr/share/man/html3/tss_create.html comp-c-htmlman html +./usr/share/man/html3/tss_delete.html comp-c-htmlman html +./usr/share/man/html3/tss_get.html comp-c-htmlman html +./usr/share/man/html3/tss_set.html comp-c-htmlman html ./usr/share/man/html3/ttyaction.html comp-c-htmlman html ./usr/share/man/html3/ttylock.html comp-c-htmlman html ./usr/share/man/html3/ttymsg.html comp-c-htmlman html @@ -19082,6 +19151,7 @@ ./usr/share/man/man3/MD5_Init.3 comp-obsolete obsolete ./usr/share/man/man3/MIN.3 comp-c-man .man ./usr/share/man/man3/OBJ_nid2obj.3 comp-c-man crypto,.man +./usr/share/man/man3/ONCE_FLAG_INIT.3 comp-c-man .man ./usr/share/man/man3/OPENSSL_Applink.3 comp-c-man crypto,.man ./usr/share/man/man3/OPENSSL_VERSION_NUMBER.3 comp-c-man crypto,.man ./usr/share/man/man3/OPENSSL_config.3 comp-c-man crypto,.man @@ -19401,6 +19471,7 @@ ./usr/share/man/man3/TAILQ_REPLACE.3 comp-c-man .man ./usr/share/man/man3/TIMESPEC_TO_TIMEVAL.3 comp-c-man .man ./usr/share/man/man3/TIMEVAL_TO_TIMESPEC.3 comp-c-man .man +./usr/share/man/man3/TSS_DTOR_ITERATIONS.3 comp-c-man .man ./usr/share/man/man3/Tspi_ChangeAuth.3 comp-c-man tpm,.man ./usr/share/man/man3/Tspi_ChangeAuthAsym.3 comp-c-man tpm,.man ./usr/share/man/man3/Tspi_Context_Close.3 comp-c-man tpm,.man @@ -20021,6 +20092,7 @@ ./usr/share/man/man3/cacoshf.3 comp-c-man complex,.man ./usr/share/man/man3/cacoshl.3 comp-c-man complex,.man ./usr/share/man/man3/cacosl.3 comp-c-man complex,.man +./usr/share/man/man3/call_once.3 comp-c-man .man ./usr/share/man/man3/calloc.3 comp-c-man .man ./usr/share/man/man3/callrpc.3 comp-c-man .man ./usr/share/man/man3/can_change_color.3 comp-c-man .man @@ -20172,6 +20244,13 @@ ./usr/share/man/man3/clrtobot.3 comp-c-man .man ./usr/share/man/man3/clrtoeol.3 comp-c-man .man ./usr/share/man/man3/cmsg.3 comp-c-man .man +./usr/share/man/man3/cnd.3 comp-c-man .man +./usr/share/man/man3/cnd_broadcast.3 comp-c-man .man +./usr/share/man/man3/cnd_destroy.3 comp-c-man .man +./usr/share/man/man3/cnd_init.3 comp-c-man .man +./usr/share/man/man3/cnd_signal.3 comp-c-man .man +./usr/share/man/man3/cnd_timedwait.3 comp-c-man .man +./usr/share/man/man3/cnd_wait.3 comp-c-man .man ./usr/share/man/man3/color_content.3 comp-c-man .man ./usr/share/man/man3/color_set.3 comp-c-man .man ./usr/share/man/man3/com_err.3 comp-krb5-man kerberos,.man @@ -22428,6 +22507,13 @@ ./usr/share/man/man3/mvwinstr.3 comp-c-man .man ./usr/share/man/man3/mvwprintw.3 comp-c-man .man ./usr/share/man/man3/mvwvline.3 comp-c-man .man +./usr/share/man/man3/mtx.3 comp-c-man .man +./usr/share/man/man3/mtx_destroy.3 comp-c-man .man +./usr/share/man/man3/mtx_init.3 comp-c-man .man +./usr/share/man/man3/mtx_lock.3 comp-c-man .man +./usr/share/man/man3/mtx_timedlock.3 comp-c-man .man +./usr/share/man/man3/mtx_trylock.3 comp-c-man .man +./usr/share/man/man3/mtx_unlock.3 comp-c-man .man ./usr/share/man/man3/nan.3 comp-c-man .man ./usr/share/man/man3/nanf.3 comp-c-man .man ./usr/share/man/man3/nanl.3 comp-c-man .man @@ -22480,6 +22566,7 @@ ./usr/share/man/man3/offsetof.3 comp-c-man .man ./usr/share/man/man3/offtime.3 comp-c-man .man ./usr/share/man/man3/offtime_r.3 comp-c-man .man +./usr/share/man/man3/once_flag.3 comp-c-man .man ./usr/share/man/man3/open_memstream.3 comp-c-man .man ./usr/share/man/man3/open_wmemstream.3 comp-c-man .man ./usr/share/man/man3/opendir.3 comp-c-man .man @@ -23712,6 +23799,7 @@ ./usr/share/man/man3/stdint.3 comp-c-man .man ./usr/share/man/man3/stdio.3 comp-c-man .man ./usr/share/man/man3/stdlib.3 comp-c-man .man +./usr/share/man/man3/stdthreads.3 comp-c-man .man ./usr/share/man/man3/stpcpy.3 comp-c-man .man ./usr/share/man/man3/stpncpy.3 comp-c-man .man ./usr/share/man/man3/stravis.3 comp-c-man .man @@ -23905,6 +23993,15 @@ ./usr/share/man/man3/tgmath.3 comp-c-man .man ./usr/share/man/man3/tgoto.3 comp-c-man .man ./usr/share/man/man3/threads.3 comp-obsolete obsolete +./usr/share/man/man3/thrd.3 comp-c-man .man +./usr/share/man/man3/thrd_create.3 comp-c-man .man +./usr/share/man/man3/thrd_current.3 comp-c-man .man +./usr/share/man/man3/thrd_detach.3 comp-c-man .man +./usr/share/man/man3/thrd_equal.3 comp-c-man .man +./usr/share/man/man3/thrd_exit.3 comp-c-man .man +./usr/share/man/man3/thrd_join.3 comp-c-man .man +./usr/share/man/man3/thrd_sleep.3 comp-c-man .man +./usr/share/man/man3/thrd_yield.3 comp-c-man .man ./usr/share/man/man3/ti_getflag.3 comp-c-man .man ./usr/share/man/man3/ti_getnum.3 comp-c-man .man ./usr/share/man/man3/ti_getstr.3 comp-c-man .man @@ -23969,6 +24066,11 @@ ./usr/share/man/man3/truncf.3 comp-c-man .man ./usr/share/man/man3/truncl.3 comp-c-man .man ./usr/share/man/man3/tsearch.3 comp-c-man .man +./usr/share/man/man3/tss.3 comp-c-man .man +./usr/share/man/man3/tss_create.3 comp-c-man .man +./usr/share/man/man3/tss_delete.3 comp-c-man .man +./usr/share/man/man3/tss_get.3 comp-c-man .man +./usr/share/man/man3/tss_set.3 comp-c-man .man ./usr/share/man/man3/ttyaction.3 comp-c-man .man ./usr/share/man/man3/ttylock.3 comp-c-man .man ./usr/share/man/man3/ttymsg.3 comp-c-man .man Index: distrib/sets/lists/comp/shl.mi =================================================================== RCS file: /cvsroot/src/distrib/sets/lists/comp/shl.mi,v retrieving revision 1.295 diff -u -r1.295 shl.mi --- distrib/sets/lists/comp/shl.mi 5 Sep 2016 02:25:37 -0000 1.295 +++ distrib/sets/lists/comp/shl.mi 29 Oct 2016 02:57:16 -0000 @@ -248,6 +248,7 @@ ./usr/lib/libssl_pic.a comp-c-piclib compatfile,picinstall,crypto ./usr/lib/libssp_pic.a comp-obsolete obsolete ./usr/lib/libstdc++_pic.a comp-cxx-piclib compatfile,picinstall,cxx,gcccmds,libstdcxx +./usr/lib/libstdthreads_pic.a comp-c-piclib compatfile,picinstall ./usr/lib/libtddl_pic.a comp-c-piclib compatfile,picinstall,tpm ./usr/lib/libtelnet_pic.a comp-obsolete obsolete ./usr/lib/libtermcap_pic.a comp-c-piclib compatfile,picinstall Index: distrib/sets/lists/debug/md.amd64 =================================================================== RCS file: /cvsroot/src/distrib/sets/lists/debug/md.amd64,v retrieving revision 1.90 diff -u -r1.90 md.amd64 --- distrib/sets/lists/debug/md.amd64 2 Jul 2016 15:40:51 -0000 1.90 +++ distrib/sets/lists/debug/md.amd64 29 Oct 2016 02:57:16 -0000 @@ -8,6 +8,7 @@ ./usr/libdata/debug/usr/lib/i386/libi386.so.1.0.debug comp-compat-shlib compat,pic,debug ./usr/libdata/debug/usr/lib/i386/libproc.so.0.0.debug comp-compat-shlib compat,pic,debug,dtrace ./usr/libdata/debug/usr/lib/i386/librtld_db.so.0.0.debug comp-compat-shlib compat,pic,debug,dtrace +./usr/libdata/debug/usr/lib/i386/libstdthreads.so.0.0.debug comp-compat-shlib compat,pic,debug ./usr/libdata/debug/usr/lib/libx86_64.so.0.0.debug comp-sys-shlib pic,debug ./usr/libdata/debug/usr/libexec/ld.elf_so-i386 comp-obsolete obsolete ./usr/libdata/debug/usr/libexec/ld.elf_so-i386.debug comp-sys-debug debug,compat Index: distrib/sets/lists/debug/mi =================================================================== RCS file: /cvsroot/src/distrib/sets/lists/debug/mi,v retrieving revision 1.167 diff -u -r1.167 mi --- distrib/sets/lists/debug/mi 5 Sep 2016 02:25:38 -0000 1.167 +++ distrib/sets/lists/debug/mi 29 Oct 2016 02:57:17 -0000 @@ -239,6 +239,8 @@ ./usr/lib/libssh_g.a comp-c-debuglib debuglib,compatfile,crypto ./usr/lib/libssl_g.a comp-c-debuglib debuglib,compatfile,crypto ./usr/lib/libstdc++_g.a comp-c-debuglib debuglib,compatfile,cxx,gcccmds,libstdcxx +./usr/lib/libstdthreads_g.a comp-c-debuglib debuglib,compatfile +./usr/lib/libstdthreads_p.a comp-c-debuglib debuglib,compatfile ./usr/lib/libsupc++_g.a comp-c-debuglib debuglib,compatfile,cxx,gcccmds,libstdcxx ./usr/lib/libtddl_g.a comp-c-debuglib debuglib,compatfile,tpm ./usr/lib/libtermcap_g.a comp-obsolete obsolete,compatfile Index: distrib/sets/lists/debug/shl.mi =================================================================== RCS file: /cvsroot/src/distrib/sets/lists/debug/shl.mi,v retrieving revision 1.148 diff -u -r1.148 shl.mi --- distrib/sets/lists/debug/shl.mi 14 Oct 2016 16:09:45 -0000 1.148 +++ distrib/sets/lists/debug/shl.mi 29 Oct 2016 02:57:17 -0000 @@ -265,6 +265,7 @@ ./usr/libdata/debug/usr/lib/libssl.so.12.0.debug comp-crypto-debug debug,compatfile,crypto ./usr/libdata/debug/usr/lib/libstdc++.so.7.3.debug comp-sys-debug debug,compatfile,gcc=48,cxx,libstdcxx ./usr/libdata/debug/usr/lib/libstdc++.so.7.4.debug comp-sys-debug debug,compatfile,gcc=53,cxx,libstdcxx +./usr/libdata/debug/usr/lib/libstdthreads.so.0.0.debug comp-sys-debug debug,compatfile ./usr/libdata/debug/usr/lib/libterminfo.so.1.0.debug comp-sys-debug debug,compatfile ./usr/libdata/debug/usr/lib/libtpm_unseal.so.1.0.debug comp-tpm-debug debug,compatfile,tpm ./usr/libdata/debug/usr/lib/libtre.so.0.8.debug comp-sys-debug debug,compatfile Index: lib/libstdthreads/Makefile =================================================================== RCS file: lib/libstdthreads/Makefile diff -N lib/libstdthreads/Makefile --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lib/libstdthreads/Makefile 29 Oct 2016 02:58:47 -0000 @@ -0,0 +1,61 @@ +# $NetBSD$ + +# WARNS= 6 + +CPPFLAGS+= -I${.CURDIR} + +LIB= stdthreads + +INCS= threads.h +INCSDIR= /usr/include + +SRCS= # +SRCS+= call_once.c # ISO/IEC 9899:201x 7.26.2 Initialization functions +SRCS+= cnd.c # ISO/IEC 9899:201x 7.26.3 Condition variable functions +SRCS+= mtx.c # ISO/IEC 9899:201x 7.26.4 Mutex functions +SRCS+= thrd.c # ISO/IEC 9899:201x 7.26.5 Thread functions +SRCS+= tss.c # ISO/IEC 9899:201x 7.26.6 Thread-specific storage functions + +LIBDPLIBS+= pthread ${.CURDIR}/../libpthread + +MAN= # +MAN+= stdthreads.3 # The libstdthreads library overview +MAN+= call_once.3 +MAN+= cnd.3 +MAN+= mtx.3 +MAN+= thrd.3 +MAN+= tss.3 + +MLINKS+= call_once.3 ONCE_FLAG_INIT.3 +MLINKS+= call_once.3 once_flag.3 + +MLINKS+= cnd.3 cnd_broadcast.3 +MLINKS+= cnd.3 cnd_destroy.3 +MLINKS+= cnd.3 cnd_init.3 +MLINKS+= cnd.3 cnd_signal.3 +MLINKS+= cnd.3 cnd_timedwait.3 +MLINKS+= cnd.3 cnd_wait.3 + +MLINKS+= mtx.3 mtx_destroy.3 +MLINKS+= mtx.3 mtx_init.3 +MLINKS+= mtx.3 mtx_lock.3 +MLINKS+= mtx.3 mtx_timedlock.3 +MLINKS+= mtx.3 mtx_trylock.3 +MLINKS+= mtx.3 mtx_unlock.3 + +MLINKS+= thrd.3 thrd_create.3 +MLINKS+= thrd.3 thrd_current.3 +MLINKS+= thrd.3 thrd_detach.3 +MLINKS+= thrd.3 thrd_equal.3 +MLINKS+= thrd.3 thrd_exit.3 +MLINKS+= thrd.3 thrd_join.3 +MLINKS+= thrd.3 thrd_sleep.3 +MLINKS+= thrd.3 thrd_yield.3 + +MLINKS+= tss.3 TSS_DTOR_ITERATIONS.3 +MLINKS+= tss.3 tss_create.3 +MLINKS+= tss.3 tss_delete.3 +MLINKS+= tss.3 tss_get.3 +MLINKS+= tss.3 tss_set.3 + +.include Index: lib/libstdthreads/call_once.3 =================================================================== RCS file: lib/libstdthreads/call_once.3 diff -N lib/libstdthreads/call_once.3 --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lib/libstdthreads/call_once.3 29 Oct 2016 02:58:47 -0000 @@ -0,0 +1,113 @@ +.\" $NetBSD$ +.\" +.\" 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 CALL_ONCE 3 +.Os +.Sh NAME +.Nm call_once +.Nd calls function exactly once +.Sh LIBRARY +.Lb libstdthreads +.Sh SYNOPSIS +.In threads.h +.Ft void +.Fn call_once "once_flag *flag" "void (*func)(void))" +.Vt once_flag flag No = Dv ONCE_FLAG_INIT ; +.Sh DESCRIPTION +The +.Nm +function uses the +.Fa flag +parameter to ensure that +.Fa func +is called exactly once, +even if called from several threads. +.Pp +The +.Dv ONCE_FLAG_INIT +definition expands to a value that can be used to initialize an object of type +.Dv once_flag . +.Pp +This portable interface is implemented on top of the +.Xr pthread_once 3 +functionality. +.Sh RETURN VALUES +None. +.Sh EXAMPLES +The following calls +.Nm +from two threads using the portable +.Xr thrd 3 +interface. +.Bd -literal -offset indent +#include +#include + +static once_flag oflag = ONCE_FLAG_INIT; + +void +called_once(void) +{ + printf("called once\n"); +} + +inf +tfun(void *ptr) +{ + call_once(&oflag, called_once); +} + +int +main(int argc, char **argv) +{ + thrd_t th1, th2; + + thrd_create(&th1, tfun, NULL); + thrd_create(&th2, tfun, NULL); + + thrd_join(th1, NULL); + thrd_join(th2, NULL); + + return 0; +} +.Ed +.Sh SEE ALSO +.Xr pthread_once 3 , +.Xr stdthreads 3 +.Sh STANDARDS +The +.Nm +function conforms to +.St -isoC-2011 . +.Sh HISTORY +This interface first appeared in +.Nx 8 . +.Sh AUTHORS +.An Kamil Rytarowski Aq Mt kamil@NetBSD.org Index: lib/libstdthreads/call_once.c =================================================================== RCS file: lib/libstdthreads/call_once.c diff -N lib/libstdthreads/call_once.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lib/libstdthreads/call_once.c 29 Oct 2016 02:58:47 -0000 @@ -0,0 +1,52 @@ +/* $NetBSD$ */ + +/*- + * Copyright (c) 2016 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by + * + * 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. + */ + +#include +__RCSID("$NetBSD$"); + +#include +#include +#include +#include +#include + +void +call_once(once_flag *flag, void (*func)(void)) +{ + + _DIAGASSERT(flag != NULL); + _DIAGASSERT(func != NULL); + + /* The call_once(3) function returns no value, this forces this code to + * break as there is nothing better available. */ + if (pthread_once(flag, func) != 0) + errx(EXIT_FAILURE, "pthread_once failed"); +} Index: lib/libstdthreads/cnd.3 =================================================================== RCS file: lib/libstdthreads/cnd.3 diff -N lib/libstdthreads/cnd.3 --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lib/libstdthreads/cnd.3 29 Oct 2016 02:58:47 -0000 @@ -0,0 +1,198 @@ +.\" $NetBSD$ +.\" +.\" 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 libstdthreads +.Sh SYNOPSIS +.In threads.h +.Ft int +.Fn cnd_broadcast "cnd_t *cond" +.Ft int +.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. +This function returns status of operation as the +.Nx +extension. +.Pp +The +.Fn cnd_init +function initializes 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 atomicalyl 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 blocks on 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 +.Dv thrd_success +on success, otherwise +.Dv thrd_busy +if the value +.Dv cond +is locked by another thread or +.Dv thrd_error +if the value +.Dv cond +is invalid. +.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, otherwise +.Dv thrd_error +on failure. +.Sh SEE ALSO +.Xr pthread_cond 3 , +.Xr stdthreads 3 +.Sh STANDARDS +The +.Nm +interface conforms to +.St -isoC-2011 , +with return value extension in the +.Fa cnd_destroy +function. +.Sh HISTORY +This interface first appeared in +.Nx 8 . +.Sh AUTHORS +.An Kamil Rytarowski Aq Mt kamil@NetBSD.org Index: lib/libstdthreads/cnd.c =================================================================== RCS file: lib/libstdthreads/cnd.c diff -N lib/libstdthreads/cnd.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lib/libstdthreads/cnd.c 29 Oct 2016 02:58:47 -0000 @@ -0,0 +1,128 @@ +/* $NetBSD$ */ + +/*- + * 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. + */ + +#include +__RCSID("$NetBSD$"); + +#include +#include +#include +#include + +int +cnd_broadcast(cnd_t *cond) +{ + + _DIAGASSERT(cond != NULL); + + if (pthread_cond_broadcast(cond) == 0) + return thrd_success; + + return thrd_error; +} + +int +cnd_destroy(cnd_t *cond) +{ + + _DIAGASSERT(cond != NULL); + + /* + * The cnd_destroy(3) function that conforms to C11 returns no value + * Extend this interface and return errors, instread of silently + * breaking behind the scenes. + */ + switch (pthread_cond_destroy(cond)) { + case 0: + return thrd_success; + case EBUSY: + return thrd_busy; + case EINVAL: + default: + return thrd_error; + } +} + +int +cnd_init(cnd_t *cond) +{ + + _DIAGASSERT(cond != NULL); + + if (pthread_cond_init(cond, NULL) == 0) + return thrd_success; + + return thrd_error; +} + +int +cnd_signal(cnd_t *cond) +{ + + _DIAGASSERT(cond != NULL); + + if (pthread_cond_signal(cond) == 0) + return thrd_success; + + return thrd_error; +} + +int +cnd_timedwait(cnd_t * __restrict cond, mtx_t * __restrict mtx, + const struct timespec * __restrict ts) +{ + + _DIAGASSERT(cond != NULL); + _DIAGASSERT(mtx != NULL); + _DIAGASSERT(ts != NULL); + + switch (pthread_cond_timedwait(cond, mtx, ts)) { + case 0: + return thrd_success; + case ETIMEDOUT: + return thrd_timedout; + default: + return thrd_error; + } +} + +int +cnd_wait(cnd_t *cond, mtx_t *mtx) +{ + + _DIAGASSERT(cond != NULL); + _DIAGASSERT(mtx != NULL); + + if (pthread_cond_wait(cond, mtx) == 0) + return thrd_success; + + return thrd_error; +} Index: lib/libstdthreads/mtx.3 =================================================================== RCS file: lib/libstdthreads/mtx.3 diff -N lib/libstdthreads/mtx.3 --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lib/libstdthreads/mtx.3 29 Oct 2016 02:58:48 -0000 @@ -0,0 +1,233 @@ +.\" $NetBSD$ +.\" +.\" 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 MTX 3 +.Os +.Sh NAME +.Nm mtx +.Nd mutex functions +.Sh LIBRARY +.Lb libstdthreads +.Sh SYNOPSIS +.In threads.h +.Ft int +.Fn mtx_destroy "mtx_t *mtx" +.Ft int +.Fn mtx_init "mtx_t *mtx" "int type" +.Ft int +.Fn mtx_lock "mtx_t *mtx" +.Ft int +.Fn mtx_timedlock "mtx_t *__restrict mtx" "const struct timespec *__restrict ts" +.Ft int +.Fn mtx_trylock "mtx_t *mtx" +.Ft int +.Fn mtx_unlock "mtx_t *mtx" +.Sh DESCRIPTION +The +.Fn mtx_destroy +function releases the resources of +.Fa mtx . +It is not allowed to block the same +.Fa mtx +during the +.Fn mtx_destroy +call. +This functions returns status of operation as +.Nx +extension. +.Pp +The +.Fn mtx_init +function initialized the +.Fa mtx +object uniquely identificable with the +.Fa type +properties. +The allowed values of +.Fa type +are as follows: +.Bl -column "mtx_plain | mtx_recursive" +.It Sy "Type" Ta Sy "Description" +.It Xr mtx_plain Ta basic mutex +.It Xr mtx_timed Ta mutex with timeout support +.It Xr mtx_plain | mtx_recursive Ta basic recursive mutex +.It Xr mtx_timed | mtx_recursive Ta recursive mutex with timeout support +.El +.Pp +The underlaying +.Nx +implementation of mutex types does not distinguish between +.Dv mtx_plain +and +.Dv mtx_timed , +however portable code must keep the distinction. +.Pp +The +.Fn mtx_lock +function locks the +.Fa mtx +object. +It is required the never lock multiple times the same +.Fa mtx +object without the +.Dv mtx_recursive +property. +If the +.Fa mtx +object is already locked by another thread, +caller of +.Fa mtx_lock +blocks until lock becomes available. +.Pp +The +.Fn mtx_timedlock +function tries to lock the +.Fa mtx +object. +In case of blocked resource by another thread, +this call blocks with specified timeout in the +.Fa ts +argument. +The timeout argument is +.Dv TIME_UTC +based time of +.Dv timespec +type. +It is required the never lock multiple times the same +.Fa mtx +object without the +.Dv mtx_recursive +property. +In portable code there must be used +.Fa mtx +object with the +.Dv mtx_recursive +property. +.Pp +The +.Fn mtx_trylock +function call attempts to lock the +.Fa mtx +object. +This function does not block if another thread already locked the +.Fa mtx +object, but immediately returns indicating proper status. +.Pp +The +.Fn mtx_unlock +function unlocks the +.Fa mtx +object. +This call must be proceded with lock by the calling thread. +.Sh RETURN VALUES +The +.Fn mtx_destroy +function returns +.Dv thrd_success +on success, otherwise +.Dv thrd_busy +if the value +.Dv mtx +is locked by another thread or +.Dv thrd_error +if the value +.Dv mtx +is invalid. +.Pp +The +.Fn mtx_init +function returns +.Dv thrd_success +on success or +.Dv thrd_error +on failure. +.Pp +The +.Fn mtx_lock +function returns +.Dv thrd_success +on success or +.Dv thrd_error +on failure. +.Pp +The +.Fn mtx_lock +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 mtx_trylock +function returns +.Dv thrd_success +on success, +otherwise +.Dv thrd_timedout +to indicate that +.Fa mtx +object is already locked or +.Dv thrd_error +on failure. +.Pp +The +.Fn mtx_unlock +function returns +.Dv thrd_success +on success, +otherwise +.Dv thrd_timedout +to indicate that +.Fa mtx +object is already locked or +.Dv thrd_error +on failure. +.Sh SEE ALSO +.Xr pthread_mutex 3 , +.Xr stdthreads 3 +.Sh STANDARDS +The +.Nm +interface conforms to +.St -isoC-2011 +with extension in the +.Fn mtx_destroy +function. +.Sh HISTORY +This interface first appeared in +.Nx 8 . +.Sh AUTHORS +.An Kamil Rytarowski Aq Mt kamil@NetBSD.org Index: lib/libstdthreads/mtx.c =================================================================== RCS file: lib/libstdthreads/mtx.c diff -N lib/libstdthreads/mtx.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lib/libstdthreads/mtx.c 29 Oct 2016 02:58:48 -0000 @@ -0,0 +1,171 @@ +/* $NetBSD$ */ + +/*- + * 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. + */ + +#include +__RCSID("$NetBSD$"); + +#include +#include +#include +#include + +int +mtx_destroy(mtx_t *mtx) +{ + + _DIAGASSERT(mtx != NULL); + + /* + * The cnd_destroy(3) function that conforms to C11 returns no value + * Extend this interface and return errors, instread of silently + * breaking behind the scenes. + */ + switch (pthread_mutex_destroy(mtx)) { + case 0: + return thrd_success; + case EBUSY: + return thrd_busy; + case EINVAL: + default: + return thrd_error; + } +} + +static inline int +mtx_init_default(mtx_t *mtx) +{ + + _DIAGASSERT(mtx != NULL); + + if (pthread_mutex_init(mtx, NULL) != 0) + return thrd_error; + + return thrd_success; +} + +static inline int +mtx_init_recursive(mtx_t *mtx) +{ + pthread_mutexattr_t attr; + + _DIAGASSERT(mtx != NULL); + + if (pthread_mutexattr_init(&attr) != 0) + return thrd_error; + + if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE) != 0) { + pthread_mutexattr_destroy(&attr); + + return thrd_error; + } + + if (pthread_mutex_init(mtx, &attr) == 0) + return thrd_success; + + pthread_mutexattr_destroy(&attr); + + return thrd_error; +} + +int +mtx_init(mtx_t *mtx, int type) +{ + + _DIAGASSERT(mtx != NULL); + + switch (type) { + case mtx_plain: + case mtx_timed: + return mtx_init_default(mtx); + case mtx_plain | mtx_recursive: + case mtx_timed | mtx_recursive: + return mtx_init_recursive(mtx); + default: + return thrd_error; + } +} + +int +mtx_lock(mtx_t *mtx) +{ + + _DIAGASSERT(mtx != NULL); + + if (pthread_mutex_lock(mtx) == 0) + return thrd_success; + + return thrd_error; +} + +int +mtx_timedlock(mtx_t *__restrict mtx, const struct timespec *__restrict ts) +{ + + _DIAGASSERT(mtx != NULL); + _DIAGASSERT(ts != NULL); + + switch(pthread_mutex_timedlock(mtx, ts)) { + case 0: + return thrd_success; + case ETIMEDOUT: + return thrd_timedout; + default: + return thrd_error; + } +} + +int +mtx_trylock(mtx_t *mtx) +{ + + _DIAGASSERT(mtx != NULL); + + switch(pthread_mutex_trylock(mtx)) { + case 0: + return thrd_success; + case EBUSY: + return thrd_busy; + default: + return thrd_error; + } +} + +int +mtx_unlock(mtx_t *mtx) +{ + + _DIAGASSERT(mtx != NULL); + + if (pthread_mutex_unlock(mtx) == 0) + return thrd_success; + + return thrd_error; +} Index: lib/libstdthreads/shlib_version =================================================================== RCS file: lib/libstdthreads/shlib_version diff -N lib/libstdthreads/shlib_version --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lib/libstdthreads/shlib_version 29 Oct 2016 02:58:48 -0000 @@ -0,0 +1,5 @@ +# $NetBSD$ +# Remember to update distrib/sets/lists/base/shl.* when changing +# +major=0 +minor=0 Index: lib/libstdthreads/stdthreads.3 =================================================================== RCS file: lib/libstdthreads/stdthreads.3 diff -N lib/libstdthreads/stdthreads.3 --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lib/libstdthreads/stdthreads.3 29 Oct 2016 02:58:48 -0000 @@ -0,0 +1,111 @@ +.\" $NetBSD$ +.\" +.\" 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 STDTHREDS 3 +.Os +.Sh NAME +.Nm stdthreads +.Nd thread support library +.Sh LIBRARY +.Lb libstdthreads +.Sh SYNOPSIS +.In threads.h +.Sh DESCRIPTION +Portable Threads library provides an implementation of portable threading +interface, built on top of the +.Xr pthread 3 +native interfaces. +This library is composed of: +.Bl -dash +.It +Initialization functions. +.It +Condition variable functions. +.It +Mutex functions. +.It +Thread functions. +.It +Thread-specifig storage functions. +.El +.Pp +This API shall not be used in the same time with other interfaces, +including C++ threads and native POSIX threads. +.Bl -column "mtx_timedwait" +.It Sy "Function" Ta Sy "Summary" +.It Xr call_once 3 Ta calls function exactly once +.It Xr cnd_broadcast 3 Ta unblocks all threads blocked on a condition +.It Xr cnd_destroy 3 Ta releases all resources used by a condition +.It Xr cnd_init 3 Ta creates a condition variable +.It Xr cnd_signal 3 Ta unblocks one of threads blocked on a condition +.It Xr cnd_timedwait 3 Ta unlocks a mutex and blocks until a signal or timeout +.It Xr cnd_wait 3 Ta unlocks a mutex and blocks until a signal +.It Xr mtx_destroy 3 Ta releases resources used by a mutex +.It Xr mtx_init 3 Ta creates a mutex object with requested properties +.It Xr mtx_lock 3 Ta blocks on a mutex optionally with a recursive type +.It Xr mtx_timedwait 3 Ta tries to block until it locks a mutex or timeout +.It Xr mtx_trylock 3 Ta tries to lock a mutex +.It Xr mtx_unlock 3 Ta unlocks a mutex +.It Xr thrd_create 3 Ta creates a thread executing a function with a parameter +.It Xr thrd_current 3 Ta identifies the thread that called this function +.It Xr thrd_detach 3 Ta dispose of resources allocatd to a thread on exit +.It Xr thrd_equal 3 Ta determines whether two threads reffer the same thread +.It Xr thrd_exit 3 Ta terminates a calling thread and sets its result code +.It Xr thrd_join 3 Ta joins a thread with the current one and blocks +.It Xr thrd_sleep 3 Ta suspends a calling thread until a signal or timeout +.It Xr tss_create 3 Ta crates a thread-specific storage pointer with a dtor +.It Xr tss_delete 3 Ta releases resources used by a thread-specific storage +.It Xr tss_get 3 Ta gets a value of thread-specific storage from a key +.It Xr tss_set 3 Ta sets a value of thread-specific storage to a key +.El +.Sh SEE ALSO +.Xr c11 1 , +.Xr pthread 3 , +.Xr c 7 +.Sh STANDARDS +The +.Nm +library interfaces conform to +.St -isoC-2011 . +.Pp +Keeping them in a separate library is a +.Nx +extension. +The reasoning for it is its optional nature in the standard and +avoidandce of +.Lb libpthread +linking in the +.Lb libc +library. +.Sh HISTORY +This interface first appeared in +.Nx 8 . +.Sh AUTHORS +.An Kamil Rytarowski Aq Mt kamil@NetBSD.org Index: lib/libstdthreads/thrd.3 =================================================================== RCS file: lib/libstdthreads/thrd.3 diff -N lib/libstdthreads/thrd.3 --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lib/libstdthreads/thrd.3 29 Oct 2016 02:58:48 -0000 @@ -0,0 +1,260 @@ +.\" $NetBSD$ +.\" +.\" 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 THRD 3 +.Os +.Sh NAME +.Nm thrd +.Nd thread functions +.Sh LIBRARY +.Lb libstdthreads +.Sh SYNOPSIS +.In threads.h +.Ft int +.Fn thrd_create "thrd_t *thr" "thrd_start_t func" "void *arg" +.Ft thrd_t +.Fn thrd_current "void" +.Ft int +.Fn thrd_detach "thrd_t thr" +.Ft int +.Fn thrd_equal "thrd_t t1" "thrd_t t2" +.Ft __dead void +.Fn thrd_exit "intptr_t res" +.Ft int +.Fn thrd_join "thrd_t thr" "intptr_t *res" +.Ft int +.Fn thrd_sleep "const struct timespec *duration" "struct timespec *remaining" +.Ft void +.Fn thrd_yield "void" +.Sh DESCRIPTION +The +.Nm +interface operates over opaque object of the +.Dv thrd_t +type. +.Pp +The +.Fn thrd_create +function is used to create a new thread, calling +.Fa func +with +.Fa arg +parameter. +This function initializes the +.Fa thr +object with the identifier of newly created thread. +The completion of +.Fn thrd_create +is synchronized with the start of the newly produced thread. +It is possible to reuse the +.Fa thr +object once the thread has terminated either by joining another thread +operation or been detached. +.Pp +The +.Fn thrd_current +function returns thread identifier. +.Pp +The +.Fn thrd_detach +function is used to indicate that storage for the +.Fa thr +object can be reclaimed on thread's termination. +The +.Fa thr +object cannot be already detached or joined. +.Pp +The +.Fn thrd_equal +function is used to check whether two +.Fa t1 +and +.Fa t2 +objects refer to the same thread. +.Pp +The +.Fn thrd_exit +function terminates calling thread and passes the +.Fa res +value, that might be read by the +.Fn thrd_join +function. +The program terminates once all threads has been terminated with +result equivalent to calling the +.Xr exit 3 +function with the +.Dv EXIT_SUCCESS +status. +The +.Fn thrd_join +function joins the +.Fa thr +thread, waiting and blocking until it has terminated. +The +.Fa res +parameter points to a variable that will store the status passed from the +joined function. +If +.Fa res +is +.Dv NULL +then the status from the +.Fn thrd_exit +function is ignored. +The +.Nx +extension is to pass the +.Fa res +value of type +.Dv intptr_t +to more properly map the underlaying POSIX implementation and use-cases +and allow passing structures accessible with pointers. +.Pp +The +.Fn thrd_sleep +function suspends execution of the calling thread until either +a signal is received or the interval specified in the +.Fa duration +argument has been passed. +The +.Fa remaining +parameter stores requested timeout reduced with the time actually suspended. +This argument is used when the +.Fn thrd_sleep +has been interrupted. +It is valid code to point both arguments +.Fa duration +and +.Fa remaining +to the same object. +It is not guaranteed that sleep will not take longer than specified +.Fa duration , +however unless interrupted with a signal it will not take shorter +than specified interval. +.Pp +The +.Fn thrd_yield +function yields a process voluntarily and gives other threads a chance to run +without waiting for any involuntary preemptive switch. +.Sh RETURN VALUES +The +.Fn thrd_create +function returns +.Dv thrd_success +on success, otherwise +.Dv thrd_nomem +if not sufficient memory could be allocated or +.Dv thrd_error +on other error. +.Pp +The +.Fn thrd_current +function returns identifier of the calling thread. +.Pp +The +.Fn thrd_detach +function returns +.Dv thrd_current +on success or +.Dv thrd_error +on failure. +.Pp +The +.Fn thrd_equal +function returns non-zero if +.Fa t0 +and +.Fa t1 +refer to the same thread, +otherwise it will return 0. +.Pp +The +.Fn thrd_exit +function does not return. +The standard attributes this function with the +.Dv _Noreturn +keyword, +however in the +.Nx +version it is attributed with the traditional and functionally equivalent +.Dv __dead +keyword. +.Pp +The +.Fn thrd_join +function returns +.Dv thrd_success +on success or +.Dv thrd_error +on failure. +.Pp +The +.Fn thrd_sleep +function returns +.Dv 0 +on success (as the requested time has elapsed), +.Dv -1 +once the function was interrupted by a signal +or a negative value to indicate error. +The +.Nx +implementation returns +.Dv -2 +on error. +.Pp +The +.Fn thrd_yield +returns no value. +.Sh SEE ALSO +.Xr nanosleep 2 , +.Xr pthread_create 3 , +.Xr pthread_detach 3 , +.Xr pthread_equal 3 , +.Xr pthread_exit 3 , +.Xr pthread_join 3 , +.Xr pthread_self 3 , +.Xr sched 3 , +.Xr stdthreads 3 +.Sh STANDARDS +The +.Nm +interface conforms to +.St -isoC-2011 +with extensions in the +.Fn thrd_exit +and +.Fn thrd_join +function. +The +.Sh HISTORY +This interface first appeared in +.Nx 8 . +.Sh AUTHORS +.An Kamil Rytarowski Aq Mt kamil@NetBSD.org Index: lib/libstdthreads/thrd.c =================================================================== RCS file: lib/libstdthreads/thrd.c diff -N lib/libstdthreads/thrd.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lib/libstdthreads/thrd.c 29 Oct 2016 02:58:48 -0000 @@ -0,0 +1,137 @@ +/* $NetBSD$ */ + +/*- + * 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. + */ + +#include +__RCSID("$NetBSD$"); + +#include +#include +#include +#include +#include +#include + +int +thrd_create(thrd_t *thr, thrd_start_t func, void *arg) +{ + + _DIAGASSERT(thr != NULL); + _DIAGASSERT(func != NULL); + + switch(pthread_create(thr, NULL, (void *(*)(void *))func, arg)) { + case 0: + return thrd_success; + case EAGAIN: + return thrd_nomem; + default: + return thrd_error; + } +} + +thrd_t +thrd_current(void) +{ + + return pthread_self(); +} + +int +thrd_detach(thrd_t thr) +{ + + _DIAGASSERT(thr != NULL); + + if (pthread_detach(thr) == 0) + return thrd_success; + + return thrd_error; +} + +int +thrd_equal(thrd_t t1, thrd_t t2) +{ + + _DIAGASSERT(t1 != NULL); + _DIAGASSERT(t2 != NULL); + + return !pthread_equal(t1, t2); +} + +__dead void +thrd_exit(intptr_t res) +{ + + pthread_exit((void *)res); +} + +int +thrd_join(thrd_t thrd, intptr_t *res) +{ + void *ptr; + + _DIAGASSERT(thrd != NULL); + + if (pthread_join(thrd, &ptr) == 0) { + if (res) + *res = (intptr_t)ptr; + + return thrd_success; + } + + return thrd_error; +} + +int +thrd_sleep(const struct timespec *duration, struct timespec *remaining) +{ + + _DIAGASSERT(duration != NULL); + + /* Use clock_nanosleep(3) to skip handling errno */ + + switch (clock_nanosleep(CLOCK_MONOTONIC, TIMER_RELTIME, duration, + remaining)) { + case 0: + return 0; + case EINTR: + return -1; + default: + /* Negative value different than -1 */ + return -2; + } +} + +void +thrd_yield(void) +{ + + sched_yield(); +} Index: lib/libstdthreads/threads.h =================================================================== RCS file: lib/libstdthreads/threads.h diff -N lib/libstdthreads/threads.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lib/libstdthreads/threads.h 29 Oct 2016 02:58:48 -0000 @@ -0,0 +1,121 @@ +/* $NetBSD$ */ + +/*- + * 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. + */ + +#ifndef _THREADS_H_ +#define _THREADS_H_ + +#include +#include +#include +#include +#include + +/* ISO/IEC 9899:201x 7.26.1/3 */ +#ifndef __thread_local_is_defined +#if ((__cplusplus - 0) < 201103L) +#define thread_local _Thread_local +#endif +#define __thread_local_is_defined +#endif /* __thread_local_is_defined */ + +#ifndef ONCE_FLAG_INIT +#define ONCE_FLAG_INIT _PTHREAD_ONCE_INIT +#endif /* ONCE_FLAG_INIT */ + +#ifndef TSS_DTOR_ITERATIONS +#define TSS_DTOR_ITERATIONS PTHREAD_DESTRUCTOR_ITERATIONS +#endif /* TSS_DTOR_ITERATIONS */ + +/* ISO/IEC 9899:201x 7.26.1/4 */ +typedef pthread_cond_t cnd_t; +typedef pthread_t thrd_t; +typedef int tss_t; +typedef pthread_mutex_t mtx_t; +typedef void (*tss_dtor_t) (void *); +typedef int (*thrd_start_t) (void *); +typedef pthread_once_t once_flag; + +/* ISO/IEC 9899:201x 7.26.1/5 */ +enum { + mtx_plain = 1, + mtx_recursive = 2, + mtx_timed = 4, + _MTX_MAXTYPE = 0x7fffffff +}; + +enum { + thrd_timedout = -1, + thrd_success = 0, + thrd_busy = 1, + thrd_error = 2, + thrd_nomem = 3, + _THRD_MAXTYPE = 0x7fffffff +}; + +__BEGIN_DECLS +/* ISO/IEC 9899:201x 7.26.2 Initialization functions */ +void call_once(once_flag *, void (*)(void)); + +/* ISO/IEC 9899:201x 7.26.3 Condition variable functions */ +int cnd_broadcast(cnd_t *); +int cnd_destroy(cnd_t *); +int cnd_init(cnd_t *); +int cnd_signal(cnd_t *); +int cnd_timedwait(cnd_t * __restrict, mtx_t * __restrict, + const struct timespec * __restrict); +int cnd_wait(cnd_t *, mtx_t *); + +/* ISO/IEC 9899:201x 7.26.4 Mutex functions */ +int mtx_destroy(mtx_t *); +int mtx_init(mtx_t *, int); +int mtx_lock(mtx_t *); +int mtx_timedlock(mtx_t *__restrict, const struct timespec *__restrict); +int mtx_trylock(mtx_t *); +int mtx_unlock(mtx_t *); + +/* ISO/IEC 9899:201x 7.26.5 Thread functions */ +int thrd_create(thrd_t *, thrd_start_t, void *); +thrd_t thrd_current(void); +int thrd_detach(thrd_t); +int thrd_equal(thrd_t, thrd_t); +void thrd_exit(intptr_t) __dead; +int thrd_join(thrd_t, intptr_t *); +int thrd_sleep(const struct timespec *, struct timespec *); +void thrd_yield(void); + +/* ISO/IEC 9899:201x 7.26.6 Thread-specific storage functions */ +int tss_create(tss_t *, tss_dtor_t); +int tss_delete(tss_t); +void *tss_get(tss_t); +int tss_set(tss_t, void *); +__END_DECLS + +#endif Index: lib/libstdthreads/tss.3 =================================================================== RCS file: lib/libstdthreads/tss.3 diff -N lib/libstdthreads/tss.3 --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lib/libstdthreads/tss.3 29 Oct 2016 02:58:48 -0000 @@ -0,0 +1,173 @@ +.\" $NetBSD$ +.\" +.\" 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 TSS 3 +.Os +.Sh NAME +.Nm tss +.Nd thread-specific storage functions +.Sh LIBRARY +.Lb libstdthreads +.Sh SYNOPSIS +.In threads.h +.Ft int +.Fn tss_create "tss_t *key" "tss_dtor_t dtor" +.Ft void +.Fn tss_delete "tss_t key" +.Ft void * +.Fn tss_get "tss_t key" +.Ft int +.Fn tss_set "tss_t key" "void *val" +.Vt #define TSS_DTOR_ITERATIONS /* implementation specified */ +.Sh DESCRIPTION +There are two groups of storage in C programs: +.Bl -dash +.It +local storage, +.It +global storage. +.El +Multithreaded programs in C add the third group +.Sy thread-specific storage . +This data is private to thread and every entry of this type has associated +.Dv tss_t +opaque key that is global to all threads in the process. +A thread using the +.Dv tss_t * +pointer accesses private data. +.Pp +The +.Fn tss_create +function creates a thread-specific storage with the +.Fa key +handler with optional destructor +.Fa dtor . +If the +.Fa dtor +parameter is not +.Dv NULL +then specified appropriate destructor will be called on thread termination. +Destructor is not called if a thread called the +.Fn tss_delete +function for the specified +.Fa key . +If, +after all the destructors have been called for all +.Dv non-NULL +values with associated destructors, +ther are still some +.Dv non-NULL values with +associated destructors, +then the process is repeated. +If, +after at least +.Dv TSS_DTOR_ITERATIONS +iterations of destructor calls for outstanding +.Dv non-NULL +values, +there are still some +.Dv non-NULL +values with associated destructors, +the +.Nx +implementation stops further calling destructors. +The +.Xr thrd_exit +function must not be called from a destructor. +As the extension of +.Nx +the +.Fn tss_delete +function returns status of operation. +.Pp +The +.Fn tss_delete +function frees resources used by the thread-specific storage identified by the +.Fa key +object. +This function can be called inside the +.Fa dtor +destructor, +however the destructor is not called by +.Fn tss_delete . +.Pp +The +.Fn tss_get +and +.Fn tss_set +functions are used to get and set thread-specific storage. +.Sh RETURN VALUES +The +.Fn tss_create +function returns +.Dv thrd_success +on success, otherwise +.Dv thrd_error +on failure. +.Pp +The +.Fn tss_delete +function returns +.Dv thrd_success +on success, otherwise +.Dv thrd_error +on failure. +.Pp +The +.Fn tss_get +returns pointer to thread-specific storage on success or +.Dv NULL +on failure. +.Pp +The +.Fn tss_delete +function returns +.Dv thrd_success +on success, otherwise +.Dv thrd_error +on failure. +.Sh SEE ALSO +.Xr pthread_getspecific 3 , +.Xr pthread_key_create 3 , +.Xr stdthreads 3 +.Sh STANDARDS +The +.Nm +interface conforms to +.St -isoC-2011 +with extensions in the +.Fn tss_delete +function. +The +.Sh HISTORY +This interface first appeared in +.Nx 8 . +.Sh AUTHORS +.An Kamil Rytarowski Aq Mt kamil@NetBSD.org Index: lib/libstdthreads/tss.c =================================================================== RCS file: lib/libstdthreads/tss.c diff -N lib/libstdthreads/tss.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lib/libstdthreads/tss.c 29 Oct 2016 02:58:48 -0000 @@ -0,0 +1,91 @@ +/* $NetBSD$ */ + +/*- + * 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. + */ + +#include +__RCSID("$NetBSD$"); + +#include +#include +#include +#include + +int +tss_create(tss_t *key, tss_dtor_t dtor) +{ + + _DIAGASSERT(key != NULL); + + if (pthread_key_create(key, dtor) == 0) + return thrd_success; + + return thrd_error; +} + +int +tss_delete(tss_t key) +{ + + _DIAGASSERT(key != NULL); + + /* + * The tss_delete(3) function that conforms to C11 returns no value + * Extend this interface and return errors, instread of silently + * breaking behind the scenes. + */ + switch (pthread_key_delete(key)) { + case 0: + return thrd_success; + case EINVAL: + default: + return thrd_error; + } +} + +void * +tss_get(tss_t key) +{ + + _DIAGASSERT(key != NULL); + + return pthread_getspecific(key); +} + +int +tss_set(tss_t key, void *val) +{ + + _DIAGASSERT(key != NULL); + + if (pthread_setspecific(key, val) == 0) + return thrd_success; + + return thrd_error; +}