aboutsummaryrefslogtreecommitdiff
path: root/libfshelp/lock-acquire.c
diff options
context:
space:
mode:
Diffstat (limited to 'libfshelp/lock-acquire.c')
-rw-r--r--libfshelp/lock-acquire.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/libfshelp/lock-acquire.c b/libfshelp/lock-acquire.c
index 9c81634a..bad1114d 100644
--- a/libfshelp/lock-acquire.c
+++ b/libfshelp/lock-acquire.c
@@ -42,9 +42,11 @@ fshelp_acquire_lock (struct lock_box *box, int *user, struct mutex *mut,
if (flags & LOCK_UN)
{
if (*user & LOCK_UN)
- return EBADF;
+ return 0;
+
assert (*user == box->type);
assert (*user == LOCK_SH || *user == LOCK_EX);
+
if (*user == LOCK_SH)
{
if (!--box->shcount)
@@ -80,7 +82,8 @@ fshelp_acquire_lock (struct lock_box *box, int *user, struct mutex *mut,
if (flags & LOCK_NB)
return EWOULDBLOCK;
box->waiting = 1;
- condition_wait (&box->wait, mut);
+ if (hurd_condition_wait (&box->wait, mut))
+ return EINTR;
}
/* If we have a shared lock, release it. */
@@ -108,15 +111,16 @@ fshelp_acquire_lock (struct lock_box *box, int *user, struct mutex *mut,
}
else if (flags & LOCK_EX)
{
- /* Wait for any shared locks to finish. */
- while (box->type == LOCK_SH)
+ /* Wait for any shared (and exclusive) locks to finish. */
+ while (box->type != LOCK_UN)
{
if (flags & LOCK_NB)
return EWOULDBLOCK;
else
{
box->waiting = 1;
- condition_wait (&box->wait, mut);
+ if (hurd_condition_wait (&box->wait, mut))
+ return EINTR;
}
}
box->type = LOCK_EX;