OpenBSD CVS

CVS log for src/lib/librthread/Attic/rthread_sync.c


[BACK] Up to [local] / src / lib / librthread

Request diff between arbitrary revisions


Default branch: MAIN


Revision 1.47, Tue Sep 5 02:40:54 2017 UTC (6 years, 9 months ago) by guenther
Branch: MAIN
CVS Tags: HEAD
Changes since 1.46: +1 -1 lines
FILE REMOVED

Move mutex, condvar, and thread-specific data routes, pthread_once, and
pthread_exit from libpthread to libc, along with low-level bits to
support them.  Major bump to both libc and libpthread.

Requested by libressl team.  Ports testing by naddy@
ok kettenis@

Revision 1.46 / (download) - annotate - [select for diffs], Sat Jul 29 16:42:10 2017 UTC (6 years, 10 months ago) by deraadt
Branch: MAIN
Changes since 1.45: +0 -2 lines
Diff to previous 1.45 (colored)

not all the world is an i386.  Back out breakage.

Revision 1.45 / (download) - annotate - [select for diffs], Sat Jul 29 08:36:23 2017 UTC (6 years, 10 months ago) by pirofti
Branch: MAIN
Changes since 1.44: +3 -1 lines
Diff to previous 1.44 (colored)

Use memory barriers to prevent pointer use before initialization.

This work was sparked by the topic posted on hn by wuch. I am still not
sure that this fixes the defect he claims to have observed because I was
not able to create a proper regress test for it to manifest.

To that end, a proof of concept is more than welcomed!
Thank you for the report!

Discussed with and OK kettenis@, tedu@.

Revision 1.44 / (download) - annotate - [select for diffs], Sun Sep 4 10:13:35 2016 UTC (7 years, 9 months ago) by akfaew
Branch: MAIN
CVS Tags: OPENBSD_6_1_BASE, OPENBSD_6_1
Changes since 1.43: +8 -9 lines
Diff to previous 1.43 (colored)

Get rid of ticket support, replace "struct _spinlock" with "_atomic_lock_t".

ok tedu@

Revision 1.43 / (download) - annotate - [select for diffs], Sat Sep 3 16:44:20 2016 UTC (7 years, 9 months ago) by akfaew
Branch: MAIN
Changes since 1.42: +7 -8 lines
Diff to previous 1.42 (colored)

Remove _USING_TICKETS, it's defined as 0. No functional change.

ok tedu@ mpi@

Revision 1.42 / (download) - annotate - [select for diffs], Sat May 7 19:05:22 2016 UTC (8 years, 1 month ago) by guenther
Branch: MAIN
CVS Tags: OPENBSD_6_0_BASE, OPENBSD_6_0
Changes since 1.41: +20 -13 lines
Diff to previous 1.41 (colored)

Use a Thread Information Block in both single and multi-threaded programs.
This stores errno, the cancelation flags, and related bits for each thread
and is allocated by ld.so or libc.a.  This is an ABI break from 5.9-stable!

Make libpthread dlopen'able by moving the cancelation wrappers into libc
and doing locking and fork/errno handling via callbacks that libpthread
registers when it first initializes.  'errno' *must* be declared via
<errno.h> now!

Clean up libpthread's symbol exports like libc.

On powerpc, offset the TIB/TCB/TLS data from the register per the ELF spec.

Testing by various, particularly sthen@ and patrick@
ok kettenis@

Revision 1.41 / (download) - annotate - [select for diffs], Fri Apr 15 21:04:04 2016 UTC (8 years, 1 month ago) by guenther
Branch: MAIN
Changes since 1.40: +2 -1 lines
Diff to previous 1.40 (colored)

PROTO_NORMAL(pthread_cond_signal) requires DEF_STD(pthread_cond_signal)

Revision 1.40 / (download) - annotate - [select for diffs], Sat Apr 2 19:56:53 2016 UTC (8 years, 2 months ago) by guenther
Branch: MAIN
Changes since 1.39: +9 -1 lines
Diff to previous 1.39 (colored)

Wrap <pthread.h> and <pthread_np.h> to eliminate PLT entries for internal
references.  Use _thread_pagesize for the semaphore mmap size instead of
calling getpagesize() each time.

ok beck@

Revision 1.39 / (download) - annotate - [select for diffs], Sat Jun 1 23:06:26 2013 UTC (11 years ago) by tedu
Branch: MAIN
CVS Tags: OPENBSD_5_9_BASE, OPENBSD_5_9, OPENBSD_5_8_BASE, OPENBSD_5_8, OPENBSD_5_7_BASE, OPENBSD_5_7, OPENBSD_5_6_BASE, OPENBSD_5_6, OPENBSD_5_5_BASE, OPENBSD_5_5, OPENBSD_5_4_BASE, OPENBSD_5_4
Changes since 1.38: +10 -9 lines
Diff to previous 1.38 (colored)

