From: Adam Michalski Date: Mon, 25 Jul 2022 14:50:48 +0000 (+0200) Subject: Add `volatile` specifier for the mapped memory area pointer to give X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c1ce626859d650a9274f4e9df56aad30edfdfb03;p=platform%2Fcore%2Fsystem%2Fdbus-tools.git Add `volatile` specifier for the mapped memory area pointer to give a hint to the compiler that it cannot optimize any checks to it Without this hint the compiler tends to optimize the synchronization barrier as it thinks that if a variable is unchanged in the parent process, it can optimize access to it and not perform the check each time during the `while` loop which leads to deadlock (endless waiting). Change-Id: I0a316b4e0d1546bc6864737c20c86601635fff2a --- diff --git a/benchmark/gdbus.c b/benchmark/gdbus.c index b9a02f7..5c281ef 100644 --- a/benchmark/gdbus.c +++ b/benchmark/gdbus.c @@ -256,7 +256,7 @@ void Measure_bandwidth(void) int returnp[nprocs/2][2]; int pids[nprocs]; int ready_fd; - char *ready_ptr; + volatile char *ready_ptr; ready_fd = shm_open("isready", O_CREAT | O_TRUNC | O_RDWR, 0666); if(ready_fd == -1) @@ -359,7 +359,7 @@ void Measure_bandwidth(void) waitpid(pids[child], NULL, 0); } - ret = munmap(ready_ptr, sizeof(bool)); + ret = munmap((void*)ready_ptr, sizeof(bool)); if (ret != 0) { perror("munmap"); exit(1); diff --git a/benchmark/libdbus.c b/benchmark/libdbus.c index 84f1df7..2efa631 100644 --- a/benchmark/libdbus.c +++ b/benchmark/libdbus.c @@ -213,7 +213,7 @@ void Measure_bandwidth(void) int returnp[nprocs/2][2]; int pids[nprocs]; int ready_fd; - char *ready_ptr; + volatile char *ready_ptr; ready_fd = shm_open("isready", O_CREAT | O_TRUNC | O_RDWR, 0666); if(ready_fd == -1) @@ -318,7 +318,7 @@ void Measure_bandwidth(void) waitpid(pids[child], NULL, 0); } - ret = munmap(ready_ptr, sizeof(bool)); + ret = munmap((void*)ready_ptr, sizeof(bool)); if (ret != 0) { perror("munmap"); exit(1); diff --git a/benchmark/pipe.c b/benchmark/pipe.c index f0b3907..1d46d8f 100644 --- a/benchmark/pipe.c +++ b/benchmark/pipe.c @@ -137,7 +137,7 @@ void Measure_bandwidth(void) int p[nprocs/2][2]; int pids[nprocs]; int ready_fd; - char *ready_ptr; + volatile char *ready_ptr; ready_fd = shm_open("isready", O_CREAT | O_TRUNC | O_RDWR, 0666); if(ready_fd == -1) @@ -251,7 +251,7 @@ void Measure_bandwidth(void) waitpid(pids[child], NULL, 0); } - ret = munmap(ready_ptr, sizeof(bool)); + ret = munmap((void*)ready_ptr, sizeof(bool)); if (ret != 0) { perror("munmap"); exit(1); diff --git a/benchmark/socket.c b/benchmark/socket.c index 01d24d3..2d3ed7a 100644 --- a/benchmark/socket.c +++ b/benchmark/socket.c @@ -137,7 +137,7 @@ void Measure_bandwidth(void) int fd[nprocs/2][2]; int pids[nprocs]; int ready_fd; - char *ready_ptr; + volatile char *ready_ptr; ready_fd = shm_open("isready", O_CREAT | O_TRUNC | O_RDWR, 0666); if(ready_fd == -1) @@ -251,7 +251,7 @@ void Measure_bandwidth(void) waitpid(pids[child], NULL, 0); } - ret = munmap(ready_ptr, sizeof(bool)); + ret = munmap((void*)ready_ptr, sizeof(bool)); if (ret != 0) { perror("munmap"); exit(1);