mirror of
https://github.com/processone/ejabberd.git
synced 2024-06-18 22:15:20 +02:00
Fall back to map/2 and foreach/2 on single-core machines
This commit is contained in:
parent
01f531b3d6
commit
04ccba0347
12
src/misc.erl
12
src/misc.erl
|
@ -446,6 +446,9 @@ best_match(Pattern, Opts) ->
|
||||||
|
|
||||||
-spec pmap(fun((T1) -> T2), [T1]) -> [T2].
|
-spec pmap(fun((T1) -> T2), [T1]) -> [T2].
|
||||||
pmap(Fun, [_,_|_] = List) ->
|
pmap(Fun, [_,_|_] = List) ->
|
||||||
|
case erlang:system_info(logical_processors) of
|
||||||
|
1 -> lists:map(Fun, List);
|
||||||
|
_ ->
|
||||||
Self = self(),
|
Self = self(),
|
||||||
lists:map(
|
lists:map(
|
||||||
fun({Pid, Ref}) ->
|
fun({Pid, Ref}) ->
|
||||||
|
@ -460,12 +463,16 @@ pmap(Fun, [_,_|_] = List) ->
|
||||||
end
|
end
|
||||||
end, [spawn_monitor(
|
end, [spawn_monitor(
|
||||||
fun() -> Self ! {self(), Fun(X)} end)
|
fun() -> Self ! {self(), Fun(X)} end)
|
||||||
|| X <- List]);
|
|| 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) ->
|
||||||
|
case erlang:system_info(logical_processors) of
|
||||||
|
1 -> lists:foreach(Fun, List);
|
||||||
|
_ ->
|
||||||
Self = self(),
|
Self = self(),
|
||||||
lists:foreach(
|
lists:foreach(
|
||||||
fun({Pid, Ref}) ->
|
fun({Pid, Ref}) ->
|
||||||
|
@ -480,7 +487,8 @@ peach(Fun, [_,_|_] = List) ->
|
||||||
end
|
end
|
||||||
end, [spawn_monitor(
|
end, [spawn_monitor(
|
||||||
fun() -> Fun(X), Self ! self() end)
|
fun() -> Fun(X), Self ! self() end)
|
||||||
|| X <- List]);
|
|| 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