Skip to content

Commit 722f507

Browse files
author
David Berry
committed
Allow f77 apps to bypass internal HDS lock checks
This is because multi-threaded C apps that use F77 code (via a suitabel C wrapper) serialise the execution of the F77 code using a mutex (usually within the wrapper layer), and so HDS functions called within the F77 code (via a suitable wrapper) should not perform extra serialisation checks. The new datNolock function can be used to indicate that locking checks should not be performed on a specified object.
1 parent 9a4b4db commit 722f507

8 files changed

+128
-2
lines changed

Makefile.am

+1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ datValid.c \
108108
datVec.c \
109109
datLock.c \
110110
datLocked.c \
111+
datNolock.c \
111112
datUnlock.c \
112113
hdsCopy.c \
113114
hdsErase.c \

dat1.h

+2
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ typedef struct Handle {
155155
for any known child objects */
156156
int nchild; /* The length of the "children" array */
157157
char *name; /* Name (cleaned) of the HDF object within its parent */
158+
char docheck; /* If non-zero, check any lock is appropriate
159+
before using the locator */
158160
} Handle;
159161

160162
/* Private definition of the HDS locator struct */

dat1Handle.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ Handle *dat1Handle( const HDSLoc *parent_loc, const char *name, int rdonly,
217217
}
218218

219219
/* Initialise the Handle to indicate it is currently unlocked. */
220+
result->docheck = 1;
220221
result->nwrite_lock = 0;
221222
result->nread_lock = 0;
222223
result->read_lockers = NULL;
@@ -225,7 +226,7 @@ Handle *dat1Handle( const HDSLoc *parent_loc, const char *name, int rdonly,
225226
/* If a parent was supplied, see if the current thread has a read or
226227
write lock on the parent object. We give the same sort of lock to the
227228
new Handle below (ignoring the supplied value for "rdonly"). */
228-
if( parent ) {
229+
if( parent && parent->docheck ) {
229230
lock_status = dat1HandleLock( parent, 1, 0, 0, status );
230231
if( lock_status == 1 ) {
231232
rdonly = 0;

dat1ValidateLocator.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ int dat1ValidateLocator( const char *func, int checklock, const HDSLoc *loc,
113113
/* If required, check that the object is locked by the current thread for
114114
the appropriate type of access. Do not check any child objects as these
115115
will be checked if and when accessed. */
116-
if( checklock && *status == SAI__OK ) {
116+
if( checklock && loc->handle->docheck && *status == SAI__OK ) {
117117
lock_status = dat1HandleLock( loc->handle, 1, 0, 0, status );
118118

119119
/* Calling function will not make any change to the object. In this case

datNolock.c

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
*+
3+
* Name:
4+
* datNolock
5+
6+
* Purpose:
7+
* Indicate that an object should be used without checking its lock.
8+
9+
* Language:
10+
* Starlink ANSI C
11+
12+
* Type of Module:
13+
* Library routine
14+
15+
* Invocation:
16+
* datNolock( HDSLoc *locator, int *status );
17+
18+
* Arguments:
19+
* locator = HDSLoc * (Given)
20+
* Locator to the object that is to be modified.
21+
* status = int* (Given and Returned)
22+
* Pointer to global status.
23+
24+
* Description:
25+
* By default, every HDS function will check that the supplied locator
26+
* is locked for use by the current thread before using it, and issue
27+
* an error report if it is not suitably locked. In some cases however,
28+
* this check is not required and can cause problems. This function can
29+
* be used to supres the check when required. It stores a flag with the
30+
* given locator indicating that no such checks should be performed
31+
* before using the locator.
32+
*
33+
* For instance, objects created within Fortran code may require this
34+
* flag to be set.
35+
36+
* Authors:
37+
* DSB: David S Berry (DSB)
38+
* {enter_new_authors_here}
39+
40+
* History:
41+
* 9-OCT-2017 (DSB):
42+
* Initial version
43+
* {enter_further_changes_here}
44+
45+
* Copyright:
46+
* Copyright (C) 2017 East Asian Observatory.
47+
* All Rights Reserved.
48+
49+
* Licence:
50+
* Redistribution and use in source and binary forms, with or
51+
* without modification, are permitted provided that the following
52+
* conditions are met:
53+
*
54+
* - Redistributions of source code must retain the above copyright
55+
* notice, this list of conditions and the following disclaimer.
56+
*
57+
* - Redistributions in binary form must reproduce the above
58+
* copyright notice, this list of conditions and the following
59+
* disclaimer in the documentation and/or other materials
60+
* provided with the distribution.
61+
*
62+
* - Neither the name of the {organization} nor the names of its
63+
* contributors may be used to endorse or promote products
64+
* derived from this software without specific prior written
65+
* permission.
66+
*
67+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
68+
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
69+
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
70+
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
71+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
72+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
73+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
74+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
75+
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
76+
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
77+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
78+
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
79+
* THE POSSIBILITY OF SUCH DAMAGE.
80+
81+
* Bugs:
82+
* {note_any_bugs_here}
83+
*-
84+
*/
85+
86+
#include "sae_par.h"
87+
#include "dat1.h"
88+
#include "hds.h"
89+
90+
int datNolock( HDSLoc *locator, int *status ) {
91+
92+
/* Check inherited status. */
93+
if (*status != SAI__OK) return *status;
94+
95+
/* Validate input locator. */
96+
dat1ValidateLocator( "datNolock", 0, locator, 0, status );
97+
98+
/* Check we can de-reference "locator" safely. */
99+
if( *status == SAI__OK ) {
100+
101+
/* Set the flag. */
102+
locator->handle->docheck = 0;
103+
}
104+
105+
return *status;
106+
}
107+

hds.h

+7
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,13 @@ datType(const HDSLoc *locator, char type_str[DAT__SZTYP + 1], int *status);
960960
int
961961
datUnlock( HDSLoc *locator, int recurs, int *status);
962962

963+
/*=============================================================*/
964+
/* datNolock - Prevent lock checks being performed on an object. */
965+
/*=============================================================*/
966+
967+
int
968+
datNolock( HDSLoc *locator, int *status);
969+
963970

964971
/*=========================*/
965972
/* datUnmap - Unmap object */

hds_v5.h

+7
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,13 @@ datThere_v5(const HDSLoc *locator, const char *name_c, hdsbool_t *there, int *st
946946
int
947947
datType_v5(const HDSLoc *locator, char type_str[DAT__SZTYP + 1], int *status);
948948

949+
/*=============================================================*/
950+
/* datNolock - Prevent lock echks being performed on an object */
951+
/*=============================================================*/
952+
953+
int
954+
datNolock_v5( HDSLoc *locator, int *status);
955+
949956
/*=============================================================*/
950957
/* datUnlock - Unlock an object so another thread can lock it. */
951958
/*=============================================================*/

hds_v5_map.h

+1
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@
130130
#define datTemp datTemp_v5
131131
#define datThere datThere_v5
132132
#define datType datType_v5
133+
#define datNolock datNolock_v5
133134
#define datUnlock datUnlock_v5
134135
#define datUnmap datUnmap_v5
135136
#define datValid datValid_v5

0 commit comments

Comments
 (0)