anchor.diff:  release_lock({Tid, Oid, {queued, _}}) ->
       ?ets_match_delete(mnesia_lock_queue, #queue{oid=Oid, tid = Tid, op = '_',
   						pid = '_', lucky = '_'});
  -release_lock({Tid, Oid, Op}) ->
  -    if
  -	Op == write ->
  -	    ?ets_delete(mnesia_held_locks, {Oid, Tid});
  -	Op == read ->
  -	    ets:delete_object(mnesia_held_locks, {{Oid, Tid}, Op})
  +release_lock({This, Oid, Op}) ->
  +    case ?ets_lookup(mnesia_held_locks, Oid) of
  +	[] -> ok;
  +	[{Oid, Prev, Locks0}] ->
  +	    Locks = [{TOp, Tid} || {TOp, Tid} <- Locks0, Tid =/= This],
  +	    if Locks =:= [] ->
  +		    ?ets_delete(mnesia_held_locks, Oid);
  +	       Op =:= read ->
  +		    ?ets_insert(mnesia_held_locks, {Oid, Prev, Locks});
  +	       true ->
  +		    case lists:any(fun({TOp, _}) -> TOp =:= write end, Locks) of
  +			true ->
  +			    ?ets_insert(mnesia_held_locks, {Oid, write, Locks});
  +			false ->
  +			    ?ets_insert(mnesia_held_locks, {Oid, read, Locks})
  +		    end
  +	    end
       end.
   
   rearrange_queue([{_Tid, {Tab, Key}, _} | Locks]) ->
  
positive.code: 
  set_lock(Tid, Oid, Op) ->
      ?dbg("Granted ~p ~p ~p~n", [Tid,Oid,Op]),
      ?ets_insert(mnesia_held_locks, {{Oid, Tid}, Op}),
      ?ets_insert(mnesia_tid_locks, {Tid, Oid, Op}).
  
  %%%%%%%%%%%%%%%%%%%%%%%%%%%
  
negative.code: 
  get_held_locks() ->
      ?MODULE ! {get_table, self(), mnesia_held_locks},
      Locks = receive {mnesia_held_locks, Ls} -> Ls after 5000 -> [] end,
      rewrite_locks(Locks, []).
  
  rewrite_locks([{Oid, _, Ls}|Locks], Acc0) ->
      Acc = rewrite_locks(Ls, Oid, Acc0),
      rewrite_locks(Locks, Acc);
  rewrite_locks([], Acc) ->
      lists:reverse(Acc).
  
  rewrite_locks([{Op, Tid}|Ls], Oid, Acc) ->
      rewrite_locks(Ls, Oid, [{Oid, Op, Tid}|Acc]);
  rewrite_locks([], _, Acc) ->
      Acc.
  
  get_lock_queue() ->
      ?MODULE ! {get_table, self(), mnesia_lock_queue},
      Q = receive {mnesia_lock_queue, Locks} -> Locks after 5000 -> [] end,
      [{Oid, Op, Pid, Tid, WFT} || {queue, Oid, Tid, Op, Pid, WFT} <- Q].
  
  do_stop() ->
  