ref: fcc5e75d07e5bc6cb3ddac6d9a437e7ec62d0d95
parent: 49ac0b93d3a4652e0bda07d7654c9ffb7c3fb004
author: cinap_lenrek <[email protected]>
date: Mon Jul 30 18:45:49 EDT 2012
tsemacquire: manpage and syscallfmt
--- 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 @@
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 @@
.B RFMEM
flag
(see
-.IR fork (2)),
+.IR fork (2)),
.IR segattach (2),
or
.IR thread (2).
@@ -32,8 +36,6 @@
.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
@@ -40,13 +42,24 @@
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 @@
.PP
Like
.IR rendezvous (2),
-.I semacquire
+.IR semacquire ,
+.IR tsemacquire ,
and
.I semrelease
are not typically used directly.
@@ -86,8 +100,9 @@
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
--- a/sys/src/9/port/syscallfmt.c
+++ b/sys/src/9/port/syscallfmt.c
@@ -231,6 +231,11 @@
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);