OpenBSD CVS

CVS log for src/lib/librthread/rthread_sem.c


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

Request diff between arbitrary revisions


Default branch: MAIN


Revision 1.33 / (download) - annotate - [select for diffs], Sat May 14 14:52:20 2022 UTC (2 years ago) by cheloha
Branch: MAIN
CVS Tags: OPENBSD_7_5_BASE, OPENBSD_7_5, OPENBSD_7_4_BASE, OPENBSD_7_4, OPENBSD_7_3_BASE, OPENBSD_7_3, OPENBSD_7_2_BASE, OPENBSD_7_2, HEAD
Changes since 1.32: +2 -3 lines
Diff to previous 1.32 (colored)

librthread: validate timespec inputs with timespecisvalid(3)

ok millert@

Revision 1.32 / (download) - annotate - [select for diffs], Mon Apr 6 00:01:08 2020 UTC (4 years, 2 months ago) by pirofti
Branch: MAIN
CVS Tags: OPENBSD_7_1_BASE, OPENBSD_7_1, OPENBSD_7_0_BASE, OPENBSD_7_0, OPENBSD_6_9_BASE, OPENBSD_6_9, OPENBSD_6_8_BASE, OPENBSD_6_8, OPENBSD_6_7_BASE, OPENBSD_6_7
Changes since 1.31: +2 -2 lines
Diff to previous 1.31 (colored)

Update my email address.

Revision 1.31 / (download) - annotate - [select for diffs], Fri Nov 1 16:04:19 2019 UTC (4 years, 7 months ago) by mpi
Branch: MAIN
Changes since 1.30: +1 -2 lines
Diff to previous 1.30 (colored)

Remove duplicated header.

Revision 1.30 / (download) - annotate - [select for diffs], Tue Jan 29 17:43:23 2019 UTC (5 years, 4 months ago) by mpi
Branch: MAIN
CVS Tags: OPENBSD_6_6_BASE, OPENBSD_6_6, OPENBSD_6_5_BASE, OPENBSD_6_5
Changes since 1.29: +25 -29 lines
Diff to previous 1.29 (colored)

Rename 1-letter variables to be coherent with others futex(2) based
implementations.

ok pirofti@

Revision 1.29 / (download) - annotate - [select for diffs], Fri Jun 8 13:53:01 2018 UTC (6 years ago) by pirofti
Branch: MAIN
CVS Tags: OPENBSD_6_4_BASE, OPENBSD_6_4
Changes since 1.28: +47 -57 lines
Diff to previous 1.28 (colored)

New semaphore implementation making sem_post async-safe.

POSIX dictates that sem_post() needs to be async-safe here[0] and is
thus included in the list of safe functions to call from within a signal
handler here[1].

The old semaphore implementation is using spinlocks and __thrsleep to
synchronize between threads.

Let's say there are two threads: T0 and T1 and the semaphore has V=0.
T1 calls sem_wait() and it will now sleep (spinlock) until someone else
sem_post()'s. Let's say T0 sends a signal to T1 and exits.
The signal handler calls sem_post() which is meant to unblock T1 by
incrementing V. With the old semaphore implementation we we are now in a
deadlock as sem_post spinlocks on the same lock.

The new implementation does not suffer from this defect as it
uses futexes to resolve locking and thus sem_post does not need to spin.
Besides fixing this defect and making us POSIX compliant, this should
also improve performance as there should be less context switching and
thus less time spent in the kernel.

For architectures that do not provied futexes and atomic operations,
the old implementation will be used and it is now being renamed to
rthread_sem_compat as discussed with mpi@.

[0] -- http://pubs.opengroup.org/onlinepubs/9699919799/functions/sem_post.html
[1] -- http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html

OK visa@, mpi@, guenther@

Revision 1.28 / (download) - annotate - [select for diffs], Fri Apr 27 06:47:34 2018 UTC (6 years, 1 month ago) by guenther
Branch: MAIN
Changes since 1.27: +13 -9 lines
Diff to previous 1.27 (colored)

pthread_join() must not return EINTR
Simplify sem_trywait()

ok pirofti@ mpi@

Revision 1.27 / (download) - annotate - [select for diffs], Tue Apr 24 16:28:42 2018 UTC (6 years, 1 month ago) by pirofti
Branch: MAIN
Changes since 1.26: +8 -7 lines
Diff to previous 1.26 (colored)

Validate timespec and return ECANCELED when interrupted with SA_RESTART.

Discussing with mpi@ and guenther@, we decided to first fix the existing
semaphore implementation with regards to SA_RESTART and POSIX compliant
returns in the case where we deal with restartable signals.

Currently we return EINTR everywhere which is mostly incorrect as the
user can not know if she needs to recall the syscall or not. Return
ECANCELED to signal that SA_RESTART was set and EINTR otherwise.

