Skip to content

Commit

Permalink
Use atomic operations for some index variables
Browse files Browse the repository at this point in the history
This makes the related functions thread safe, but calling them from
different processes will still cause problems because all processes
use the same filenames which are generated by using the index.

Signed-off-by: Stefan Weil <[email protected]>
  • Loading branch information
stweil committed Sep 1, 2023
1 parent d0fa51c commit b00337b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/compare.c
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ pixCompareGray(PIX *pix1,
PIX **ppixdiff)
{
char buf[64];
static l_int32 index = 0;
static l_atomic index = 0;
l_int32 d1, d2, same, first, last;
GPLOT *gplot;
NUMA *na, *nac;
Expand Down Expand Up @@ -1078,7 +1078,7 @@ pixCompareRGB(PIX *pix1,
PIX **ppixdiff)
{
char buf[64];
static l_int32 index = 0;
static l_atomic index = 0;
l_int32 rsame, gsame, bsame, same, first, rlast, glast, blast, last;
l_float32 rdiff, gdiff, bdiff;
GPLOT *gplot;
Expand Down
6 changes: 3 additions & 3 deletions src/gplot.c
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ gplotSimplePix1(NUMA *na,
const char *title)
{
char buf[64];
static l_int32 index;
static l_atomic index;
GPLOT *gplot;
PIX *pix;

Expand Down Expand Up @@ -803,7 +803,7 @@ gplotSimplePix2(NUMA *na1,
const char *title)
{
char buf[64];
static l_int32 index;
static l_atomic index;
GPLOT *gplot;
PIX *pix;

Expand Down Expand Up @@ -844,7 +844,7 @@ gplotSimplePixN(NUMAA *naa,
const char *title)
{
char buf[64];
static l_int32 index;
static l_atomic index;
GPLOT *gplot;
PIX *pix;

Expand Down
2 changes: 1 addition & 1 deletion src/regutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ struct L_RegParams
char *testname; /*!< name of test, without '_reg' */
char *tempfile; /*!< name of temp file for compare mode output */
l_int32 mode; /*!< generate, compare or display */
l_int32 index; /*!< index into saved files for this test; 0-based */
l_atomic index; /*!< index into saved files for this test; 0-based */
l_int32 success; /*!< overall result of the test */
l_int32 display; /*!< 1 if in display mode; 0 otherwise */
L_TIMER tstart; /*!< marks beginning of the reg test */
Expand Down
2 changes: 1 addition & 1 deletion src/writefile.c
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ pixDisplayWithTitle(PIX *pixs,
{
char *tempname;
char buffer[Bufsize];
static l_int32 index = 0; /* caution: not .so or thread safe */
static l_atomic index = 0; /* caution: not .so safe */
l_int32 w, h, d, spp, maxheight, opaque, threeviews;
l_float32 ratw, rath, ratmin;
PIX *pix0, *pix1, *pix2;
Expand Down

0 comments on commit b00337b

Please sign in to comment.