Skip to content

Commit 581e0ae

Browse files
authored
Merge pull request #3220 from BsAtHome/fix-not_zero-volatile
Fix wrong use of volatile and pointless assignments.
2 parents a71b1d0 + 5fca884 commit 581e0ae

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

src/libnml/buffer/shmem.cc

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ extern "C" {
2828
#include <string.h> /* strchr(), memcpy(), memset() */
2929
#include <stdlib.h> /* strtod */
3030
#include <physmem.hh> /* PHYSMEM_HANDLE */
31+
#include <math.h>
3132

3233
#ifdef __cplusplus
3334
}
@@ -44,21 +45,10 @@ extern "C" {
4445
//#include "autokey.h"
4546
/* rw-rw-r-- permissions */
4647
#define MODE (0700)
47-
static double last_non_zero_x;
48-
static double last_x;
4948

50-
static int not_zero(volatile double x)
49+
static inline bool not_zero(double x)
5150
{
52-
last_x = x;
53-
if (x < -1E-6 && last_x < -1E-6) {
54-
last_non_zero_x = x;
55-
return 1;
56-
}
57-
if (x > 1E-6 && last_x > 1E-6) {
58-
last_non_zero_x = x;
59-
return 1;
60-
}
61-
return 0;
51+
return fabs(x) > 1e-6;
6252
}
6353

6454
/* SHMEM Member Functions. */
@@ -578,7 +568,7 @@ CMS_STATUS SHMEM::main_access(void *_local, int *serial_number)
578568

579569
case CMS_READ_ACCESS:
580570
if (NULL != bsem && status == CMS_READ_OLD &&
581-
(blocking_timeout > 1e-6 || blocking_timeout < -1E-6)) {
571+
not_zero(blocking_timeout)) {
582572
if (second_read > 10 && total_subdivisions <= 1) {
583573
status = CMS_MISC_ERROR;
584574
rcs_print_error

0 commit comments

Comments
 (0)