Fix: bad implementation of with_mutex/2

This commit is contained in:
Vítor Santos Costa 2014-05-30 01:00:57 +01:00
parent 21fe137d27
commit 37e8fcc353
2 changed files with 26 additions and 25 deletions

View File

@ -1018,7 +1018,7 @@ source_file_property( File0, Prop) :-
'$source_file_property'( File, Prop).
'$source_file_property'( OldF, includes(F, Age)) :-
recorded('$lf_loaded','$lf_loaded'( F, _M, _ include, _File, OldF, _Line, _), _),
recorded('$lf_loaded','$lf_loaded'( F, _M, include, _File, OldF, _Line, _), _),
recorded('$lf_loaded','$lf_loaded'( F, Age, _), _).
'$source_file_property'( F, included_in(OldF, Line)) :-
recorded('$lf_loaded','$lf_loaded'( F, _M, include, _File, OldF, Line, _), _).

View File

@ -564,35 +564,36 @@ mutex_unlock_all :-
'$mutex_unlock_all'(Id).
with_mutex(M, G) :-
'$no_threads', !,
call(G).
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), !,
'$with_mutex_mutex'(WMId),
'$lock_mutex'(WMId),
( recorded('$mutex_alias',[Id|M],_) ->
( '$no_threads' ->
once(G)
;
var(M) ->
'$do_error'(instantiation_error,with_mutex(M, G))
;
var(G) ->
'$do_error'(instantiation_error,with_mutex(M, G))
;
\+ callable(G) ->
'$do_error'(type_error(callable,G),with_mutex(M, G))
;
atom(M) ->
'$with_mutex_mutex'(WMId),
'$lock_mutex'(WMId),
( recorded('$mutex_alias',[Id|M],_) ->
true
; '$new_mutex'(Id),
; '$new_mutex'(Id),
recorda('$mutex_alias',[Id|M],_)
),
'$lock_mutex'(Id),
'$unlock_mutex'(WMId),
( catch('$execute'(G), E, ('$unlock_mutex'(Id), throw(E))) ->
),
'$unlock_mutex'(WMId),
'$lock_mutex'(Id),
( catch('$execute'(G), E, ('$unlock_mutex'(Id), throw(E))) ->
'$unlock_mutex'(Id)
; '$unlock_mutex'(Id),
; '$unlock_mutex'(Id),
fail
)
;
'$do_error'(type_error(atom,M),with_mutex(M, G))
).
with_mutex(M, G) :-
'$do_error'(type_error(atom,M),with_mutex(M, G)).
current_mutex(M, T, NRefs) :-
recorded('$mutex_alias',[Id|M],_),