diff options
| author | Alexandru Scvortov <alexandru@rabbitmq.com> | 2011-09-07 15:19:48 +0100 |
|---|---|---|
| committer | Alexandru Scvortov <alexandru@rabbitmq.com> | 2011-09-07 15:19:48 +0100 |
| commit | 4b1d22c617adfe178d89b0dd91e19d71023ede76 (patch) | |
| tree | 6b412fbdc02957db2177a81b52cd3907854645be /src | |
| parent | dbdec09ea1dba290da41622184593fce85f57411 (diff) | |
| download | rabbitmq-server-git-4b1d22c617adfe178d89b0dd91e19d71023ede76.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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/rabbit.erl | 5 | ||||
| -rw-r--r-- | src/rabbit_prelaunch.erl | 3 | ||||
| -rw-r--r-- | src/worker_pool.erl | 14 |
3 files changed, 11 insertions, 11 deletions
diff --git a/src/rabbit.erl b/src/rabbit.erl index 0a4aa03240..b8dbccc767 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 bbbea54358..92829e4918 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 e4f260cc50..bdcafc8419 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) -> |
