gproc_init.erl 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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())
  31. orelse is_process_alive(Pid) ],
  32. %% kill via supervisor
  33. ok = supervisor:terminate_child(gproc_sup, gproc),
  34. %% delete ets table
  35. _ = [ ets:delete(Tab) || Tab <- ets:all(), Tab =:= gproc ],
  36. %% restart via supervisor
  37. {ok,_} = supervisor:restart_child(gproc_sup, gproc),
  38. ok.
  39. %%====================================================================
  40. %% Internal functions
  41. %%====================================================================