Skip to content

Commit 1fb9cee

Browse files
committed
refactor: atomic add
Signed-off-by: composer <[email protected]>
1 parent eb2d7e7 commit 1fb9cee

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

plugins/out_doris/doris.c

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@
4646
#include <winnt.h>
4747
#endif
4848

49+
static inline void sync_fetch_and_add(size_t *dest, size_t value) {
50+
#ifdef FLB_SYSTEM_WINDOWS
51+
InterlockedAdd(dest, value);
52+
#else
53+
__sync_fetch_and_add(dest, value);
54+
#endif
55+
}
56+
4957
static int cb_doris_init(struct flb_output_instance *ins,
5058
struct flb_config *config, void *data)
5159
{
@@ -317,11 +325,7 @@ static void cb_doris_flush(struct flb_event_chunk *event_chunk,
317325

318326
if (ret != FLB_OK) {
319327
if (ret == FLB_ERROR && ctx->log_progress_interval > 0) {
320-
#ifdef FLB_SYSTEM_WINDOWS
321-
InterlockedAdd(&ctx->reporter->failed_rows, event_chunk->total_events);
322-
#else
323-
__sync_fetch_and_add(&ctx->reporter->failed_rows, event_chunk->total_events);
324-
#endif
328+
sync_fetch_and_add(&ctx->reporter->failed_rows, event_chunk->total_events);
325329
}
326330
FLB_OUTPUT_RETURN(ret);
327331
}
@@ -337,19 +341,10 @@ static void cb_doris_flush(struct flb_event_chunk *event_chunk,
337341
flb_sds_destroy(out_body);
338342

339343
if (ret == FLB_OK && ctx->log_progress_interval > 0) {
340-
#ifdef FLB_SYSTEM_WINDOWS
341-
InterlockedAdd(&ctx->reporter->total_bytes, out_size);
342-
InterlockedAdd(&ctx->reporter->total_rows, event_chunk->total_events);
343-
#else
344-
__sync_fetch_and_add(&ctx->reporter->total_bytes, out_size);
345-
__sync_fetch_and_add(&ctx->reporter->total_rows, event_chunk->total_events);
346-
#endif
344+
sync_fetch_and_add(&ctx->reporter->total_bytes, out_size);
345+
sync_fetch_and_add(&ctx->reporter->total_rows, event_chunk->total_events);
347346
} else if (ret == FLB_ERROR && ctx->log_progress_interval > 0) {
348-
#ifdef FLB_SYSTEM_WINDOWS
349-
InterlockedAdd(&ctx->reporter->failed_rows, event_chunk->total_events);
350-
#else
351-
__sync_fetch_and_add(&ctx->reporter->failed_rows, event_chunk->total_events);
352-
#endif
347+
sync_fetch_and_add(&ctx->reporter->failed_rows, event_chunk->total_events);
353348
}
354349
FLB_OUTPUT_RETURN(ret);
355350
}

0 commit comments

Comments
 (0)