Implemented the predicate with_mutex/2.

git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1751 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
pmoura 2006-12-30 10:49:37 +00:00
parent 7d1b20c9cd
commit 8ddee740a4
2 changed files with 24 additions and 2 deletions

View File

@ -16,8 +16,9 @@
<h2>Yap-5.1.2:</h2>
<ul>
<li> NEW: with_mutex/2.</li>
<li> NEW: call_cleanup/2 and call_cleanup/3 at the request of Paulo
Moura and Christian1.</li>
Moura and Christian.</li>
<li> FIXED: garbage collector would not understand bindings to mavars in
tabling version.</li>
<li> FIXED: cut might not prune correctly around meta-call (obs by

View File

@ -336,6 +336,27 @@ mutex_unlock_all.
'$unlock_mutex'(Id),
'$mutex_unlock_all'(Id).
with_mutex(M, G) :-
var(M), !,
'$do_error'(instantiation_error,with_mutex(M, G)).
with_mutex(M, G) :-
var(G), !,
'$do_error'(instantiation_error,with_mutex(M, G)).
with_mutex(M, G) :-
\+ callable(G),
'$do_error'(type_error(callable,G),with_mutex(M, G)).
with_mutex(M, G) :-
atom(M), !,
( recorded('$mutex',[M|Id],_) ->
true
; '$new_mutex'(Id),
recorda('$mutex',[M|Id],_)
),
'$lock_mutex'(Id),
call_cleanup(once(G), '$unlock_mutex'(Id)).
with_mutex(M, G) :-
'$do_error'(type_error(atom,M),with_mutex(M, G)).
current_mutex(M, T, NRefs) :-
recorded('$mutex',[M|Id],_),
'$mutex_info'(Id, NRefs, T).