summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexandru Scvortov <alexandru@rabbitmq.com>2011-09-07 15:19:48 +0100
committerAlexandru Scvortov <alexandru@rabbitmq.com>2011-09-07 15:19:48 +0100
commit9acf13278d94ccf7f16dc138988b918b89794623 (patch)
tree6b412fbdc02957db2177a81b52cd3907854645be
parent42f660ca790f091638bedc003fc465c164ffbd1a (diff)
downloadrabbitmq-server-9acf13278d94ccf7f16dc138988b918b89794623.tar.gz
if the worker_pool is not running, run the submitted job in the current process
The only time when this happens is when using the file2 and filelib2 functions during prelaunch and prepare, which should be fine. The alternative is starting worker_pool before it's needed, but the logic of that ends up being quite complicated, as we also have to stop it before starting rabbit fully and it may already be running.
-rw-r--r--src/rabbit.erl5
-rw-r--r--src/rabbit_prelaunch.erl3
-rw-r--r--src/worker_pool.erl14
3 files changed, 11 insertions, 11 deletions
diff --git a/src/rabbit.erl b/src/rabbit.erl
index 0a4aa032..b8dbccc7 100644
--- a/src/rabbit.erl
+++ b/src/rabbit.erl
@@ -211,11 +211,8 @@
%%----------------------------------------------------------------------------
prepare() ->
- %% Some of the rabbit_misc functions use worker_pool, so start it now.
- {ok, Pid} = worker_pool_sup:start_link(),
ok = ensure_working_log_handlers(),
- ok = rabbit_upgrade:maybe_upgrade_mnesia(),
- exit(Pid, shutdown).
+ ok = rabbit_upgrade:maybe_upgrade_mnesia().
start() ->
try
diff --git a/src/rabbit_prelaunch.erl b/src/rabbit_prelaunch.erl
index bbbea543..92829e49 100644
--- a/src/rabbit_prelaunch.erl
+++ b/src/rabbit_prelaunch.erl
@@ -37,9 +37,6 @@
start() ->
io:format("Activating RabbitMQ plugins ...~n"),
- %% Some of the rabbit_misc functions use worker_pool, so start it now.
- worker_pool_sup:start_link(),
-
%% Determine our various directories
[PluginDir, UnpackedPluginDir, NodeStr] = init:get_plain_arguments(),
RootName = UnpackedPluginDir ++ "/rabbit",
diff --git a/src/worker_pool.erl b/src/worker_pool.erl
index e4f260cc..bdcafc84 100644
--- a/src/worker_pool.erl
+++ b/src/worker_pool.erl
@@ -59,10 +59,16 @@ start_link() ->
[{timeout, infinity}]).
submit(Fun) ->
- case get(worker_pool_worker) of
- true -> worker_pool_worker:run(Fun);
- _ -> Pid = gen_server2:call(?SERVER, next_free, infinity),
- worker_pool_worker:submit(Pid, Fun)
+ %% If the worker_pool is not running, just run the Fun in the
+ %% current process.
+ case whereis(?SERVER) of
+ undefined -> Fun();
+ _ -> case get(worker_pool_worker) of
+ true -> worker_pool_worker:run(Fun);
+ _ -> Pid = gen_server2:call(?SERVER, next_free,
+ infinity),
+ worker_pool_worker:submit(Pid, Fun)
+ end
end.
submit_async(Fun) ->