summaryrefslogtreecommitdiffstats
path: root/sys/sys/_semaphore.h
diff options
context:
space:
mode:
authordavidxu <davidxu@FreeBSD.org>2010-01-05 02:37:59 +0000
committerdavidxu <davidxu@FreeBSD.org>2010-01-05 02:37:59 +0000
commit87c8a1faf252e6bbed958df4fbcbfae972bf04d9 (patch)
treec7f16cd6fa7d769efff569dabd92c58350947dcf /sys/sys/_semaphore.h
parent6c3ad0385cac32227b87922ca96729062247ec89 (diff)
downloadFreeBSD-src-87c8a1faf252e6bbed958df4fbcbfae972bf04d9.zip
FreeBSD-src-87c8a1faf252e6bbed958df4fbcbfae972bf04d9.tar.gz
Use umtx to implement process sharable semaphore, to make this work,
now type sema_t is a structure which can be put in a shared memory area, and multiple processes can operate it concurrently. User can either use mmap(MAP_SHARED) + sem_init(pshared=1) or use sem_open() to initialize a shared semaphore. Named semaphore uses file system and is located in /tmp directory, and its file name is prefixed with 'SEMD', so now it is chroot or jail friendly. In simplist cases, both for named and un-named semaphore, userland code does not have to enter kernel to reduce/increase semaphore's count. The semaphore is designed to be crash-safe, it means even if an application is crashed in the middle of operating semaphore, the semaphore state is still safely recovered by later use, there is no waiter counter maintained by userland code. The main semaphore code is in libc and libthr only has some necessary stubs, this makes it possible that a non-threaded application can use semaphore without linking to thread library. Old semaphore implementation is kept libc to maintain binary compatibility. The kernel ksem API is no longer used in the new implemenation. Discussed on: threads@
Diffstat (limited to 'sys/sys/_semaphore.h')
-rw-r--r--sys/sys/_semaphore.h21
1 files changed, 2 insertions, 19 deletions
diff --git a/sys/sys/_semaphore.h b/sys/sys/_semaphore.h
index df3c5da..5266d04 100644
--- a/sys/sys/_semaphore.h
+++ b/sys/sys/_semaphore.h
@@ -31,26 +31,9 @@
typedef intptr_t semid_t;
struct timespec;
-#ifndef _KERNEL
-
-#include <sys/cdefs.h>
+#define SEM_VALUE_MAX __INT_MAX
-/*
- * Semaphore definitions.
- */
-struct sem {
-#define SEM_MAGIC ((u_int32_t) 0x09fa4012)
- u_int32_t magic;
- pthread_mutex_t lock;
- pthread_cond_t gtzero;
- u_int32_t count;
- u_int32_t nwaiters;
-#define SEM_USER (NULL)
- semid_t semid; /* semaphore id if kernel (shared) semaphore */
- int syssem; /* 1 if kernel (shared) semaphore */
- LIST_ENTRY(sem) entry;
- struct sem **backpointer;
-};
+#ifndef _KERNEL
__BEGIN_DECLS
OpenPOWER on IntegriCloud