aboutsummaryrefslogtreecommitdiff
path: root/storeio/storeio.c
diff options
context:
space:
mode:
authorMarcus Brinkmann <marcus@gnu.org>2001-04-19 22:11:52 +0000
committerMarcus Brinkmann <marcus@gnu.org>2001-04-19 22:11:52 +0000
commit82781dd6da2b6a1eb113e20d100052509bb85a90 (patch)
tree748f7044ed4fe884d8d3b350e75906e29e01aa41 /storeio/storeio.c
parent83e61d2d234ac403a6e6e91c12b1d87aca64de10 (diff)
downloadhurd-82781dd6da2b6a1eb113e20d100052509bb85a90.tar.gz
hurd-82781dd6da2b6a1eb113e20d100052509bb85a90.tar.bz2
hurd-82781dd6da2b6a1eb113e20d100052509bb85a90.zip
2001-02-18 Marcus Brinkmann <marcus@gnu.org>
* dev.h (struct dev): New member nperopens. * storeio.c (open_hook): Hold device lock and check if this is the first open. If yes, activate the store. (close_hook): Hold global_lock and check if this was the last open. If yes, inactivate the store. * dev.c (dev_open): Open the store with STORE_INACTIVE (in store_parsed_open as well as in store_create).
Diffstat (limited to 'storeio/storeio.c')
-rw-r--r--storeio/storeio.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/storeio/storeio.c b/storeio/storeio.c
index 5b82a6c8..87bc249c 100644
--- a/storeio/storeio.c
+++ b/storeio/storeio.c
@@ -233,18 +233,34 @@ check_open_hook (struct trivfs_control *trivfs_control,
static error_t
open_hook (struct trivfs_peropen *peropen)
{
+ error_t err = 0;
struct dev *const dev = peropen->cntl->hook;
+
if (dev->store)
- return open_create (dev, (struct open **)&peropen->hook);
- else
- return 0;
+ {
+ mutex_lock (&dev->lock);
+ if (dev->nperopens++ == 0)
+ err = store_clear_flags (dev->store, STORE_INACTIVE);
+ mutex_unlock (&dev->lock);
+ if (!err)
+ err = open_create (dev, (struct open **)&peropen->hook);
+ }
+ return err;
}
static void
close_hook (struct trivfs_peropen *peropen)
{
+ struct dev *const dev = peropen->cntl->hook;
+
if (peropen->hook)
- open_free (peropen->hook);
+ {
+ mutex_lock (&dev->lock);
+ if (--dev->nperopens == 0)
+ store_set_flags (dev->store, STORE_INACTIVE);
+ mutex_unlock (&dev->lock);
+ open_free (peropen->hook);
+ }
}
/* ---------------------------------------------------------------- */