summaryrefslogtreecommitdiff
path: root/otherlibs
diff options
context:
space:
mode:
authorGabriel Scherer <gabriel.scherer@gmail.com>2023-04-26 23:04:46 +0200
committerGitHub <noreply@github.com>2023-04-26 23:04:46 +0200
commit9fd4767208663033b7695c3b507239c6197bdded (patch)
tree5ee8ce78f99cf003e1c17a85ecfd3d7707ff4450 /otherlibs
parent69472048a0d1782d2b773561588339136a8cf5b6 (diff)
parent2788503869eae32cbddfbc9952dd7b512a4816cb (diff)
downloadocaml-9fd4767208663033b7695c3b507239c6197bdded.tar.gz
Merge pull request #12192 from gadmm/simpl_atomic
Simplification with atomic_ helpers
Diffstat (limited to 'otherlibs')
-rw-r--r--otherlibs/runtime_events/runtime_events_consumer.c10
-rw-r--r--otherlibs/systhreads/st_pthreads.h10
-rw-r--r--otherlibs/systhreads/st_stubs.c4
-rw-r--r--otherlibs/unix/symlink_win32.c7
-rw-r--r--otherlibs/unix/unixsupport_unix.c5
-rw-r--r--otherlibs/unix/unixsupport_win32.c5
6 files changed, 22 insertions, 19 deletions
diff --git a/otherlibs/runtime_events/runtime_events_consumer.c b/otherlibs/runtime_events/runtime_events_consumer.c
index 0901a3d931..1e5f229fd1 100644
--- a/otherlibs/runtime_events/runtime_events_consumer.c
+++ b/otherlibs/runtime_events/runtime_events_consumer.c
@@ -23,6 +23,7 @@
#include "caml/misc.h"
#include "caml/mlvalues.h"
#include "caml/osdeps.h"
+#include "caml/platform.h"
#include <fcntl.h>
#include <stdatomic.h>
@@ -391,10 +392,8 @@ caml_runtime_events_read_poll(struct caml_runtime_events_cursor *cursor,
do {
uint64_t buf[RUNTIME_EVENTS_MAX_MSG_LENGTH];
uint64_t ring_mask, header, msg_length;
- ring_head = atomic_load_explicit(&runtime_events_buffer_header->ring_head,
- memory_order_acquire);
- ring_tail = atomic_load_explicit(&runtime_events_buffer_header->ring_tail,
- memory_order_acquire);
+ ring_head = atomic_load_acquire(&runtime_events_buffer_header->ring_head);
+ ring_tail = atomic_load_acquire(&runtime_events_buffer_header->ring_tail);
if (ring_head > cursor->current_positions[domain_num]) {
if (cursor->lost_events) {
@@ -427,8 +426,7 @@ caml_runtime_events_read_poll(struct caml_runtime_events_cursor *cursor,
atomic_thread_fence(memory_order_seq_cst);
- ring_head = atomic_load_explicit(&runtime_events_buffer_header->ring_head,
- memory_order_acquire);
+ ring_head = atomic_load_acquire(&runtime_events_buffer_header->ring_head);
/* Check the message we've read hasn't been overwritten by the writer */
if (ring_head > cursor->current_positions[domain_num]) {
diff --git a/otherlibs/systhreads/st_pthreads.h b/otherlibs/systhreads/st_pthreads.h
index 5d29df67d1..bd8839b6de 100644
--- a/otherlibs/systhreads/st_pthreads.h
+++ b/otherlibs/systhreads/st_pthreads.h
@@ -37,7 +37,7 @@ static atomic_uintnat tick_thread_stop[Max_domains];
static int st_initialize(void)
{
- atomic_store_rel(&Tick_thread_stop, 0);
+ atomic_store_release(&Tick_thread_stop, 0);
return 0;
}
@@ -112,14 +112,14 @@ static void st_masterlock_init(st_masterlock * m)
m->init = 1;
}
m->busy = 1;
- atomic_store_rel(&m->waiters, 0);
+ atomic_store_release(&m->waiters, 0);
return;
};
static uintnat st_masterlock_waiters(st_masterlock * m)
{
- return atomic_load_acq(&m->waiters);
+ return atomic_load_acquire(&m->waiters);
}
static void st_bt_lock_acquire(st_masterlock *m) {
@@ -295,10 +295,10 @@ static void * caml_thread_tick(void * arg)
caml_init_domain_self(*domain_id);
caml_domain_state *domain = Caml_state;
- while(! atomic_load_acq(&Tick_thread_stop)) {
+ while(! atomic_load_acquire(&Tick_thread_stop)) {
st_msleep(Thread_timeout);
- atomic_store_rel(&domain->requested_external_interrupt, 1);
+ atomic_store_release(&domain->requested_external_interrupt, 1);
caml_interrupt_self();
}
return NULL;
diff --git a/otherlibs/systhreads/st_stubs.c b/otherlibs/systhreads/st_stubs.c
index 389a343b2d..09d56120a7 100644
--- a/otherlibs/systhreads/st_stubs.c
+++ b/otherlibs/systhreads/st_stubs.c
@@ -488,9 +488,9 @@ CAMLprim value caml_thread_initialize(value unit)
CAMLprim value caml_thread_cleanup(value unit)
{
if (Tick_thread_running){
- atomic_store_rel(&Tick_thread_stop, 1);
+ atomic_store_release(&Tick_thread_stop, 1);
st_thread_join(Tick_thread_id);
- atomic_store_rel(&Tick_thread_stop, 0);
+ atomic_store_release(&Tick_thread_stop, 0);
Tick_thread_running = 0;
}
diff --git a/otherlibs/unix/symlink_win32.c b/otherlibs/unix/symlink_win32.c
index 3a1d6a1b8b..aac6545b31 100644
--- a/otherlibs/unix/symlink_win32.c
+++ b/otherlibs/unix/symlink_win32.c
@@ -26,6 +26,7 @@
#include <caml/fail.h>
#include <caml/signals.h>
#include <caml/osdeps.h>
+#include <caml/platform.h>
#include "unixsupport.h"
#ifndef SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE
@@ -78,13 +79,11 @@ CAMLprim value caml_unix_symlink(value to_dir, value osource, value odest)
caml_unix_check_path(osource, "symlink");
caml_unix_check_path(odest, "symlink");
- additional_flags = atomic_load_explicit(&additional_symlink_flags,
- memory_order_relaxed);
+ additional_flags = atomic_load_relaxed(&additional_symlink_flags);
if (additional_flags == -1) {
additional_flags = IsDeveloperModeEnabled() ?
SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE : 0;
- atomic_store_explicit(&additional_symlink_flags, additional_flags,
- memory_order_relaxed);
+ atomic_store_relaxed(&additional_symlink_flags, additional_flags);
}
flags =
diff --git a/otherlibs/unix/unixsupport_unix.c b/otherlibs/unix/unixsupport_unix.c
index 4a206072a0..449af8b5c2 100644
--- a/otherlibs/unix/unixsupport_unix.c
+++ b/otherlibs/unix/unixsupport_unix.c
@@ -13,11 +13,14 @@
/* */
/**************************************************************************/
+#define CAML_INTERNALS
+
#include <caml/mlvalues.h>
#include <caml/alloc.h>
#include <caml/callback.h>
#include <caml/memory.h>
#include <caml/fail.h>
+#include <caml/platform.h>
#include "unixsupport.h"
#include "cst2constr.h"
#include <errno.h>
@@ -293,7 +296,7 @@ void caml_unix_error(int errcode, const char *cmdname, value cmdarg)
value res;
const value * exn;
- exn = atomic_load_explicit(&caml_unix_error_exn, memory_order_acquire);
+ exn = atomic_load_acquire(&caml_unix_error_exn);
if (exn == NULL) {
exn = caml_named_value("Unix.Unix_error");
if (exn == NULL)
diff --git a/otherlibs/unix/unixsupport_win32.c b/otherlibs/unix/unixsupport_win32.c
index f9e85a4586..cb5eb35df7 100644
--- a/otherlibs/unix/unixsupport_win32.c
+++ b/otherlibs/unix/unixsupport_win32.c
@@ -13,6 +13,8 @@
/* */
/**************************************************************************/
+#define CAML_INTERNALS
+
#include <stddef.h>
#include <caml/mlvalues.h>
#include <caml/callback.h>
@@ -20,6 +22,7 @@
#include <caml/memory.h>
#include <caml/fail.h>
#include <caml/custom.h>
+#include <caml/platform.h>
#include "unixsupport.h"
#include "cst2constr.h"
#include <errno.h>
@@ -297,7 +300,7 @@ void caml_unix_error(int errcode, const char *cmdname, value cmdarg)
value res;
const value * exn;
- exn = atomic_load_explicit(&caml_unix_error_exn, memory_order_acquire);
+ exn = atomic_load_acquire(&caml_unix_error_exn);
if (exn == NULL) {
exn = caml_named_value("Unix.Unix_error");
if (exn == NULL)