Skip to content

Commit 40243cf

Browse files
committed
fbtl/posix: use a macro to initialize atomicity lock
thank you Raafat Feki to making this suggestion during the code review, it makes the code much nicer! Signed-off-by: Edgar Gabriel <egabriel@central.uh.edu>
1 parent cb638c2 commit 40243cf

File tree

5 files changed

+22
-71
lines changed

5 files changed

+22
-71
lines changed

ompi/mca/fbtl/posix/fbtl_posix.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,22 @@ typedef struct mca_fbtl_posix_request_data_t mca_fbtl_posix_request_data_t;
9595
#define FBTL_POSIX_READ 1
9696
#define FBTL_POSIX_WRITE 2
9797

98+
#define OMPIO_SET_ATOMICITY_LOCK(_fh, _lock, _lock_counter, _op) { \
99+
int32_t _orig_flags = _fh->f_flags; \
100+
_fh->f_flags &= ~OMPIO_LOCK_NEVER; \
101+
_fh->f_flags &= ~OMPIO_LOCK_NOT_THIS_OP; \
102+
off_t _end_offset = (off_t)_fh->f_io_array[_fh->f_num_of_io_entries-1].offset + \
103+
(off_t)_fh->f_io_array[_fh->f_num_of_io_entries-1].length; \
104+
off_t _len = _end_offset - (off_t)_fh->f_io_array[0].offset; \
105+
int _ret = mca_fbtl_posix_lock ( &_lock, _fh, _op, (off_t)_fh->f_io_array[0].offset, \
106+
_len, OMPIO_LOCK_ENTIRE_REGION, &_lock_counter); \
107+
if ( _ret == -1 ) { \
108+
opal_output(1, "mca_fbtl_posix: error in mca_fbtl_posix_lock():%s", \
109+
strerror(errno)); \
110+
return OMPI_ERROR; \
111+
} \
112+
_fh->f_flags = _orig_flags; }
113+
98114

