diff options
author | jhb <jhb@FreeBSD.org> | 2014-10-24 20:02:44 +0000 |
---|---|---|
committer | jhb <jhb@FreeBSD.org> | 2014-10-24 20:02:44 +0000 |
commit | 5dd26e948ded0a684546918d8402bc5beced28fb (patch) | |
tree | ff024ddfa290c34065e439d40ebeac2d43870f71 /include | |
parent | fcc57fff950cce92dd04cdfabbc48e25ca438027 (diff) | |
download | FreeBSD-src-5dd26e948ded0a684546918d8402bc5beced28fb.zip FreeBSD-src-5dd26e948ded0a684546918d8402bc5beced28fb.tar.gz |
The current POSIX semaphore implementation stores the _has_waiters flag
in a separate word from the _count. This does not permit both items to
be updated atomically in a portable manner. As a result, sem_post()
must always perform a system call to safely clear _has_waiters.
This change removes the _has_waiters field and instead uses the high bit
of _count as the _has_waiters flag. A new umtx object type (_usem2) and
two new umtx operations are added (SEM_WAIT2 and SEM_WAKE2) to implement
these semantics. The older operations are still supported under the
COMPAT_FREEBSD9/10 options. The POSIX semaphore API in libc has
been updated to use the new implementation. Note that the new
implementation is not compatible with the previous implementation.
However, this only affects static binaries (which cannot be helped by
symbol versioning). Binaries using a dynamic libc will continue to work
fine. SEM_MAGIC has been bumped so that mismatched binaries will error
rather than corrupting a shared semaphore. In addition, a padding field
has been added to sem_t so that it remains the same size.
Differential Revision: https://reviews.freebsd.org/D961
Reported by: adrian
Reviewed by: kib, jilles (earlier version)
Sponsored by: Norse
Diffstat (limited to 'include')
-rw-r--r-- | include/semaphore.h | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/include/semaphore.h b/include/semaphore.h index 3531353..218de99 100644 --- a/include/semaphore.h +++ b/include/semaphore.h @@ -38,7 +38,8 @@ struct _sem { __uint32_t _magic; - struct _usem _kern; + struct _usem2 _kern; + __uint32_t _padding; /* Preserve structure size */ }; typedef struct _sem sem_t; |