Regression tests pass and so does the posixsuite. Timespec validation
bits are needed to pass the later.

OK mpi@, guenther@

Revision 1.26 / (download) - annotate - [select for diffs], Tue Sep 5 02:40:54 2017 UTC (6 years, 9 months ago) by guenther
Branch: MAIN
CVS Tags: OPENBSD_6_3_BASE, OPENBSD_6_3, OPENBSD_6_2_BASE, OPENBSD_6_2
Changes since 1.25: +4 -1 lines
Diff to previous 1.25 (colored)

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.25 / (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.24: +4 -4 lines
Diff to previous 1.24 (colored)

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

ok tedu@

Revision 1.24 / (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.23: +3 -4 lines
Diff to previous 1.23 (colored)

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

ok tedu@ mpi@

Revision 1.23 / (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.22: +23 -7 lines
Diff to previous 1.22 (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.22 / (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.21: +3 -3 lines
Diff to previous 1.21 (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.21 / (download) - annotate - [select for diffs], Thu Dec 10 13:02:24 2015 UTC (8 years, 6 months ago) by tedu
Branch: MAIN
CVS Tags: OPENBSD_5_9_BASE, OPENBSD_5_9
Changes since 1.20: +2 -2 lines
Diff to previous 1.20 (colored)

use geteuid to allow root to communicate with others.
report from Jeunder Yu

Revision 1.20 / (download) - annotate - [select for diffs], Fri Jan 16 16:48:52 2015 UTC (9 years, 4 months ago) by deraadt
Branch: MAIN
CVS Tags: OPENBSD_5_8_BASE, OPENBSD_5_8, OPENBSD_5_7_BASE, OPENBSD_5_7
Changes since 1.19: +2 -2 lines
Diff to previous 1.19 (colored)

Move to the <limits.h> universe.
review by millert, binary checking process with doug, concept with guenther

Revision 1.19 / (download) - annotate - [select for diffs], Fri Jun 27 23:21:47 2014 UTC (9 years, 11 months ago) by matthew
Branch: MAIN
CVS Tags: OPENBSD_5_6_BASE, OPENBSD_5_6
Changes since 1.18: +2 -2 lines
Diff to previous 1.18 (colored)

Fix mmap() flag usage: explicitly specify MAP_PRIVATE and drop useless
MAP_FILE and MAP_HASSEMAPHORE flags.

Discussed with deraadt, tedu, and kettenis

Revision 1.18 / (download) - annotate - [select for diffs], Wed Dec 11 16:24:16 2013 UTC (10 years, 6 months ago) by tedu
Branch: MAIN
CVS Tags: OPENBSD_5_5_BASE, OPENBSD_5_5
Changes since 1.17: +10 -4 lines
Diff to previous 1.17 (colored)

revert to return EPERM for sem_init pshared until it really works
reported by zhuk

Revision 1.17 / (download) - annotate - [select for diffs], Sun Dec 8 19:04:07 2013 UTC (10 years, 6 months ago) by fgsch
Branch: MAIN
Changes since 1.16: +2 -2 lines
Diff to previous 1.16 (colored)

Reduce the random name length when sem_init is called with pshared
following what is recommended for mkstemp. This reduces the number of calls
to sched_yield considerably.
tedu@ ok.

Revision 1.16 / (download) - annotate - [select for diffs], Tue Nov 26 11:24:43 2013 UTC (10 years, 6 months ago) by fgsch
Branch: MAIN
Changes since 1.15: +37 -44 lines
Diff to previous 1.15 (colored)

Remove unused var and include.  Fix errno values as per spec.
NULL semaphore in sem_close().  Minor cosmetic changes.
tedu@ zhuk@ ok

Revision 1.15 / (download) - annotate - [select for diffs], Fri Nov 22 07:48:41 2013 UTC (10 years, 6 months ago) by deraadt
Branch: MAIN
Changes since 1.14: +2 -2 lines
Diff to previous 1.14 (colored)

don't use PAGE_SIZE, it is not portable.  Ted can polish this after
if he wants, but let us get the tree building.

Revision 1.14 / (download) - annotate - [select for diffs], Thu Nov 21 17:43:57 2013 UTC (10 years, 6 months ago) by tedu
Branch: MAIN
Changes since 1.13: +16 -3 lines
Diff to previous 1.13 (colored)

handle the fourth vararg value to sem_open
ok zhuk and presumably fgsch who just sent me a similar diff

Revision 1.13 / (download) - annotate - [select for diffs], Wed Nov 20 23:18:17 2013 UTC (10 years, 6 months ago) by tedu
Branch: MAIN
Changes since 1.12: +53 -42 lines
Diff to previous 1.12 (colored)

shared semaphore fixes. first, eliminate the sem inside a sem indirection.
it's not needed (mindless holdover from earlier prototype). everything is
simpler and sem_init shared semaphores even work now (confirmed by sthen).
correct the einval checks to not deref a pointer before the null check.
in sem_open, if we created the semaphore, we need to initialize the spinlock.

Revision 1.12 / (download) - annotate - [select for diffs], Wed Nov 20 03:16:39 2013 UTC (10 years, 6 months ago) by tedu
Branch: MAIN
Changes since 1.11: +4 -1 lines
Diff to previous 1.11 (colored)

oops, forgot about unnamed shared sems

Revision 1.11 / (download) - annotate - [select for diffs], Wed Nov 20 03:04:29 2013 UTC (10 years, 6 months ago) by tedu
Branch: MAIN
Changes since 1.10: +14 -23 lines
Diff to previous 1.10 (colored)

zhuk and i have slightly different styles. unify and consistify

Revision 1.10 / (download) - annotate - [select for diffs], Mon Nov 18 23:10:48 2013 UTC (10 years, 6 months ago) by tedu
Branch: MAIN
Changes since 1.9: +168 -22 lines
Diff to previous 1.9 (colored)

interprocess semaphores ala sem_open. mostly following in the pattern
of shm_open. with some additions and fixes from zhuk.

Revision 1.9 / (download) - annotate - [select for diffs], Sat Jun 1 23:06:26 2013 UTC (11 years ago) by tedu
Branch: MAIN
CVS Tags: OPENBSD_5_4_BASE, OPENBSD_5_4
Changes since 1.8: +4 -3 lines
Diff to previous 1.8 (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.8 / (download) - annotate - [select for diffs], Sat Jun 1 20:47:40 2013 UTC (11 years ago) by tedu
Branch: MAIN
Changes since 1.7: +4 -4 lines
Diff to previous 1.7 (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.7 / (download) - annotate - [select for diffs], Sat Mar 3 11:09:19 2012 UTC (12 years, 3 months ago) by guenther
Branch: MAIN
CVS Tags: OPENBSD_5_3_BASE, OPENBSD_5_3, OPENBSD_5_2_BASE, OPENBSD_5_2
Changes since 1.6: +2 -2 lines
Diff to previous 1.6 (colored)

sem_timedwait() should return ETIMEDOUT instead of EWOULDBLOCK on timeout

Revision 1.6 / (download) - annotate - [select for diffs], Sat Mar 3 10:02:26 2012 UTC (12 years, 3 months ago) by guenther
Branch: MAIN
Changes since 1.5: +48 -14 lines
Diff to previous 1.5 (colored)

Add sem_timewait() and fix sem_wait()'s handling of signals, so
that it resumes waiting unless the thread was canceled.  As part
of this, change the internal _sem_wait() function to return zero
on success and an errno value on failure instead of 1 on success
and zero on failure.

Revision 1.5 / (download) - annotate - [select for diffs], Fri Mar 2 08:07:43 2012 UTC (12 years, 3 months ago) by guenther
Branch: MAIN
Changes since 1.4: +2 -1 lines
Diff to previous 1.4 (colored)

_SPINLOCK_UNLOCKED isn't zero everywhere (*cough*hppa*cough*), so
sem_init() can't assume that calloc will leave the embedded spinlock
in the unlocked state

ok miod@ otto@

Revision 1.4 / (download) - annotate - [select for diffs], Tue Jan 17 02:34:18 2012 UTC (12 years, 4 months ago) by guenther
Branch: MAIN
CVS Tags: OPENBSD_5_1_BASE, OPENBSD_5_1
Changes since 1.3: +30 -67 lines
Diff to previous 1.3 (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.3 / (download) - annotate - [select for diffs], Wed Jan 4 21:01:25 2012 UTC (12 years, 5 months ago) by guenther
Branch: MAIN
Changes since 1.2: +1 -1 lines
Diff to previous 1.2 (colored)

Fix $OpenBSD tag

Revision 1.2 / (download) - annotate - [select for diffs], Wed Jan 4 17:59:28 2012 UTC (12 years, 5 months ago) by mpi
Branch: MAIN
Changes since 1.1: +56 -4 lines
Diff to previous 1.1 (colored)

Add some sanity checks, set errno accordingly to POSIX and add the named
semaphore stubs already provided by libpthread. We may move them in their
own file in the future when we figure out a real implementation.

Discussed with and looks ok to guenther@

Revision 1.1 / (download) - annotate - [select for diffs], Wed Jan 4 17:43:34 2012 UTC (12 years, 5 months ago) by mpi
Branch: MAIN

Split out the semaphore functions.

ok guenther@

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.