From 069efdcf4037b7fa25586648bf733777cb6a453b Mon Sep 17 00:00:00 2001 From: malc Date: Wed, 13 Jul 2016 02:58:42 +0300 Subject: [PATCH] Give ml_postprocess a chance to succeed Admittedly this is fugly, but no clean solution immediately springs to mind. (Register continuation that will be called upon unlock and will notify caml code to retry? Use cloned contexts? Something else?) All other trylocks are just as ugly, but probably much less noticeable. --- link.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/link.c b/link.c index 71eb2e3..3236e54 100644 --- a/link.c +++ b/link.c @@ -319,6 +319,22 @@ static int trylock (const char *cap) return ret == EBUSY; } +static int oneseclock (const char *cap) +{ + int ret; + struct timespec tp; + + if (clock_gettime (CLOCK_REALTIME, &tp)) { + err (1, "%s: clock_gettime: %s", cap, strerror (errno)); + } + tp.tv_sec += 1; + ret = pthread_mutex_timedlock (&mutex, &tp); + if (ret && ret != EBUSY) { + errx (1, "%s: pthread_mutex_timedlock: %s", cap, strerror (ret)); + } + return ret == EBUSY; +} + static void *parse_pointer (const char *cap, const char *s) { int ret; @@ -2632,7 +2648,7 @@ CAMLprim value ml_postprocess (value ptr_v, value hlinks_v, goto done; } - if (trylock (__func__)) { + if (oneseclock (__func__)) { noff = 0; goto done; } -- 2.11.4.GIT