summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/H5Fint.c19
-rw-r--r--src/H5Fpkg.h1
2 files changed, 16 insertions, 4 deletions
diff --git a/src/H5Fint.c b/src/H5Fint.c
index 46508fe..a29d20b 100644
--- a/src/H5Fint.c
+++ b/src/H5Fint.c
@@ -1872,6 +1872,9 @@ H5F_open(const char *name, unsigned flags, hid_t fcpl_id, hid_t fapl_id)
set_flag = TRUE;
} /* end else */
+ /* Set the file locking flag */
+ file->use_file_locking = use_file_locking;
+
/* Check to see if both SWMR and cache image are requested. Fail if so */
if(H5C_cache_image_status(file, &ci_load, &ci_write) < 0)
HGOTO_ERROR(H5E_FILE, H5E_CANTGET, NULL, "can't get MDC cache image status")
@@ -3571,6 +3574,7 @@ H5F__start_swmr_write(H5F_t *f)
size_t u; /* Local index variable */
hbool_t setup = FALSE; /* Boolean flag to indicate whether SWMR setting is enabled */
H5VL_t *vol_connector = NULL; /* VOL connector for the file */
+ hbool_t use_file_locking = TRUE;/* Using file locks? */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE
@@ -3695,6 +3699,12 @@ H5F__start_swmr_write(H5F_t *f)
setup = TRUE;
+ /* Place an advisory lock on the file */
+ if(f->use_file_locking)
+ if(H5FD_lock(f->shared->lf, TRUE) < 0) {
+ HGOTO_ERROR(H5E_FILE, H5E_CANTLOCKFILE, FAIL, "unable to lock the file")
+ }
+
/* Mark superblock as dirty */
if(H5F_super_dirty(f) < 0)
HGOTO_ERROR(H5E_FILE, H5E_CANTMARKDIRTY, FAIL, "unable to mark superblock as dirty")
@@ -3712,10 +3722,6 @@ H5F__start_swmr_write(H5F_t *f)
if(H5O_refresh_metadata_reopen(obj_ids[u], &obj_glocs[u], vol_connector, TRUE) < 0)
HGOTO_ERROR(H5E_ATOM, H5E_CLOSEERROR, FAIL, "can't refresh-close object")
- /* Unlock the file */
- if(H5FD_unlock(f->shared->lf) < 0)
- HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, FAIL, "unable to unlock the file")
-
done:
if(ret_value < 0 && setup) {
@@ -3744,6 +3750,11 @@ done:
HDONE_ERROR(H5E_FILE, H5E_CANTFLUSH, FAIL, "unable to flush superblock")
} /* end if */
+ /* Unlock the file */
+ if(f->use_file_locking)
+ if(H5FD_unlock(f->shared->lf) < 0)
+ HDONE_ERROR(H5E_FILE, H5E_CANTUNLOCKFILE, FAIL, "unable to unlock the file")
+
/* Free memory */
if(obj_ids)
H5MM_xfree(obj_ids);
diff --git a/src/H5Fpkg.h b/src/H5Fpkg.h
index ff44536..294687c 100644
--- a/src/H5Fpkg.h
+++ b/src/H5Fpkg.h
@@ -382,6 +382,7 @@ struct H5F_t {
hbool_t closing; /* File is in the process of being closed */
struct H5F_t *parent; /* Parent file that this file is mounted to */
unsigned nmounts; /* Number of children mounted to this file */
+ hbool_t use_file_locking; /* Whether or not to use file locking */
};