erlang's global lock
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

41 linhas
916 B

  1. -module(eALockMgr).
  2. -behaviour(gen_server).
  3. -include("eGLock.hrl").
  4. -export([start_link/0]).
  5. -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2,
  6. code_change/3]).
  7. -define(SERVER, ?MODULE).
  8. -record(state, {}).
  9. %%%===================================================================
  10. %%% Spawning and gen_server implementation
  11. %%%===================================================================
  12. start_link() ->
  13. gen_server:start_link({local, ?SERVER}, ?MODULE, [], []).
  14. init([]) ->
  15. process_flag(trap_exit, true),
  16. ATLockRef = atomics:new(?eALockSize, [{signed, false}]),
  17. persistent_term:put(?eALockRef, ATLockRef),
  18. {ok, #state{}}.
  19. handle_call(_Request, _From, State) ->
  20. {reply, ok, State}.
  21. handle_cast(_Request, State) ->
  22. {noreply, State}.
  23. handle_info(_Info, State) ->
  24. {noreply, State}.
  25. terminate(_Reason, _State) ->
  26. ok.
  27. code_change(_OldVsn, State, _Extra) ->
  28. {ok, State}.