Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

added gproc:bcast/[2,3]

  • Loading branch information...
commit 56944c7f60de9e428d19e7d3d4db6e5722b56eb5 1 parent 53f97bd
Ulf Wiger uwiger authored committed
1  README.md
Source Rendered
@@ -91,6 +91,7 @@ Freiburg 2007 ([Paper available here](http://github.com/esl/gproc/blob/master/do
91 91 <table width="100%" border="0" summary="list of modules">
92 92 <tr><td><a href="http://github.com/esl/gproc/blob/master/doc/gproc.md" class="module">gproc</a></td></tr>
93 93 <tr><td><a href="http://github.com/esl/gproc/blob/master/doc/gproc_app.md" class="module">gproc_app</a></td></tr>
  94 +<tr><td><a href="http://github.com/esl/gproc/blob/master/doc/gproc_bcast.md" class="module">gproc_bcast</a></td></tr>
94 95 <tr><td><a href="http://github.com/esl/gproc/blob/master/doc/gproc_dist.md" class="module">gproc_dist</a></td></tr>
95 96 <tr><td><a href="http://github.com/esl/gproc/blob/master/doc/gproc_info.md" class="module">gproc_info</a></td></tr>
96 97 <tr><td><a href="http://github.com/esl/gproc/blob/master/doc/gproc_init.md" class="module">gproc_init</a></td></tr>
1  doc/README.md
Source Rendered
@@ -91,6 +91,7 @@ Freiburg 2007 ([Paper available here](erlang07-wiger.pdf)).
91 91 <table width="100%" border="0" summary="list of modules">
92 92 <tr><td><a href="gproc.md" class="module">gproc</a></td></tr>
93 93 <tr><td><a href="gproc_app.md" class="module">gproc_app</a></td></tr>
  94 +<tr><td><a href="gproc_bcast.md" class="module">gproc_bcast</a></td></tr>
94 95 <tr><td><a href="gproc_dist.md" class="module">gproc_dist</a></td></tr>
95 96 <tr><td><a href="gproc_info.md" class="module">gproc_info</a></td></tr>
96 97 <tr><td><a href="gproc_init.md" class="module">gproc_init</a></td></tr>
4 doc/edoc-info
... ... @@ -1,4 +1,4 @@
1 1 {application,gproc}.
2 2 {packages,[]}.
3   -{modules,[gproc,gproc_app,gproc_dist,gproc_info,gproc_init,gproc_lib,
4   - gproc_monitor,gproc_ps,gproc_sup]}.
  3 +{modules,[gproc,gproc_app,gproc_bcast,gproc_dist,gproc_info,gproc_init,
  4 + gproc_lib,gproc_monitor,gproc_ps,gproc_sup]}.
32 doc/gproc.md
Source Rendered
@@ -207,7 +207,7 @@ a = aggregate_counter
207 207 ##Function Index##
208 208
209 209
210   -<table width="100%" border="1" cellspacing="0" cellpadding="2" summary="function index"><tr><td valign="top"><a href="#add_global_aggr_counter-1">add_global_aggr_counter/1</a></td><td>Registers a global (unique) aggregated counter.</td></tr><tr><td valign="top"><a href="#add_global_counter-2">add_global_counter/2</a></td><td>Registers a global (non-unique) counter.</td></tr><tr><td valign="top"><a href="#add_global_name-1">add_global_name/1</a></td><td>Registers a global (unique) name.</td></tr><tr><td valign="top"><a href="#add_global_property-2">add_global_property/2</a></td><td>Registers a global (non-unique) property.</td></tr><tr><td valign="top"><a href="#add_local_aggr_counter-1">add_local_aggr_counter/1</a></td><td>Registers a local (unique) aggregated counter.</td></tr><tr><td valign="top"><a href="#add_local_counter-2">add_local_counter/2</a></td><td>Registers a local (non-unique) counter.</td></tr><tr><td valign="top"><a href="#add_local_name-1">add_local_name/1</a></td><td>Registers a local (unique) name.</td></tr><tr><td valign="top"><a href="#add_local_property-2">add_local_property/2</a></td><td>Registers a local (non-unique) property.</td></tr><tr><td valign="top"><a href="#add_shared_local_counter-2">add_shared_local_counter/2</a></td><td>Registers a local shared (unique) counter.</td></tr><tr><td valign="top"><a href="#audit_process-1">audit_process/1</a></td><td></td></tr><tr><td valign="top"><a href="#await-1">await/1</a></td><td>Equivalent to <a href="#await-2"><tt>await(Key, infinity)</tt></a>.</td></tr><tr><td valign="top"><a href="#await-2">await/2</a></td><td>Wait for a local name to be registered.</td></tr><tr><td valign="top"><a href="#cancel_wait-2">cancel_wait/2</a></td><td>Cancels a previous call to nb_wait/1.</td></tr><tr><td valign="top"><a href="#cancel_wait_or_monitor-1">cancel_wait_or_monitor/1</a></td><td></td></tr><tr><td valign="top"><a href="#default-1">default/1</a></td><td></td></tr><tr><td valign="top"><a href="#demonitor-2">demonitor/2</a></td><td>Remove a monitor on a registered name
  210 +<table width="100%" border="1" cellspacing="0" cellpadding="2" summary="function index"><tr><td valign="top"><a href="#add_global_aggr_counter-1">add_global_aggr_counter/1</a></td><td>Registers a global (unique) aggregated counter.</td></tr><tr><td valign="top"><a href="#add_global_counter-2">add_global_counter/2</a></td><td>Registers a global (non-unique) counter.</td></tr><tr><td valign="top"><a href="#add_global_name-1">add_global_name/1</a></td><td>Registers a global (unique) name.</td></tr><tr><td valign="top"><a href="#add_global_property-2">add_global_property/2</a></td><td>Registers a global (non-unique) property.</td></tr><tr><td valign="top"><a href="#add_local_aggr_counter-1">add_local_aggr_counter/1</a></td><td>Registers a local (unique) aggregated counter.</td></tr><tr><td valign="top"><a href="#add_local_counter-2">add_local_counter/2</a></td><td>Registers a local (non-unique) counter.</td></tr><tr><td valign="top"><a href="#add_local_name-1">add_local_name/1</a></td><td>Registers a local (unique) name.</td></tr><tr><td valign="top"><a href="#add_local_property-2">add_local_property/2</a></td><td>Registers a local (non-unique) property.</td></tr><tr><td valign="top"><a href="#add_shared_local_counter-2">add_shared_local_counter/2</a></td><td>Registers a local shared (unique) counter.</td></tr><tr><td valign="top"><a href="#audit_process-1">audit_process/1</a></td><td></td></tr><tr><td valign="top"><a href="#await-1">await/1</a></td><td>Equivalent to <a href="#await-2"><tt>await(Key, infinity)</tt></a>.</td></tr><tr><td valign="top"><a href="#await-2">await/2</a></td><td>Wait for a local name to be registered.</td></tr><tr><td valign="top"><a href="#bcast-2">bcast/2</a></td><td>Equivalent to <a href="#bcast-3"><tt>bcast(nodes(), Key, Msg)</tt></a>.</td></tr><tr><td valign="top"><a href="#bcast-3">bcast/3</a></td><td>Sends a message to processes corresponding to Key on Nodes.</td></tr><tr><td valign="top"><a href="#cancel_wait-2">cancel_wait/2</a></td><td>Cancels a previous call to nb_wait/1.</td></tr><tr><td valign="top"><a href="#cancel_wait_or_monitor-1">cancel_wait_or_monitor/1</a></td><td></td></tr><tr><td valign="top"><a href="#default-1">default/1</a></td><td></td></tr><tr><td valign="top"><a href="#demonitor-2">demonitor/2</a></td><td>Remove a monitor on a registered name
211 211 This function is the reverse of monitor/1.</td></tr><tr><td valign="top"><a href="#first-1">first/1</a></td><td>Behaves as ets:first(Tab) for a given type of registration object.</td></tr><tr><td valign="top"><a href="#get_env-3">get_env/3</a></td><td>Equivalent to <a href="#get_env-4"><tt>get_env(Scope, App, Key, [app_env])</tt></a>.</td></tr><tr><td valign="top"><a href="#get_env-4">get_env/4</a></td><td>Read an environment value, potentially cached as a <code>gproc_env</code> property.</td></tr><tr><td valign="top"><a href="#get_set_env-3">get_set_env/3</a></td><td>Equivalent to <a href="#get_set_env-4"><tt>get_set_env(Scope, App, Key, [app_env])</tt></a>.</td></tr><tr><td valign="top"><a href="#get_set_env-4">get_set_env/4</a></td><td>Fetch and cache an environment value, if not already cached.</td></tr><tr><td valign="top"><a href="#get_value-1">get_value/1</a></td><td>Reads the value stored with a key registered to the current process.</td></tr><tr><td valign="top"><a href="#get_value-2">get_value/2</a></td><td>Reads the value stored with a key registered to the process Pid.</td></tr><tr><td valign="top"><a href="#give_away-2">give_away/2</a></td><td>Atomically transfers the key <code>From</code> to the process identified by <code>To</code>.</td></tr><tr><td valign="top"><a href="#goodbye-0">goodbye/0</a></td><td>Unregister all items of the calling process and inform gproc
212 212 to forget about the calling process.</td></tr><tr><td valign="top"><a href="#i-0">i/0</a></td><td>Similar to the built-in shell command <code>i()</code> but inserts information
213 213 about names and properties registered in Gproc, where applicable.</td></tr><tr><td valign="top"><a href="#info-1">info/1</a></td><td>Similar to <code>process_info(Pid)</code> but with additional gproc info.</td></tr><tr><td valign="top"><a href="#info-2">info/2</a></td><td>Similar to process_info(Pid, Item), but with additional gproc info.</td></tr><tr><td valign="top"><a href="#last-1">last/1</a></td><td>Behaves as ets:last(Tab) for a given type of registration object.</td></tr><tr><td valign="top"><a href="#lookup_global_aggr_counter-1">lookup_global_aggr_counter/1</a></td><td>Lookup a global (unique) aggregated counter and returns its value.</td></tr><tr><td valign="top"><a href="#lookup_global_counters-1">lookup_global_counters/1</a></td><td>Look up all global (non-unique) instances of a given Counter.</td></tr><tr><td valign="top"><a href="#lookup_global_name-1">lookup_global_name/1</a></td><td>Lookup a global unique name.</td></tr><tr><td valign="top"><a href="#lookup_global_properties-1">lookup_global_properties/1</a></td><td>Look up all global (non-unique) instances of a given Property.</td></tr><tr><td valign="top"><a href="#lookup_local_aggr_counter-1">lookup_local_aggr_counter/1</a></td><td>Lookup a local (unique) aggregated counter and returns its value.</td></tr><tr><td valign="top"><a href="#lookup_local_counters-1">lookup_local_counters/1</a></td><td>Look up all local (non-unique) instances of a given Counter.</td></tr><tr><td valign="top"><a href="#lookup_local_name-1">lookup_local_name/1</a></td><td>Lookup a local unique name.</td></tr><tr><td valign="top"><a href="#lookup_local_properties-1">lookup_local_properties/1</a></td><td>Look up all local (non-unique) instances of a given Property.</td></tr><tr><td valign="top"><a href="#lookup_pid-1">lookup_pid/1</a></td><td>Lookup the Pid stored with a key.</td></tr><tr><td valign="top"><a href="#lookup_pids-1">lookup_pids/1</a></td><td>Returns a list of pids with the published key Key.</td></tr><tr><td valign="top"><a href="#lookup_value-1">lookup_value/1</a></td><td>Lookup the value stored with a key.</td></tr><tr><td valign="top"><a href="#lookup_values-1">lookup_values/1</a></td><td>Retrieve the <code>{Pid,Value}</code> pairs corresponding to Key.</td></tr><tr><td valign="top"><a href="#monitor-1">monitor/1</a></td><td>monitor a registered name
@@ -320,7 +320,35 @@ either an interger > 0 or 'infinity'.
320 320 A small optimization: we first perform a lookup, to see if the name
321 321 is already registered. This way, the cost of the operation will be
322 322 roughly the same as of where/1 in the case where the name is already
323   -registered (the difference: await/2 also returns the value).<a name="cancel_wait-2"></a>
  323 +registered (the difference: await/2 also returns the value).<a name="bcast-2"></a>
  324 +
  325 +###bcast/2##
  326 +
  327 +
  328 +<pre>bcast(Key::<a href="#type-key">key()</a>, Msg::any()) -> Msg</pre>
  329 +<br></br>
  330 +
  331 +
  332 +Equivalent to [`bcast(nodes(), Key, Msg)`](#bcast-3).<a name="bcast-3"></a>
  333 +
  334 +###bcast/3##
  335 +
  336 +
  337 +<pre>bcast(Nodes::[atom()], Key::<a href="#type-key">key()</a>, Msg::any()) -> Msg</pre>
  338 +<br></br>
  339 +
  340 +
  341 +
  342 +
  343 +Sends a message to processes corresponding to Key on Nodes.
  344 +
  345 +This function complements `send/2` and works on locally registered resources
  346 +that `send/2` supports. Messages are routed via a special broadcast server
  347 +on each node to ensure that ordering is preserved. Distributed delivery
  348 +is asynchronous and carries the same guarantees as normal message passing
  349 +(with the added proviso that the broadcast server also needs to be available).
  350 +
  351 +__See also:__ [send/2](#send-2).<a name="cancel_wait-2"></a>
324 352
325 353 ###cancel_wait/2##
326 354
30 src/gproc.erl
@@ -95,6 +95,7 @@
95 95 give_away/2,
96 96 goodbye/0,
97 97 send/2,
  98 + bcast/2, bcast/3,
98 99 info/1, info/2,
99 100 i/0,
100 101 select/1, select/2, select/3,
@@ -1401,6 +1402,34 @@ send1({T,C,_} = Key, Msg) when C==l; C==g ->
1401 1402 send1(_, _) ->
1402 1403 ?THROW_GPROC_ERROR(badarg).
1403 1404
  1405 +%% @spec (Key::key(), Msg::any()) -> Msg
  1406 +%%
  1407 +%% @equiv bcast(nodes(), Key, Msg)
  1408 +%% @end
  1409 +%%
  1410 +bcast(Key, Msg) ->
  1411 + bcast(nodes(), Key, Msg).
  1412 +
  1413 +%% @spec (Nodes::[atom()], Key::key(), Msg::any()) -> Msg
  1414 +%%
  1415 +%% @doc Sends a message to processes corresponding to Key on Nodes.
  1416 +%%
  1417 +%% This function complements `send/2' and works on locally registered resources
  1418 +%% that `send/2' supports. Messages are routed via a special broadcast server
  1419 +%% on each node to ensure that ordering is preserved. Distributed delivery
  1420 +%% is asynchronous and carries the same guarantees as normal message passing
  1421 +%% (with the added proviso that the broadcast server also needs to be available).
  1422 +%% @see send/2
  1423 +%% @end
  1424 +%%
  1425 +bcast(Ns, Key, Msg) ->
  1426 + ?CATCH_GPROC_ERROR(bcast1(Ns, Key, Msg), [Key, Msg]).
  1427 +
  1428 +bcast1(Ns, {T,l,_} = Key, Msg) when T==p; T==a; T==c; T==n; T==p ->
  1429 + send1(Key, Msg),
  1430 + gen_server:abcast(Ns -- [node()], gproc_bcast, {send, Key, Msg}),
  1431 + Msg.
  1432 +
1404 1433
1405 1434 %% @spec (Context :: context()) -> key() | '$end_of_table'
1406 1435 %%
@@ -1727,6 +1756,7 @@ code_change(_FromVsn, S, _Extra) ->
1727 1756 end,
1728 1757 {ok, S}.
1729 1758
  1759 +
1730 1760 %% @hidden
1731 1761 terminate(_Reason, _S) ->
1732 1762 ok.
4 src/gproc_sup.erl
@@ -50,7 +50,9 @@ init(_Args) ->
50 50 end,
51 51 Mon = {gproc_monitor, {gproc_monitor, start_link, []},
52 52 permanent, 2000, worker, [gproc_monitor]},
53   - {ok,{{one_for_one, 15, 60}, [GProc| Dist] ++ [Mon]}}.
  53 + BCast = {gproc_bcast, {gproc_bcast, start_link, []},
  54 + permanent, 2000, worker, [gproc_bcast]},
  55 + {ok,{{one_for_one, 15, 60}, [GProc| Dist] ++ [Mon, BCast]}}.
54 56
55 57
56 58 %%%----------------------------------------------------------------------

0 comments on commit 56944c7

Please sign in to comment.
Something went wrong with that request. Please try again.