something's not quite right yet. ticket locks result in more CPU usage
and spinning in kernel. partially back out, but in a way that makes going
forward again easy.
seen by ajacoutot

Revision 1.38 / (download) - annotate - [select for diffs], Sat Jun 1 20:47:40 2013 UTC (11 years ago) by tedu
Branch: MAIN
Changes since 1.37: +11 -11 lines
Diff to previous 1.37 (colored)

cleanup and consolidate the spinlock_lock (what a name!) code.
it's now atomic_lock to better reflect its usage, and librthread now
features a new spinlock that's really a ticket lock.
thrlseep can handle both types of lock via a flag in the clock arg.
(temp back compat hack)
remove some old stuff that's accumulated along the way and no longer used.
some feedback from dlg, who is concerned with all things ticket lock.
(you need to boot a new kernel before installing librthread)

Revision 1.37 / (download) - annotate - [select for diffs], Sat Jun 1 19:47:28 2013 UTC (11 years ago) by tedu
Branch: MAIN
Changes since 1.36: +2 -2 lines
Diff to previous 1.36 (colored)

fix wrong fn name in debug

Revision 1.36 / (download) - annotate - [select for diffs], Sat Apr 14 12:07:49 2012 UTC (12 years, 2 months ago) by kurt
Branch: MAIN
CVS Tags: OPENBSD_5_3_BASE, OPENBSD_5_3, OPENBSD_5_2_BASE, OPENBSD_5_2
Changes since 1.35: +8 -3 lines
Diff to previous 1.35 (colored)

Add new mutex type, PTHREAD_MUTEX_STRICT_NP which checks for application
errors similar to PTHREAD_MUTEX_ERRORCHECK, however upon error it aborts.
The rational is that many applications don't check the return values on
pthread functions and will miss the errors that ERRORCHECK returns.
PTHREAD_MUTEX_STRICT_NP will be our default mutex type for awhile
okay guenther@ dcoppa@

Revision 1.35 / (download) - annotate - [select for diffs], Fri Apr 13 13:50:37 2012 UTC (12 years, 2 months ago) by kurt
Branch: MAIN
Changes since 1.34: +13 -5 lines
Diff to previous 1.34 (colored)

Use PTHREAD_MUTEX_DEFAULT in static init and mutexattr_init. If the
default mutex type changes to NORMAL, when there is an uninitialized
mutex provided to unlock, allow it to succeed similar to an unlocked
mutex. For other cases abort instead of segfault. okay guenther@

Revision 1.34 / (download) - annotate - [select for diffs], Fri Apr 13 12:39:28 2012 UTC (12 years, 2 months ago) by kurt
Branch: MAIN
Changes since 1.33: +31 -7 lines
Diff to previous 1.33 (colored)

Per POSIX, PTHREAD_MUTEX_NORMAL type mutexes have undefined behavior for
certain conditions. In the case of unlocking an unlocked mutex we will
allow that to succeed, all other undefined behaviors will result in an
immediate abort(). okay guenther@

Revision 1.33 / (download) - annotate - [select for diffs], Tue Feb 28 02:41:56 2012 UTC (12 years, 3 months ago) by guenther
Branch: MAIN
Changes since 1.32: +20 -1 lines
Diff to previous 1.32 (colored)

Our default mutex type is PTHREAD_MUTEX_ERRORCHECK, for which trying
to unlock an uninitialized mutex is required to return EPERM, so add
the necessary checks.

For recursive mutexes, return an error from pthread_mutex_lock()
if the count would overflow.

problem observed in glib testing by aja@

Revision 1.32 / (download) - annotate - [select for diffs], Thu Feb 23 07:58:25 2012 UTC (12 years, 3 months ago) by guenther
Branch: MAIN
Changes since 1.31: +16 -3 lines
Diff to previous 1.31 (colored)

PTHREAD_MUTEX_NORMAL mutexes are supposed to self-deadlock, not abort.
That deadlock can be exited via a timeout for pthread_mutex_timedlock().
Unwind all the state when pthread_mutex_timedlock() times out

Revision 1.31 / (download) - annotate - [select for diffs], Thu Feb 23 04:43:06 2012 UTC (12 years, 3 months ago) by guenther
Branch: MAIN
Changes since 1.30: +19 -36 lines
Diff to previous 1.30 (colored)

