gproc_init.erl 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. %%%----------------------------------------------------------------------
  2. %%% File : gproc_init.erl
  3. %%% Purpose : GPROC init utilities
  4. %%%----------------------------------------------------------------------
  5. -module(gproc_init).
  6. %% API
  7. -export([
  8. %% soft reset
  9. soft_reset/0
  10. %% hard reset
  11. , hard_reset/0
  12. ]).
  13. %%====================================================================
  14. %% API
  15. %%====================================================================
  16. %%--------------------------------------------------------------------
  17. %% soft_reset
  18. %% soft_reset
  19. -spec soft_reset() -> ok.
  20. soft_reset() ->
  21. ok = hard_reset(), %% soft reset isn't enough
  22. ok.
  23. %%--------------------------------------------------------------------
  24. %% hard_reset
  25. %% hard_reset
  26. -spec hard_reset() -> ok.
  27. hard_reset() ->
  28. %% exit normal {n,'_','_'}
  29. _ = [ exit(Pid,normal) || Pid <- gproc:lookup_pids({n,'_','_'}),
  30. (node(Pid) =/= node()) orelse is_process_alive(Pid) ],
  31. %% kill via supervisor
  32. ok = supervisor:terminate_child(gproc_sup, gproc),
  33. %% delete ets table
  34. _ = [ ets:delete(Tab) || Tab <- ets:all(), Tab =:= gproc ],
  35. %% restart via supervisor
  36. {ok,_} = supervisor:restart_child(gproc_sup, gproc),
  37. ok.
  38. %%====================================================================
  39. %% Internal functions
  40. %%====================================================================