Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 52 lines (41 sloc) 1.504 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
%%%----------------------------------------------------------------------
%%% File : gproc_init.erl
%%% Purpose : GPROC init utilities
%%%----------------------------------------------------------------------

-module(gproc_init).

%% API
-export([
         %% soft reset
         soft_reset/0
         %% hard reset
         , hard_reset/0
        ]).

%%====================================================================
%% API
%%====================================================================

%%--------------------------------------------------------------------
%% soft_reset

%% soft_reset
-spec soft_reset() -> ok.

soft_reset() ->
    ok = hard_reset(), %% soft reset isn't enough
    ok.

%%--------------------------------------------------------------------
%% hard_reset

%% hard_reset
-spec hard_reset() -> ok.

hard_reset() ->
    %% exit normal {n,'_','_'}
    _ = [ exit(Pid,normal) || Pid <- gproc:lookup_pids({n,'_','_'}),
                              (node(Pid) =/= node())
                                  orelse is_process_alive(Pid) ],
    %% kill via supervisor
    ok = supervisor:terminate_child(gproc_sup, gproc),
    %% delete ets table
    _ = [ ets:delete(Tab) || Tab <- ets:all(), Tab =:= gproc ],
    %% restart via supervisor
    {ok,_} = supervisor:restart_child(gproc_sup, gproc),
    ok.


%%====================================================================
%% Internal functions
%%====================================================================
Something went wrong with that request. Please try again.