gproc_init.erl 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. %% types
  17. %% soft_reset
  18. -spec soft_reset() -> ok.
  19. %% hard_reset
  20. -spec hard_reset() -> ok.
  21. %%--------------------------------------------------------------------
  22. %% soft_reset
  23. soft_reset() ->
  24. ok = hard_reset(), %% soft reset isn't enough
  25. ok.
  26. %%--------------------------------------------------------------------
  27. %% hard_reset
  28. hard_reset() ->
  29. %% exit normal {n,'_','_'}
  30. [ exit(Pid,normal) || Pid <- gproc:lookup_pids({n,'_','_'}), 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. %%====================================================================