~ubuntu-branches/ubuntu/precise/ocaml-batteries/precise

« back to all changes in this revision

Viewing changes to src/core/extlib_threads/rMutex.mli

  • Committer: Bazaar Package Importer
  • Author(s): Stefano Zacchiroli
  • Date: 2010-03-06 16:03:38 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100306160338-spvwiv3uc4jr28hw
Tags: 1.1.0-1
* New upstream release
  - major changes, "diet" version of the library
  - fix old FTBFS error, due to major code changes (Closes: #569455)
* Revamp packaging
  - adapt to new stuff shipped by upstream
  - switch from CDBS to dh
  - adapt dependencies (generally: reduce them)
* debian/patches/
  - remove old debian/patches/{debian-specific-installation-paths,
    debian-specific-info-on-doc-availability} as obsolete
  - new patch 0001-install-fix-for-bytecode-only-build: avoid
    installing *.a files with bytecode only compilation
* debian/libbatteries-ocaml-dev.links: remove file, shortend
  /usr/bin/ocaml-batteries to the top-level no longer exists
* remove debian/README.Debian (previous content is now obsolete)
* bump Standards-Version to 3.8.4 (no changes needed)
* debian/watch: update to match new upstream version convention
* debian/libbatteries-ocaml-{dev,doc}.{docs,examples}: ship only doc
  file from the root dir, other stuff is currently out of date
  (Closes: #514265)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
(*
2
 
 * RMutex - Reentrant mutexes
3
 
 * Copyright (C) 1996 Xavier Leroy
4
 
 *               1996 Damien Doligez
5
 
 *               2008 David Teller
6
 
 * 
7
 
 * This library is free software; you can redistribute it and/or
8
 
 * modify it under the terms of the GNU Lesser General Public
9
 
 * License as published by the Free Software Foundation; either
10
 
 * version 2.1 of the License, or (at your option) any later version,
11
 
 * with the special exception on linking described in file LICENSE.
12
 
 *
13
 
 * This library is distributed in the hope that it will be useful,
14
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
 
 * Lesser General Public License for more details.
17
 
 *
18
 
 * You should have received a copy of the GNU Lesser General Public
19
 
 * License along with this library; if not, write to the Free Software
20
 
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21
 
 *)
22
 
 
23
 
 
24
 
(** Locks for mutual exclusion.
25
 
 
26
 
    Mutexes (mutual-exclusion locks) are used to implement critical sections
27
 
    and protect shared mutable data structures against concurrent accesses.
28
 
    The typical use is (if [m] is the mutex associated with the data structure
29
 
    [D]):
30
 
    {[
31
 
     RMutex.synchronize ~lock:m (fun () ->
32
 
        (* Critical section that operates over D *);
33
 
     ) ()
34
 
    ]}
35
 
 
36
 
    This module implements reentrant mutexes, i.e. a version of mutexes which
37
 
    may be locked again by their owner thread without blocking this thread.
38
 
    Reentrant mutexes are typically slower than regular mutexes but also safer.
39
 
 
40
 
    @documents RMutex
41
 
 
42
 
    @author Xavier Leroy (Base module)
43
 
    @author Damien Doligez (Base module)
44
 
    @author David Teller
45
 
*)
46
 
 
47
 
type t
48
 
(** The type of mutexes. *)
49
 
 
50
 
val create : unit -> t
51
 
(** Return a new mutex. *)
52
 
 
53
 
val lock : t -> unit
54
 
  (** Lock the given mutex. Only one thread can have the mutex locked
55
 
      at any time. A thread that attempts to lock a mutex already locked
56
 
      will suspend until the other mutex is unlocked.
57
 
 
58
 
      {b Note} attempting to lock a mutex you already have locked from
59
 
      the same thread will not suspend your thread.
60
 
*)
61
 
 
62
 
val try_lock : t -> bool
63
 
(** Same as {!RMutex.lock}, but does not suspend the calling thread if
64
 
    the mutex is already locked: just return [false] immediately
65
 
    in that case. If the mutex is unlocked, lock it and
66
 
    return [true]. *)
67
 
 
68
 
val unlock : t -> unit
69
 
(** Unlock the given mutex. Other threads suspended trying to lock
70
 
    the mutex will restart. If the mutex wasn't locked, nothing happens.*)
71
 
 
72
 
val synchronize : ?lock:t -> ('a -> 'b) -> 'a -> 'b
73
 
(** Protect a function.
74
 
 
75
 
    [synchronize f] returns a new function [f'] with the same behavior
76
 
    as [f] but such that concurrenty calls to [f'] are queued if
77
 
    necessary to avoid races.
78
 
 
79
 
    [synchronize ~lock:l f] behaves as [synchronize f] but uses a
80
 
    user-specified lock [l], which may be useful to share a lock
81
 
    between several function.
82
 
 
83
 
    In either case, the lock is acquired when entering the function
84
 
    and released when the function call ends, whether this is due
85
 
    to normal termination or to some exception being raised.
86
 
*)
87
 
 
88
 
 
89
 
val make : unit -> Extlib.Concurrent.lock
90
 
(**
91
 
   Create a new abstract lock based on Reentrant Mutexes.
92
 
*)