summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Kelly <ctk21@cl.cam.ac.uk>2021-04-08 08:46:00 +0100
committerGitHub <noreply@github.com>2021-04-08 08:46:00 +0100
commit4e839485934cbe16a5e8541d05ccfbe1237d2839 (patch)
tree65ceb2899317e4e723a8b77c31a0e34de5988f63
parentdb322bc15a61cc8750223574c0e8386466002865 (diff)
parent8b3aa01180398a1506417051aeb6941cd09e28b3 (diff)
downloadocaml-4e839485934cbe16a5e8541d05ccfbe1237d2839.tar.gz
Merge pull request ocaml-multicore/ocaml-multicore#523 from Sudha247/mutex-error
Systhreads Mutex raises `Sys_error`
-rw-r--r--otherlibs/systhreads/st_posix.h15
-rw-r--r--otherlibs/systhreads/st_stubs.c14
-rw-r--r--testsuite/disabled4
3 files changed, 17 insertions, 16 deletions
diff --git a/otherlibs/systhreads/st_posix.h b/otherlibs/systhreads/st_posix.h
index a2f876ac44..daf1aad055 100644
--- a/otherlibs/systhreads/st_posix.h
+++ b/otherlibs/systhreads/st_posix.h
@@ -265,23 +265,22 @@ static int st_mutex_destroy(st_mutex m)
return 0;
}
-static INLINE void st_mutex_lock(st_mutex m)
+static INLINE int st_mutex_lock(st_mutex m)
{
- return caml_plat_lock(m);
+ return pthread_mutex_lock(m);
}
-#define MUTEX_PREVIOUSLY_UNLOCKED 1
-#define MUTEX_ALREADY_LOCKED 0
+#define MUTEX_PREVIOUSLY_UNLOCKED 0
+#define MUTEX_ALREADY_LOCKED EBUSY
static INLINE int st_mutex_trylock(st_mutex m)
{
- int retcode = caml_plat_try_lock(m);
- return retcode;
+ return pthread_mutex_trylock(m);
}
-static INLINE void st_mutex_unlock(st_mutex m)
+static INLINE int st_mutex_unlock(st_mutex m)
{
- return caml_plat_unlock(m);
+ return pthread_mutex_unlock(m);
}
/* Condition variables */
diff --git a/otherlibs/systhreads/st_stubs.c b/otherlibs/systhreads/st_stubs.c
index 7c7c9119b2..db7a8e42df 100644
--- a/otherlibs/systhreads/st_stubs.c
+++ b/otherlibs/systhreads/st_stubs.c
@@ -649,32 +649,38 @@ CAMLprim value caml_mutex_new(value unit) /* ML */
CAMLprim value caml_mutex_lock(value wrapper) /* ML */
{
+ st_retcode retcode;
st_mutex mut = Mutex_val(wrapper);
/* PR#4351: first try to acquire mutex without releasing the master lock */
- if (caml_plat_try_lock(mut) == MUTEX_PREVIOUSLY_UNLOCKED) return Val_unit;
+ if (st_mutex_trylock(mut) == MUTEX_PREVIOUSLY_UNLOCKED) return Val_unit;
/* If unsuccessful, block on mutex */
Begin_root(wrapper)
caml_enter_blocking_section();
- st_mutex_lock(mut);
+ retcode = st_mutex_lock(mut);
caml_leave_blocking_section();
End_roots();
+ st_check_error(retcode, "Mutex.lock");
return Val_unit;
}
CAMLprim value caml_mutex_unlock(value wrapper) /* ML */
{
+ st_retcode retcode;
st_mutex mut = Mutex_val(wrapper);
/* PR#4351: no need to release and reacquire master lock */
- st_mutex_unlock(mut);
+ retcode = st_mutex_unlock(mut);
+ st_check_error(retcode, "Mutex.unlock");
return Val_unit;
}
CAMLprim value caml_mutex_try_lock(value wrapper) /* ML */
{
st_mutex mut = Mutex_val(wrapper);
- int retcode = st_mutex_trylock(mut);
+ st_retcode retcode;
+ retcode = st_mutex_trylock(mut);
if (retcode == MUTEX_ALREADY_LOCKED) return Val_false;
+ st_check_error(retcode, "Mutex.try_lock");
return Val_true;
}
diff --git a/testsuite/disabled b/testsuite/disabled
index d79597f5f3..4e82a8f61b 100644
--- a/testsuite/disabled
+++ b/testsuite/disabled
@@ -61,10 +61,6 @@ tests/lib-unix/kill/'unix_kill.ml' with 1.2 (native)
tests/lib-threads/'beat.ml' with 1.2 (native)
tests/lib-threads/'beat.ml' with 1.1 (bytecode)
-# TODO: need to implement this error behaviour https://github.com/ocaml/ocaml/pull/9846
-tests/lib-threads/'mutex_errors.ml' with 1.1 (bytecode)
-tests/lib-threads/'mutex_errors.ml' with 1.2 (native)
-
# TODO: pr9971 broken in our systhread implmentation with debug build (#9971/#9973)
tests/lib-threads/'pr9971.ml' with 1.1 (bytecode)
tests/lib-threads/'pr9971.ml' with 1.2 (native)