Changeset 7120

Show
Ignore:
Timestamp:
01/29/10 06:39:11 (6 weeks ago)
Author:
dbaelde
Message:

Introduce a Tutility for win32-compatible assertions on mutexes.

Location:
trunk/liquidsoap/src
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/liquidsoap/src/sources/playlist.ml

    r7111 r7120  
    109109    * Must be called within mylock critical section. *) 
    110110  method randomize_playlist = 
    111     (* This assertion does not work on 
    112      * win32 because a thread can double-lock 
    113      * the same mutex.. *) 
    114     if Sys.os_type <> "Win32" then 
    115       assert (not (Mutex.try_lock mylock)) ; 
     111    assert (Tutils.seems_locked mylock) ; 
    116112    Utils.randomize !playlist 
    117113 
     
    236232  method reload_playlist_internal new_playlist_uri = 
    237233     
    238     (* This assertion does not work on 
    239      * win32 because a thread can double-lock 
    240      * the same mutex.. *) 
    241     if Sys.os_type <> "Win32" then 
    242       assert (not (Mutex.try_lock reloading)) ; 
     234    assert (Tutils.seems_locked reloading) ; 
    243235 
    244236    self#load_playlist ?uri:new_playlist_uri true ; 
     
    256248  method reload_update round_done = 
    257249    (* Must be called by somebody who owns [mylock] *) 
    258     (* This assertion does not work on 
    259      * win32 because a thread can double-lock 
    260      * the same mutex.. *) 
    261     if Sys.os_type <> "Win32" then 
    262       assert (not (Mutex.try_lock mylock)) ; 
     250    assert (Tutils.seems_locked mylock) ; 
    263251    match reload with 
    264252      | Never -> () 
  • trunk/liquidsoap/src/sources/request_source.ml

    r7111 r7120  
    6969    * when there is no ready request. *) 
    7070  method private begin_track = 
    71     (* This assertion does not work on 
    72      * win32 because a thread can double-lock 
    73      * the same mutex.. *) 
    74     if Sys.os_type <> "Win32" then 
    75       assert (not (Mutex.try_lock plock)) ; 
     71    assert (Tutils.seems_locked plock) ; 
    7672    assert (current = None) ; 
    7773    match self#get_next_file with 
  • trunk/liquidsoap/src/tools/tutils.ml

    r6666 r7120  
    8181    with 
    8282      | e -> Mutex.unlock lock ; raise e 
     83 
     84let seems_locked = 
     85  if Sys.os_type = "Win32" then (fun _ -> true) else 
     86    fun m -> 
     87      if Mutex.try_lock m then begin 
     88        Mutex.unlock m ; 
     89        false 
     90      end else 
     91        true 
    8392 
    8493(** Manage a set of threads and make sure they terminate correctly, 
  • trunk/liquidsoap/src/tools/tutils.mli

    r6344 r7120  
    6363(** Make a function work in critical section, protected by a given lock. *) 
    6464val mutexify : Mutex.t -> ('a -> 'b) -> ('a -> 'b) 
     65 
     66(** Tests whether a mutex is locked, without blocking. 
     67  * We cannot check on Win32, where [true] is always returned: 
     68  * it always "seems" OK, we don't raise false alarms. 
     69  * This is meant to be used for assertions. *) 
     70val seems_locked : Mutex.t -> bool