Skip to content

Commit e374ae9

Browse files
committed
JSON output: use std::atomic<bool> to ensure memory synchronization between threads.
1 parent 956b25f commit e374ae9

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/plugins/output/json/src/File.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#ifndef JSON_FILE_H
4343
#define JSON_FILE_H
4444

45+
#include <atomic>
4546
#include <string>
4647
#include <ctime>
4748
#include <cstdio>
@@ -72,7 +73,7 @@ class File : public Output {
7273
ipx_ctx_t *ctx; /**< Plugin instance context */
7374
pthread_t thread; /**< Thread */
7475
pthread_rwlock_t rwlock; /**< Data rwlock */
75-
bool stop; /**< Stop flag for termination */
76+
std::atomic<bool> stop; /**< Stop flag for termination */
7677

7778
unsigned int window_size; /**< Size of a time window */
7879
time_t window_time; /**< Current time window */

src/plugins/output/json/src/Server.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#ifndef JSON_SERVER_H
4141
#define JSON_SERVER_H
4242

43+
#include <atomic>
4344
#include <string>
4445
#include <vector>
4546
#include <pthread.h>
@@ -78,10 +79,10 @@ class Server : public Output
7879
ipx_ctx_t *ctx; /**< Instance context (for log only ) */
7980
pthread_t thread; /**< Thread */
8081
pthread_mutex_t mutex; /**< Mutex for the array */
81-
bool stop; /**< Stop flag for terminating */
82+
std::atomic<bool> stop; /**< Stop flag for terminating */
8283

8384
int socket_fd; /**< Server socket */
84-
bool new_clients_ready; /**< New clients flag */
85+
std::atomic<bool> new_clients_ready; /**< New clients flag */
8586
std::vector<client_t> new_clients; /**< Array of new clients */
8687
} acceptor_t;
8788

0 commit comments

Comments
 (0)