summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>2001-08-24 03:35:30 +0000
committerRoland McGrath <roland@gnu.org>2001-08-24 03:35:30 +0000
commit35caef3bdd2dfebef63cbd4ba6f4dd5ddf7ab182 (patch)
treec9b48d537ae5762c9c12639c3f4619f8956a6885
parent624adb6445cfa505a5644546cff7a430003f4715 (diff)
2001-08-23 Roland McGrath <roland@frob.com>
* lockfile.c: Rewritten to use macros now defined by libc.
-rw-r--r--libthreads/lockfile.c51
1 files changed, 5 insertions, 46 deletions
diff --git a/libthreads/lockfile.c b/libthreads/lockfile.c
index c815185c..2fe9800b 100644
--- a/libthreads/lockfile.c
+++ b/libthreads/lockfile.c
@@ -1,5 +1,5 @@
-/* lockfile - Handle locking and unlocking of stream. Hurd cthreads version.
- Copyright (C) 2000 Free Software Foundation, Inc.
+/* lockfile - Handle locking and unlocking of streams. Hurd cthreads version.
+ Copyright (C) 2000,01 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -18,68 +18,27 @@
Boston, MA 02111-1307, USA. */
#include <cthreads.h> /* Must come before <stdio.h>! */
-
-#define _IO_MTSAFE_IO
#include <stdio.h>
-#include <assert.h>
-
#ifdef _STDIO_USES_IOSTREAM
void
_cthreads_flockfile (_IO_FILE *fp)
{
- cthread_t self = cthread_self ();
-
- if (fp->_lock->owner == self)
- {
- assert (fp->_lock->count != 0);
- ++fp->_lock->count;
- }
- else
- {
- mutex_lock (&fp->_lock->mutex);
- assert (fp->_lock->owner == 0);
- fp->_lock->owner = self;
- assert (fp->_lock->count == 0);
- fp->_lock->count = 1;
- }
+ _IO_lock_lock (*fp->_lock);
}
void
_cthreads_funlockfile (_IO_FILE *fp)
{
- if (--fp->_lock->count == 0)
- {
- assert (fp->_lock->owner == cthread_self ());
- fp->_lock->owner = 0;
- mutex_unlock (&fp->_lock->mutex);
- }
+ _IO_lock_unlock (*fp->_lock);
}
int
_cthreads_ftrylockfile (_IO_FILE *fp)
{
- cthread_t self = cthread_self ();
-
- if (fp->_lock->owner == self)
- {
- assert (fp->_lock->count != 0);
- ++fp->_lock->count;
- }
- else if (mutex_try_lock (&fp->_lock->mutex))
- {
- assert (fp->_lock->owner == 0);
- fp->_lock->owner = self;
- assert (fp->_lock->count == 0);
- fp->_lock->count = 1;
- }
- else
- return 0; /* No lock for us. */
-
- /* We got the lock. */
- return 1;
+ return __libc_lock_trylock_recursive (*fp->_lock);
}