mirror of
https://github.com/processone/ejabberd.git
synced 2024-09-27 14:30:55 +02:00
Fall back to map/2 and foreach/2 on single-core machines
This commit is contained in:
parent
01f531b3d6
commit
04ccba0347
64
src/misc.erl
64
src/misc.erl
@ -446,41 +446,49 @@ best_match(Pattern, Opts) ->
|
|||||||
|
|
||||||
-spec pmap(fun((T1) -> T2), [T1]) -> [T2].
|
-spec pmap(fun((T1) -> T2), [T1]) -> [T2].
|
||||||
pmap(Fun, [_,_|_] = List) ->
|
pmap(Fun, [_,_|_] = List) ->
|
||||||
Self = self(),
|
case erlang:system_info(logical_processors) of
|
||||||
lists:map(
|
1 -> lists:map(Fun, List);
|
||||||
fun({Pid, Ref}) ->
|
_ ->
|
||||||
receive
|
Self = self(),
|
||||||
{Pid, Ret} ->
|
lists:map(
|
||||||
|
fun({Pid, Ref}) ->
|
||||||
receive
|
receive
|
||||||
{'DOWN', Ref, _, _, _} ->
|
{Pid, Ret} ->
|
||||||
Ret
|
receive
|
||||||
end;
|
{'DOWN', Ref, _, _, _} ->
|
||||||
{'DOWN', Ref, _, _, Reason} ->
|
Ret
|
||||||
exit(Reason)
|
end;
|
||||||
end
|
{'DOWN', Ref, _, _, Reason} ->
|
||||||
end, [spawn_monitor(
|
exit(Reason)
|
||||||
fun() -> Self ! {self(), Fun(X)} end)
|
end
|
||||||
|| X <- List]);
|
end, [spawn_monitor(
|
||||||
|
fun() -> Self ! {self(), Fun(X)} end)
|
||||||
|
|| X <- List])
|
||||||
|
end;
|
||||||
pmap(Fun, List) ->
|
pmap(Fun, List) ->
|
||||||
lists:map(Fun, List).
|
lists:map(Fun, List).
|
||||||
|
|
||||||
-spec peach(fun((T) -> any()), [T]) -> ok.
|
-spec peach(fun((T) -> any()), [T]) -> ok.
|
||||||
peach(Fun, [_,_|_] = List) ->
|
peach(Fun, [_,_|_] = List) ->
|
||||||
Self = self(),
|
case erlang:system_info(logical_processors) of
|
||||||
lists:foreach(
|
1 -> lists:foreach(Fun, List);
|
||||||
fun({Pid, Ref}) ->
|
_ ->
|
||||||
receive
|
Self = self(),
|
||||||
Pid ->
|
lists:foreach(
|
||||||
|
fun({Pid, Ref}) ->
|
||||||
receive
|
receive
|
||||||
{'DOWN', Ref, _, _, _} ->
|
Pid ->
|
||||||
ok
|
receive
|
||||||
end;
|
{'DOWN', Ref, _, _, _} ->
|
||||||
{'DOWN', Ref, _, _, Reason} ->
|
ok
|
||||||
exit(Reason)
|
end;
|
||||||
end
|
{'DOWN', Ref, _, _, Reason} ->
|
||||||
end, [spawn_monitor(
|
exit(Reason)
|
||||||
fun() -> Fun(X), Self ! self() end)
|
end
|
||||||
|| X <- List]);
|
end, [spawn_monitor(
|
||||||
|
fun() -> Fun(X), Self ! self() end)
|
||||||
|
|| X <- List])
|
||||||
|
end;
|
||||||
peach(Fun, List) ->
|
peach(Fun, List) ->
|
||||||
lists:foreach(Fun, List).
|
lists:foreach(Fun, List).
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user