summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sys/man/2/semacquire35
-rw-r--r--sys/src/9/port/syscallfmt.c5
2 files changed, 30 insertions, 10 deletions
diff --git a/sys/man/2/semacquire b/sys/man/2/semacquire
index 386734800..0eb0fc97b 100644
--- a/sys/man/2/semacquire
+++ b/sys/man/2/semacquire
@@ -1,6 +1,6 @@
.TH SEMACQUIRE 2
.SH NAME
-semacquire, semrelease \- user level semaphores
+semacquire, tsemacquire, semrelease - user level semaphores
.SH SYNOPSIS
.B #include <u.h>
.br
@@ -10,10 +10,14 @@ semacquire, semrelease \- user level semaphores
int semacquire(long *addr, int block);
.PP
.B
+int tsemacquire(long *addr, ulong ms);
+.PP
+.B
long semrelease(long *addr, long count);
.SH DESCRIPTION
-.I Semacquire
-and
+.IR Semacquire ,
+.IR tsemacquire ,
+and
.I semrelease
facilitate scheduling between processes sharing memory.
Processes arrange to share memory by using
@@ -22,7 +26,7 @@ with the
.B RFMEM
flag
(see
-.IR fork (2)),
+.IR fork (2)),
.IR segattach (2),
or
.IR thread (2).
@@ -32,21 +36,30 @@ The semaphore's value is the integer pointed at by
.I Semacquire
atomically waits until the semaphore has a positive value
and then decrements that value.
-It returns 1 if the semaphore was acquired and \-1 on error
-(e.g., if it was interrupted).
If
.I block
is zero
and the semaphore is not immediately available,
.I semacquire
returns 0 instead of waiting.
+.I Tsemacquire
+only waits
+.I ms
+milliseconds for the semaphore to attain a positive value
+and, if available in that time, decrements that value.
+It returns 0 otherwise.
+Both functions return 1 if the semaphore was acquired
+and -1 on error
+(e.g., if they were interrupted).
.I Semrelease
-adds
+adds
.I count
to the semaphore's value
and returns the new value.
.PP
.I Semacquire
+(and analogously for
+.IR tsemacquire )
and
.I semrelease
can be thought of as efficient, correct replacements for:
@@ -74,7 +87,8 @@ semrelease(long *addr, int count)
.PP
Like
.IR rendezvous (2),
-.I semacquire
+.IR semacquire ,
+.IR tsemacquire ,
and
.I semrelease
are not typically used directly.
@@ -86,8 +100,9 @@ locks, rendezvous points, and channels
and
.IR thread (2)).
Also like
-.I rendezvous ,
-.I semacquire
+.IR rendezvous ,
+.IR semacquire ,
+.IR tsemacquire ,
and
.I semrelease
cannot be used to coordinate between threads
diff --git a/sys/src/9/port/syscallfmt.c b/sys/src/9/port/syscallfmt.c
index c04cc5cf8..fdd2e0519 100644
--- a/sys/src/9/port/syscallfmt.c
+++ b/sys/src/9/port/syscallfmt.c
@@ -231,6 +231,11 @@ syscallfmt(int syscallno, ulong pc, va_list list)
i[0] = va_arg(list, int);
fmtprint(&fmt, "%#p %d", v, i[0]);
break;
+ case TSEMACQUIRE:
+ v = va_arg(list, int*);
+ l = va_arg(list, ulong);
+ fmtprint(&fmt, "%#p %ld", v, l);
+ break;
case SEEK:
v = va_arg(list, vlong*);
i[0] = va_arg(list, int);