summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjdp <jdp@FreeBSD.org>2004-06-14 18:19:05 +0000
committerjdp <jdp@FreeBSD.org>2004-06-14 18:19:05 +0000
commit32b926e0fbaacbc2b3175a2d2b1c791fbeefa99c (patch)
treef18a0b115d49023a3e78c267aa48ca58dc6304d5
parentf2c0db1521299639d6b16b7d477a777fbd81ada6 (diff)
downloadFreeBSD-src-32b926e0fbaacbc2b3175a2d2b1c791fbeefa99c.zip
FreeBSD-src-32b926e0fbaacbc2b3175a2d2b1c791fbeefa99c.tar.gz
Change the return value of sema_timedwait() so it returns 0 on
success and a proper errno value on failure. This makes it consistent with cv_timedwait(), and paves the way for the introduction of functions such as sema_timedwait_sig() which can fail in multiple ways. Bump __FreeBSD_version and add a note to UPDATING. Approved by: scottl (ips driver), arch
-rw-r--r--UPDATING6
-rw-r--r--share/man/man9/sema.921
-rw-r--r--sys/dev/ips/ips_commands.c6
-rw-r--r--sys/kern/kern_sema.c12
-rw-r--r--sys/sys/param.h2
5 files changed, 32 insertions, 15 deletions
diff --git a/UPDATING b/UPDATING
index e5a8042..592d429 100644
--- a/UPDATING
+++ b/UPDATING
@@ -17,6 +17,12 @@ NOTE TO PEOPLE WHO THINK THAT FreeBSD 5.x IS SLOW:
developers choose to disable these features on build machines
to maximize performance.
+20040614:
+ The return value of sema_timedwait(9) has been changed to
+ make it consistent with cv_timedwait(9). Be sure to recompile
+ the ips module and any third-party modules which call
+ sema_timedwait.
+
20040613:
ALTQ is now linked to the build. This breaks ABI for struct ifnet.
Make sure to recompile modules and any userland that makes use of
diff --git a/share/man/man9/sema.9 b/share/man/man9/sema.9
index 9ba5890..e8f2cb9 100644
--- a/share/man/man9/sema.9
+++ b/share/man/man9/sema.9
@@ -98,13 +98,26 @@ argument to
.Fn sema_timedwait
specifies the minimum time in ticks to wait before returning with failure.
.Fn sema_value
+is used to read the current value of the semaphore.
+.Sh RETURN VALUES
+.Fn sema_value
returns the current value of the semaphore.
.Pp
-.Fn sema_timedwait
-and
+If decrementing the semaphore would result in its value being negative,
.Fn sema_trywait
-will return 0 if waiting on the semaphore failed; otherwise a non-zero value
-will be returned to indicate success.
+returns 0 to indicate failure.
+Otherwise, a non-zero value is returned to indicate success.
+.Pp
+.Fn sema_timedwait
+returns 0 if waiting on the semaphore succeeded; otherwise a
+non-zero error code is returned.
+.Sh ERRORS
+.Fn sema_timedwait
+will fail if:
+.Bl -tag -width Er
+.It Bq Er EWOULDBLOCK
+Timeout expired.
+.El
.Sh SEE ALSO
.Xr condvar 9 ,
.Xr mtx_pool 9 ,
diff --git a/sys/dev/ips/ips_commands.c b/sys/dev/ips/ips_commands.c
index d9bc5b7..e2495ab 100644
--- a/sys/dev/ips/ips_commands.c
+++ b/sys/dev/ips/ips_commands.c
@@ -248,7 +248,7 @@ static int ips_send_adapter_info_cmd(ips_command_t *command)
ips_adapter_info_callback, command, BUS_DMA_NOWAIT);
if ((status->value == IPS_ERROR_STATUS) ||
- (sema_timedwait(&command->cmd_sema, 30*hz) == 0))
+ (sema_timedwait(&command->cmd_sema, 30*hz) != 0))
error = ETIMEDOUT;
if (error == 0) {
@@ -352,7 +352,7 @@ static int ips_send_drive_info_cmd(ips_command_t *command)
command->data_buffer,IPS_DRIVE_INFO_LEN,
ips_drive_info_callback, command, BUS_DMA_NOWAIT);
if ((status->value == IPS_ERROR_STATUS) ||
- (sema_timedwait(&command->cmd_sema, 10*hz) == 0))
+ (sema_timedwait(&command->cmd_sema, 10*hz) != 0))
error = ETIMEDOUT;
if (error == 0) {
@@ -606,7 +606,7 @@ static int ips_read_nvram(ips_command_t *command){
command->data_buffer,IPS_NVRAM_PAGE_SIZE,
ips_read_nvram_callback, command, BUS_DMA_NOWAIT);
if ((status->value == IPS_ERROR_STATUS) ||
- (sema_timedwait(&command->cmd_sema, 30*hz) == 0))
+ (sema_timedwait(&command->cmd_sema, 30*hz) != 0))
error = ETIMEDOUT;
if (error == 0) {
diff --git a/sys/kern/kern_sema.c b/sys/kern/kern_sema.c
index 0ee350a..f29aa88 100644
--- a/sys/kern/kern_sema.c
+++ b/sys/kern/kern_sema.c
@@ -108,7 +108,7 @@ _sema_wait(struct sema *sema, const char *file, int line)
int
_sema_timedwait(struct sema *sema, int timo, const char *file, int line)
{
- int ret, timed_out;
+ int error;
mtx_lock(&sema->sema_mtx);
@@ -118,27 +118,25 @@ _sema_timedwait(struct sema *sema, int timo, const char *file, int line)
* continuously, since the timeout period is merely a lower bound on how
* long to wait.
*/
- for (timed_out = 0; sema->sema_value == 0 && timed_out == 0;) {
+ for (error = 0; sema->sema_value == 0 && error == 0;) {
sema->sema_waiters++;
- timed_out = cv_timedwait(&sema->sema_cv, &sema->sema_mtx, timo);
+ error = cv_timedwait(&sema->sema_cv, &sema->sema_mtx, timo);
sema->sema_waiters--;
}
if (sema->sema_value > 0) {
/* Success. */
sema->sema_value--;
- ret = 1;
+ error = 0;
CTR6(KTR_LOCK, "%s(%p) \"%s\" v = %d at %s:%d", __func__, sema,
cv_wmesg(&sema->sema_cv), sema->sema_value, file, line);
} else {
- ret = 0;
-
CTR5(KTR_LOCK, "%s(%p) \"%s\" fail at %s:%d", __func__, sema,
cv_wmesg(&sema->sema_cv), file, line);
}
mtx_unlock(&sema->sema_mtx);
- return (ret);
+ return (error);
}
int
diff --git a/sys/sys/param.h b/sys/sys/param.h
index 4324e64..ad72535 100644
--- a/sys/sys/param.h
+++ b/sys/sys/param.h
@@ -55,7 +55,7 @@
* scheme is: <major><two digit minor><0 if release branch, otherwise 1>xx
*/
#undef __FreeBSD_version
-#define __FreeBSD_version 502114 /* Master, propagated to newvers */
+#define __FreeBSD_version 502115 /* Master, propagated to newvers */
#ifndef LOCORE
#include <sys/types.h>
OpenPOWER on IntegriCloud