[m-rev.] diff: Add an impure_init/0 function to thread.mvar.m

Paul Bone paul at bone.id.au
Fri Oct 10 00:47:04 AEDT 2014


Branches: master

---

Add an impure_init/0 function to thread.mvar.m

This change renames the init/0 function in thread.mvar.m to impure_init/0;
deprecating the old function.  This makss this module more consistent with
thread.semaphore.m.

Remove the "mvar." prefix where it is unnecessary.

Add %----% separators between some definitions in the implementation
section.

library/thread.mvar.m:
    As above.
---
 library/thread.mvar.m | 52 ++++++++++++++++++++++++++++++++++++---------------
 1 file changed, 37 insertions(+), 15 deletions(-)

diff --git a/library/thread.mvar.m b/library/thread.mvar.m
index 93b99b5..ccbe9a5 100644
--- a/library/thread.mvar.m
+++ b/library/thread.mvar.m
@@ -34,38 +34,45 @@
 
     % Create an empty mvar.
     %
-:- impure func mvar.init = (mvar(T)::uo) is det.
+:- pred init(mvar(T)::out, io::di, io::uo) is det.
 
     % Create an empty mvar.
     %
-:- pred mvar.init(mvar(T)::out, io::di, io::uo) is det.
+:- impure func impure_init = (mvar(T)::uo) is det.
+
+    % Create an empty mvar.
+    %
+    % This has been renamed to impure_init.
+    %
+:- impure func init = (mvar(T)::uo) is det.
+:- pragma obsolete(init/0).
 
     % Take the contents of the mvar out leaving the mvar empty.
     % If the mvar is empty, block until some thread fills the mvar.
     %
-:- pred mvar.take(mvar(T)::in, T::out, io::di, io::uo) is det.
+:- pred take(mvar(T)::in, T::out, io::di, io::uo) is det.
 
     % Take the contents of the mvar out leaving the mvar empty.
     % Returns immediately with no if the mvar was empty, or yes(X) if
     % the mvar contained X.
     %
-:- pred mvar.try_take(mvar(T)::in, maybe(T)::out, io::di, io::uo) is det.
+:- pred try_take(mvar(T)::in, maybe(T)::out, io::di, io::uo) is det.
 
     % Place the value of type T into an empty mvar.
     % If the mvar is full block until it becomes empty.
     %
-:- pred mvar.put(mvar(T)::in, T::in, io::di, io::uo) is det.
+:- pred put(mvar(T)::in, T::in, io::di, io::uo) is det.
 
     % Place the value of type T into an empty mvar, returning yes on success.
     % If the mvar is full, return no immediately without blocking.
     %
-:- pred mvar.try_put(mvar(T)::in, T::in, bool::out, io::di, io::uo) is det.
+:- pred try_put(mvar(T)::in, T::in, bool::out, io::di, io::uo) is det.
 
     % Read the contents of mvar, without taking it out.
     % If the mvar is empty, block until it is full.
     % This is equivalent to mvar.take followed by mvar.put.
     %
-:- pred mvar.read(mvar(T)::in, T::out, io::di, io::uo) is det.
+:- pred read(mvar(T)::in, T::out, io::di, io::uo) is det.
 
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
@@ -85,17 +92,24 @@
                 mutvar(T)   % data
             ).
 
-mvar.init(Mvar, !IO) :-
+%-----------------------------------------------------------------------------%
+
+init(Mvar, !IO) :-
     promise_pure (
-        impure Mvar = mvar.init
+        impure Mvar = impure_init
     ).
 
-mvar.init = mvar(Full, Empty, Ref) :-
+impure_init = mvar(Full, Empty, Ref) :-
     impure semaphore.impure_init(0, Full),
     impure semaphore.impure_init(1, Empty),   % Initially a mvar starts empty.
     impure new_mutvar0(Ref).
 
-mvar.take(mvar(Full, Empty, Ref), Data, !IO) :-
+init = Mvar :-
+    impure Mvar = impure_init.
+
+%-----------------------------------------------------------------------------%
+
+take(mvar(Full, Empty, Ref), Data, !IO) :-
     promise_pure (
         semaphore.wait(Full, !IO),
         impure get_mutvar(Ref, Data),
@@ -104,7 +118,9 @@ mvar.take(mvar(Full, Empty, Ref), Data, !IO) :-
         semaphore.signal(Empty, !IO)
     ).
 
-mvar.try_take(mvar(Full, Empty, Ref), MaybeData, !IO) :-
+%-----------------------------------------------------------------------------%
+
+try_take(mvar(Full, Empty, Ref), MaybeData, !IO) :-
     promise_pure (
         semaphore.try_wait(Full, Success, !IO),
         (
@@ -120,14 +136,18 @@ mvar.try_take(mvar(Full, Empty, Ref), MaybeData, !IO) :-
         )
     ).
 
-mvar.put(mvar(Full, Empty, Ref), Data, !IO) :-
+%-----------------------------------------------------------------------------%
+
+put(mvar(Full, Empty, Ref), Data, !IO) :-
     promise_pure (
         semaphore.wait(Empty, !IO),
         impure set_mutvar(Ref, Data),
         semaphore.signal(Full, !IO)
     ).
 
-mvar.try_put(mvar(Full, Empty, Ref), Data, Success, !IO) :-
+%-----------------------------------------------------------------------------%
+
+try_put(mvar(Full, Empty, Ref), Data, Success, !IO) :-
     promise_pure (
         semaphore.try_wait(Empty, Success, !IO),
         (
@@ -139,7 +159,9 @@ mvar.try_put(mvar(Full, Empty, Ref), Data, Success, !IO) :-
         )
     ).
 
-mvar.read(mvar(Full, _Empty, Ref), Data, !IO) :-
+%-----------------------------------------------------------------------------%
+
+read(mvar(Full, _Empty, Ref), Data, !IO) :-
     promise_pure (
         semaphore.wait(Full, !IO),
         impure get_mutvar(Ref, Data),
-- 
2.1.0




More information about the reviews mailing list