From b3820aaf8cce61d5d6fe9e20a0dd1ab0260e93f7 Mon Sep 17 00:00:00 2001 From: malc Date: Sun, 29 Jan 2012 05:59:02 +0400 Subject: [PATCH] Avoid deadlocks --- link.c | 12 ++++++++++-- main.ml | 7 ++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/link.c b/link.c index fe06e4a..12093a0 100644 --- a/link.c +++ b/link.c @@ -1427,10 +1427,18 @@ mainloop (void *unused) CAMLprim value ml_realloctexts (value texcount_v) { CAMLparam1 (texcount_v); - lock ("ml_realloctexts"); + int ok; + + if (trylock ("ml_realloctexts")) { + ok = 0; + goto done; + } realloctexts (Int_val (texcount_v)); + ok = 1; unlock ("ml_realloctexts"); - CAMLreturn (Val_unit); + + done: + CAMLreturn (Val_bool (ok)); } static void showsel (struct page *page, int ox, int oy) diff --git a/main.ml b/main.ml index 7addb34..b55014d 100644 --- a/main.ml +++ b/main.ml @@ -54,7 +54,7 @@ external postprocess : opaque -> bool -> int -> int -> unit = "ml_postprocess";; external pagebbox : opaque -> (int * int * int * int) = "ml_getpagebox";; external platform : unit -> platform = "ml_platform";; external setaalevel : int -> unit = "ml_setaalevel";; -external realloctexts : int -> unit = "ml_realloctexts";; +external realloctexts : int -> bool = "ml_realloctexts";; let platform_to_string = function | Punknown -> "unknown" @@ -3522,8 +3522,9 @@ let enterinfomode = src#int "texture count" (fun () -> conf.texcount) (fun v -> - conf.texcount <- v; - realloctexts conf.texcount; + if realloctexts v + then conf.texcount <- v + else showtext '!' " Failed to set texture count please retry later" ); src#int "slice height" (fun () -> conf.sliceheight) -- 2.11.4.GIT