99115
/*
100116
* ******************************************************************

ompi/mca/fbtl/posix/fbtl_posix_ipreadv.c

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -74,23 +74,7 @@ ssize_t mca_fbtl_posix_ipreadv (ompio_file_t *fh,
7474
data->aio_fh = fh;
7575

7676
if ( fh->f_atomicity ) {
77-
// save flags and disable file system specific requirements
78-
int32_t orig_flags = fh->f_flags;
79-
fh->f_flags &= ~OMPIO_LOCK_NEVER;
80-
fh->f_flags &= ~OMPIO_LOCK_NOT_THIS_OP;
81-
82-
// Set a lock on the entire region that is being modified
83-
off_t end_offset = (off_t)fh->f_io_array[fh->f_num_of_io_entries-1].offset +
84-
(off_t)fh->f_io_array[fh->f_num_of_io_entries-1].length;
85-
off_t len = end_offset - (off_t)fh->f_io_array[0].offset;
86-
ret = mca_fbtl_posix_lock ( &data->aio_lock, fh, F_RDLCK, (off_t)fh->f_io_array[0].offset,
87-
len, OMPIO_LOCK_ENTIRE_REGION, &data->aio_lock_counter);
88-
if ( ret == -1 ) {
89-
opal_output(1, "mca_fbtl_posix_ipreadv: error in mca_fbtl_posix_lock():%s", strerror(errno));
90-
return OMPI_ERROR;
91-
}
92-
93-
fh->f_flags = orig_flags;
77+
OMPIO_SET_ATOMICITY_LOCK(fh, data->aio_lock, data->aio_lock_counter, F_RDLCK);
9478
}
9579

9680
for ( i=0; i<fh->f_num_of_io_entries; i++ ) {

ompi/mca/fbtl/posix/fbtl_posix_ipwritev.c

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -72,22 +72,7 @@ ssize_t mca_fbtl_posix_ipwritev (ompio_file_t *fh,
7272
data->aio_lock_counter = 0;
7373
data->aio_fh = fh;
7474
if ( fh->f_atomicity ) {
75-
// save flags and disable file system specific requirements
76-
int32_t orig_flags = fh->f_flags;
77-
fh->f_flags &= ~OMPIO_LOCK_NEVER;
78-
fh->f_flags &= ~OMPIO_LOCK_NOT_THIS_OP;
79-
80-
// Set a lock on the entire region that is being modified
81-
off_t end_offset = (off_t)fh->f_io_array[fh->f_num_of_io_entries-1].offset +
82-
(off_t)fh->f_io_array[fh->f_num_of_io_entries-1].length;
83-
off_t len = end_offset - (off_t)fh->f_io_array[0].offset;
84-
ret = mca_fbtl_posix_lock ( &data->aio_lock, fh, F_WRLCK, (off_t)fh->f_io_array[0].offset,
85-
len, OMPIO_LOCK_ENTIRE_REGION, &data->aio_lock_counter);
86-
if ( ret == -1 ) {
87-
opal_output(1, "mca_fbtl_posix_ipwritev: error in mca_fbtl_posix_lock():%s", strerror(errno));
88-
return OMPI_ERROR;
89-
}
90-
fh->f_flags = orig_flags;
75+
OMPIO_SET_ATOMICITY_LOCK(fh, data->aio_lock, data->aio_lock_counter, F_WRLCK);
9176
}
9277

9378

ompi/mca/fbtl/posix/fbtl_posix_preadv.c

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,30 +39,14 @@ ssize_t mca_fbtl_posix_preadv (ompio_file_t *fh )
3939
{
4040
ssize_t bytes_read=0;
4141
struct flock lock;
42-
int ret, lock_counter=0;
43-
int32_t orig_flags;
42+
int lock_counter=0;
4443

4544
if (NULL == fh->f_io_array) {
4645
return OMPI_ERROR;
4746
}
4847

4948
if ( fh->f_atomicity ) {
50-
// save flags and disable file system specific requirements
51-
orig_flags = fh->f_flags;
52-
fh->f_flags &= ~OMPIO_LOCK_NEVER;
53-
fh->f_flags &= ~OMPIO_LOCK_NOT_THIS_OP;
54-
55-
// Set a lock on the entire region that is being modified
56-
off_t end_offset = (off_t)fh->f_io_array[fh->f_num_of_io_entries-1].offset +
57-
(off_t)fh->f_io_array[fh->f_num_of_io_entries-1].length;
58-
off_t len = end_offset - (off_t)fh->f_io_array[0].offset;
59-
ret = mca_fbtl_posix_lock ( &lock, fh, F_RDLCK, (off_t)fh->f_io_array[0].offset,
60-
len, OMPIO_LOCK_ENTIRE_REGION, &lock_counter);
61-
if ( ret == -1 ) {
62-
opal_output(1, "mca_fbtl_posix_preadv: error in mca_fbtl_posix_lock():%s", strerror(errno));
63-
return OMPI_ERROR;
64-
}
65-
fh->f_flags = orig_flags;
49+
OMPIO_SET_ATOMICITY_LOCK(fh, lock, lock_counter, F_RDLCK);
6650
}
6751

6852
if ( fh->f_num_of_io_entries > 1 ) {

ompi/mca/fbtl/posix/fbtl_posix_pwritev.c

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,32 +40,14 @@ ssize_t mca_fbtl_posix_pwritev(ompio_file_t *fh )
4040
{
4141
ssize_t bytes_written=0;
4242
struct flock lock;
43-
int lock_counter=0, ret;
44-
int32_t orig_flags;
43+
int lock_counter=0;
4544

4645
if (NULL == fh->f_io_array) {
4746
return OMPI_ERROR;
4847
}
4948

5049
if ( fh->f_atomicity ) {
51-
// save flags and disable file system specific requirements
52-
orig_flags = fh->f_flags;
53-
fh->f_flags &= ~OMPIO_LOCK_NEVER;
54-
fh->f_flags &= ~OMPIO_LOCK_NOT_THIS_OP;
55-
56-
// Set a lock on the entire region that is being modified
57-
off_t end_offset = (off_t)fh->f_io_array[fh->f_num_of_io_entries-1].offset +
58-
(off_t)fh->f_io_array[fh->f_num_of_io_entries-1].length;
59-
off_t len = end_offset - (off_t)fh->f_io_array[0].offset;
60-
ret = mca_fbtl_posix_lock ( &lock, fh, F_WRLCK, (off_t)fh->f_io_array[0].offset,
61-
len, OMPIO_LOCK_ENTIRE_REGION, &lock_counter);
62-
if ( 0 < ret ) {
63-
opal_output(1, "mca_fbtl_posix_pwritev: error in mca_fbtl_posix_lock() ret=%d: %s",
64-
ret, strerror(errno));
65-
mca_fbtl_posix_unlock ( &lock, fh, &lock_counter);
66-
return OMPI_ERROR;
67-
}
68-
fh->f_flags = orig_flags;
50+
OMPIO_SET_ATOMICITY_LOCK(fh, lock, lock_counter, F_WRLCK);
6951
}
7052

7153
if ( fh->f_num_of_io_entries > 1 ) {

0 commit comments

Comments
 (0)