Add pthread_condattr_{get,set}clock(), requested by aja@
Add pthread_mutex_timedlock(), requested by dcoppa@

Revision 1.30 / (download) - annotate - [select for diffs], Wed Jan 25 06:55:08 2012 UTC (12 years, 4 months ago) by guenther
Branch: MAIN
CVS Tags: OPENBSD_5_1_BASE, OPENBSD_5_1
Changes since 1.29: +1 -2 lines
Diff to previous 1.29 (colored)

@($*&  Merging patches resulted in a line being duplicated instead of
moved.  Unlocking a spinlock twice is bad, mmkay?

Revision 1.29 / (download) - annotate - [select for diffs], Tue Jan 17 02:34:18 2012 UTC (12 years, 4 months ago) by guenther
Branch: MAIN
Changes since 1.28: +428 -44 lines
Diff to previous 1.28 (colored)

Reimplement mutexes, condvars, and rwlocks to eliminate bugs,
particularly the "consume the signal you just sent" hang, and putting
the wait queues in userspace.

Do cancellation handling in pthread_cond_*wait(), pthread_join(),
and sem_wait().

Add __ prefix to thr{sleep,wakeup,exit,sigdivert}() syscalls; add
'abort" argument to thrsleep to close cancellation race; make
thr{sleep,wakeup} return errno values via *retval to avoid touching
userspace errno.

Revision 1.28 / (download) - annotate - [select for diffs], Wed Jan 4 17:43:34 2012 UTC (12 years, 5 months ago) by mpi
Branch: MAIN
Changes since 1.27: +2 -178 lines
Diff to previous 1.27 (colored)

Split out the semaphore functions.

ok guenther@

Revision 1.27 / (download) - annotate - [select for diffs], Wed Dec 21 23:59:03 2011 UTC (12 years, 5 months ago) by guenther
Branch: MAIN
Changes since 1.26: +2 -275 lines
Diff to previous 1.26 (colored)

Split out the pthread_rwlock* and pthread_once() functions from rthread_sync.c
to new files rthread_rwlock.c, rthread_rwlockattr.c, and rthread_once.c

Revision 1.26 / (download) - annotate - [select for diffs], Wed Dec 21 00:49:47 2011 UTC (12 years, 5 months ago) by guenther
Branch: MAIN
Changes since 1.25: +9 -44 lines
Diff to previous 1.25 (colored)

Split out the pthread_mutexattr_* functions from rthread_sync.c to
new file rthread_mutexattr.c.  Add basic implementations of
pthread_mutexattr_{set,get}{protocol,prioceiling}

Requested by aja

Revision 1.25 / (download) - annotate - [select for diffs], Sun Nov 6 11:48:59 2011 UTC (12 years, 7 months ago) by guenther
Branch: MAIN
Changes since 1.24: +1 -10 lines
Diff to previous 1.24 (colored)

Move <machine/spinlock.h> into rthread.h; strip out unnecessary #includes

Revision 1.24 / (download) - annotate - [select for diffs], Thu Sep 22 04:54:38 2011 UTC (12 years, 8 months ago) by guenther
Branch: MAIN
Changes since 1.23: +2 -2 lines
Diff to previous 1.23 (colored)

Return the correct errno (EBUSY) when pthread_mutex_trylock() is
called on an ERRORCHECK mutex that is locked by this thread.  Problem
observed by uwe@

Revision 1.23 / (download) - annotate - [select for diffs], Mon Apr 12 03:34:31 2010 UTC (14 years, 2 months ago) by guenther
Branch: MAIN
CVS Tags: OPENBSD_5_0_BASE, OPENBSD_5_0, OPENBSD_4_9_BASE, OPENBSD_4_9, OPENBSD_4_8_BASE, OPENBSD_4_8
Changes since 1.22: +68 -3 lines
Diff to previous 1.22 (colored)

Add pthread_rwlock_timed{rd,wr}lock().
Avoid missed wakeups in pthread_rwlock_{rd,wr}lock() by linking the spinlocks.

ok tedu@

Revision 1.22 / (download) - annotate - [select for diffs], Fri Nov 27 19:45:54 2009 UTC (14 years, 6 months ago) by guenther
Branch: MAIN
CVS Tags: OPENBSD_4_7_BASE, OPENBSD_4_7
Changes since 1.21: +12 -26 lines
Diff to previous 1.21 (colored)

Convert thrsleep() to an absolute timeout with clockid to eliminate a
race condition and prep for later support of pthread_condattr_setclock()

"get it in" deraadt@, tedu@, cheers by others

Revision 1.21 / (download) - annotate - [select for diffs], Thu Nov 19 03:31:36 2009 UTC (14 years, 6 months ago) by guenther
Branch: MAIN
Changes since 1.20: +3 -4 lines
Diff to previous 1.20 (colored)

pthread_rwlock_wrlock() should increment the count of writers just
once and not on every wakeup.

ok kurt@

Revision 1.20 / (download) - annotate - [select for diffs], Mon Oct 13 05:42:46 2008 UTC (15 years, 8 months ago) by kevlo
Branch: MAIN
CVS Tags: OPENBSD_4_6_BASE, OPENBSD_4_6, OPENBSD_4_5_BASE, OPENBSD_4_5
Changes since 1.19: +8 -15 lines
Diff to previous 1.19 (colored)

use calloc() instead of malloc() and memset()

"look good" tedu@

Revision 1.19 / (download) - annotate - [select for diffs], Fri Feb 22 09:18:28 2008 UTC (16 years, 3 months ago) by tedu
Branch: MAIN
CVS Tags: OPENBSD_4_4_BASE, OPENBSD_4_4, OPENBSD_4_3_BASE, OPENBSD_4_3
Changes since 1.18: +45 -3 lines
Diff to previous 1.18 (colored)

fix rwlocks to work with the "initialized" form, from Philip Guenther

Revision 1.18 / (download) - annotate - [select for diffs], Tue Jun 5 18:11:49 2007 UTC (17 years ago) by kurt
Branch: MAIN
CVS Tags: OPENBSD_4_2_BASE, OPENBSD_4_2
Changes since 1.17: +7 -1 lines
Diff to previous 1.17 (colored)

_FD_LOCK/UNLOCK() is libpthread specific and not needed for librthread, so
isolate its usage to libpthread only and replace with generic non-static
mutex support in the one place it is needed:
 - remove _FD_LOCK/UNLOCK from lseek and ftruncate in libc and make the
   functions weak so that libpthread can override with its own new
   versions that do the locking.
 - remove _thread_fd_lock/unlock() weak functions from libc and adjust
   libpthread for the change.
 - add generic _thread_mutex_lock/unlock/destroy() weak functions in libc
   to support non-static mutexes in libc and add libpthread and librthread
   implementations for them. libc can utilize non-static mutexes via the
   new _MUTEX_LOCK/UNLOCK/DESTROY() macros. Actually these new macros can
   support both static and non-static mutexes but currently only using
   them for non-static.
 - make opendir/closedir/readdir/readdir_r/seekdir/telldir() thread-safe
   for both thread libraries by using a non-static mutex in the struct
   _dirdesc (typedef DIR), utilizing it in the *dir functions and remove
   remaining and incorrect _FD_LOCK/UNLOCK() use in libc.
 - add comments to both thread libraries to indicate libc depends on the
   current implementation of static mutex initialization. suggested by
   marc@
 - major bump libc and libpthread due to function removal, structure
   change and weak symbol conversions.
okay marc@, tedu@

Revision 1.17 / (download) - annotate - [select for diffs], Fri May 25 22:38:39 2007 UTC (17 years ago) by kurt
Branch: MAIN
Changes since 1.16: +12 -5 lines
Diff to previous 1.16 (colored)

protect against races while initializing static mutexes. okay marc@ tedu@

Revision 1.16 / (download) - annotate - [select for diffs], Thu Jan 5 04:06:48 2006 UTC (18 years, 5 months ago) by marc
Branch: MAIN
CVS Tags: OPENBSD_4_1_BASE, OPENBSD_4_1, OPENBSD_4_0_BASE, OPENBSD_4_0, OPENBSD_3_9_BASE, OPENBSD_3_9
Changes since 1.15: +2 -2 lines
Diff to previous 1.15 (colored)


add -Wstrict-prototypes -Wmissing-prototypes -Wsign-compare
Minor tweaks to compile with the above, primarily in fixing
the conflicts between semaphore.h and rthread.h
"i like the additional warnings" tedu@

Revision 1.15 / (download) - annotate - [select for diffs], Sat Dec 31 20:07:41 2005 UTC (18 years, 5 months ago) by brad
Branch: MAIN
Changes since 1.14: +9 -1 lines
Diff to previous 1.14 (colored)

add pthread_mutexattr_gettype.

ok otto@

Revision 1.14 / (download) - annotate - [select for diffs], Fri Dec 30 04:05:55 2005 UTC (18 years, 5 months ago) by tedu
Branch: MAIN
Changes since 1.13: +4 -7 lines
Diff to previous 1.13 (colored)

prototype all the thread syscalls in rthread.h for now.
update for new thrwakeup that takes a count argument

Revision 1.13 / (download) - annotate - [select for diffs], Thu Dec 29 11:35:54 2005 UTC (18 years, 5 months ago) by otto
Branch: MAIN
Changes since 1.12: +2 -2 lines
Diff to previous 1.12 (colored)

the story in pthread_rwlockattr_destory() shoudl be destroyed

Revision 1.12 / (download) - annotate - [select for diffs], Thu Dec 22 06:49:48 2005 UTC (18 years, 5 months ago) by tedu
Branch: MAIN
Changes since 1.11: +4 -4 lines
Diff to previous 1.11 (colored)

more consistently use _rthread prefix for all not meant to be exported
interfaces that aren't static, and a few that are but which will change

Revision 1.11 / (download) - annotate - [select for diffs], Mon Dec 19 06:47:40 2005 UTC (18 years, 5 months ago) by tedu
Branch: MAIN
Changes since 1.10: +2 -2 lines
Diff to previous 1.10 (colored)

update copyright to 2005

Revision 1.10 / (download) - annotate - [select for diffs], Sun Dec 18 01:35:06 2005 UTC (18 years, 5 months ago) by tedu
Branch: MAIN
Changes since 1.9: +5 -1 lines
Diff to previous 1.9 (colored)

initialize all spinlocks to _SPINLOCK_UNLOCKED

Revision 1.9 / (download) - annotate - [select for diffs], Wed Dec 14 07:02:47 2005 UTC (18 years, 6 months ago) by tedu
Branch: MAIN
Changes since 1.8: +17 -3 lines
Diff to previous 1.8 (colored)

all is made clear: pthread_cond_timedwait takes absolute timeouts

Revision 1.8 / (download) - annotate - [select for diffs], Wed Dec 14 04:14:19 2005 UTC (18 years, 6 months ago) by tedu
Branch: MAIN
Changes since 1.7: +15 -3 lines
Diff to previous 1.7 (colored)

check for waiters when destroying a mutex or semaphore

Revision 1.7 / (download) - annotate - [select for diffs], Tue Dec 13 17:22:46 2005 UTC (18 years, 6 months ago) by tedu
Branch: MAIN
Changes since 1.6: +11 -3 lines
Diff to previous 1.6 (colored)

make the mutex unlock and sleep in pthread_cond_wait properly atomic

Revision 1.6 / (download) - annotate - [select for diffs], Tue Dec 13 07:04:34 2005 UTC (18 years, 6 months ago) by tedu
Branch: MAIN
Changes since 1.5: +7 -5 lines
Diff to previous 1.5 (colored)

several silly bugs in pthread_cond_timedwait.
1.  the time was off by a factor of 10
2.  wouldn't return error code if timeout was reached
3.  the big one.  thrsleep syscall doesn't return EWOULDBLOCK.  it
returns -1 and puts the error in errno.  doh.

Revision 1.5 / (download) - annotate - [select for diffs], Tue Dec 13 06:04:53 2005 UTC (18 years, 6 months ago) by tedu
Branch: MAIN
Changes since 1.4: +7 -7 lines
Diff to previous 1.4 (colored)

update thrsleep and thrwakeup - first arg changed from long to void *

Revision 1.4 / (download) - annotate - [select for diffs], Tue Dec 13 05:56:55 2005 UTC (18 years, 6 months ago) by tedu
Branch: MAIN
Changes since 1.3: +23 -4 lines
Diff to previous 1.3 (colored)

correct implementation of pthread_cond_signal.  it doesn't raise the sem
value if there are no waiters.

Revision 1.3 / (download) - annotate - [select for diffs], Wed Dec 7 03:18:39 2005 UTC (18 years, 6 months ago) by tedu
Branch: MAIN
Changes since 1.2: +89 -5 lines
Diff to previous 1.2 (colored)

add the posix semaphore functions.  this lets vlc work.
ok brad

Revision 1.2 / (download) - annotate - [select for diffs], Tue Dec 6 06:19:31 2005 UTC (18 years, 6 months ago) by tedu
Branch: MAIN
Changes since 1.1: +14 -1 lines
Diff to previous 1.1 (colored)

add pthread_once.  unfortunately, the public pthread.h header
defines the pthread_once_t internals, so we're stuck with them.

Revision 1.1 / (download) - annotate - [select for diffs], Sat Dec 3 18:16:19 2005 UTC (18 years, 6 months ago) by tedu
Branch: MAIN

add userland thread library.  incomplete, but functional

This form allows you to request diff's between any two revisions of a file. You may select a symbolic revision name using the selection box or you may type in a numeric name using the type-in text box.