Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e13d378

Browse files
committed
sink: fix ->processed data race on 64-bit platforms
1 parent 6a9fdb9 commit e13d378

5 files changed

Lines changed: 22 additions & 11 deletions

File tree

libvips/iofuncs/sink.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,12 @@ sink_area_allocate_fn(VipsThreadState *state, void *a, gboolean *stop)
237237

238238
/* Add the number of pixels we've just allocated to progress.
239239
*/
240+
#if GLIB_SIZEOF_VOID_P >= 8
241+
g_atomic_pointer_add(&sink_base->processed,
242+
(guint64) state->pos.width * state->pos.height);
243+
#else
240244
sink_base->processed += (guint64) state->pos.width * state->pos.height;
245+
#endif
241246

242247
return 0;
243248
}
@@ -428,13 +433,19 @@ int
428433
vips_sink_base_progress(void *a)
429434
{
430435
SinkBase *sink_base = (SinkBase *) a;
436+
guint64 processed =
437+
#if GLIB_SIZEOF_VOID_P >= 8
438+
g_atomic_pointer_get(&sink_base->processed);
439+
#else
440+
sink_base->processed;
441+
#endif
431442

432443
VIPS_DEBUG_MSG("vips_sink_base_progress:\n");
433444

434445
/* Trigger any eval callbacks on our source image and
435446
* check for errors.
436447
*/
437-
vips_image_eval(sink_base->im, sink_base->processed);
448+
vips_image_eval(sink_base->im, processed);
438449
if (vips_image_iskilled(sink_base->im))
439450
return -1;
440451

libvips/iofuncs/sinkdisc.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,12 @@ wbuffer_allocate_fn(VipsThreadState *state, void *a, gboolean *stop)
417417

418418
/* Add the number of pixels we've just allocated to progress.
419419
*/
420+
#if GLIB_SIZEOF_VOID_P >= 8
421+
g_atomic_pointer_add(&sink_base->processed,
422+
(guint64) state->pos.width * state->pos.height);
423+
#else
420424
sink_base->processed += (guint64) state->pos.width * state->pos.height;
425+
#endif
421426

422427
return 0;
423428
}

libvips/iofuncs/sinkmemory.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,12 @@ sink_memory_area_allocate_fn(VipsThreadState *state, void *a, gboolean *stop)
242242

243243
/* Add the number of pixels we've just allocated to progress.
244244
*/
245+
#if GLIB_SIZEOF_VOID_P >= 8
246+
g_atomic_pointer_add(&sink_base->processed,
247+
(guint64) state->pos.width * state->pos.height);
248+
#else
245249
sink_base->processed += (guint64) state->pos.width * state->pos.height;
250+
#endif
246251

247252
return 0;
248253
}

suppressions/tsan.supp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ race_top:vips_progress_update
1111
# Unsynchronized TRUE assignment to wbuffer->kill
1212
race_top:wbuffer_free
1313

14-
# Unsynchronized read of sink_base->processed
15-
race_top:vips_sink_base_progress
16-
1714
# Unsynchronized read of write->buf->write_errno
1815
race_top:write_check_error
1916

suppressions/valgrind.supp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -544,13 +544,6 @@
544544
fun:clone
545545
}
546546

547-
# unlocked read of pixels-processed-so-far, which is fine
548-
{
549-
helgrind4
550-
Helgrind:Race
551-
fun:vips_sink_base_progress
552-
}
553-
554547
# helgrind can't see g_private
555548
{
556549
helgrind5

0 commit comments

Comments
 (0)