# HG changeset patch # User Paul Boddie # Date 1679423014 -3600 # Node ID 2a71834ac302a86735681ab264c7507fe73c557c # Parent 765a2e126867c231f7d1b7d918f8bc47707d791b Introduced a new method to start a resource in an existing thread, also providing control over resource finalisation in the existing methods. diff -r 765a2e126867 -r 2a71834ac302 libfsserver/include/fsserver/resource_server.h --- a/libfsserver/include/fsserver/resource_server.h Mon Mar 20 22:38:24 2023 +0100 +++ b/libfsserver/include/fsserver/resource_server.h Tue Mar 21 19:23:34 2023 +0100 @@ -55,9 +55,11 @@ long start(bool finalisation = false); - long start_thread(); + long start_in_thread(l4_cap_idx_t thread, bool finalisation = false); - long start_thread(l4_cap_idx_t *server); + long start_thread(bool finalisation = true); + + long start_thread(l4_cap_idx_t *server, bool finalisation = true); }; @@ -67,7 +69,8 @@ void resource_init_config(ipc_server_config_type *config, Resource *resource); void resource_set_config_threaded(ipc_server_config_type *config, - l4_cap_idx_t thread, int new_thread); + l4_cap_idx_t thread, int new_thread, + int finalisation); /* Server initiation. */ diff -r 765a2e126867 -r 2a71834ac302 libfsserver/lib/generic/resource_server.cc --- a/libfsserver/lib/generic/resource_server.cc Mon Mar 20 22:38:24 2023 +0100 +++ b/libfsserver/lib/generic/resource_server.cc Tue Mar 21 19:23:34 2023 +0100 @@ -61,9 +61,19 @@ return resource_start_config(_config, _resource); } -/* Start a new thread with deletion notifications and finalisation. */ +/* Start serving a resource in an existing thread. */ + +long ResourceServer::start_in_thread(l4_cap_idx_t thread, bool finalisation) +{ + resource_init_config(_config, _resource); + resource_set_config_threaded(_config, thread, 1, finalisation); -long ResourceServer::start_thread() + return resource_start_config(_config, _resource); +} + +/* Start serving a resource in a new thread. */ + +long ResourceServer::start_thread(bool finalisation) { pthread_t thread; pthread_attr_t attr; @@ -78,7 +88,7 @@ if (err) return err; - resource_set_config_threaded(_config, pthread_l4_cap(thread), 1); + resource_set_config_threaded(_config, pthread_l4_cap(thread), 1, finalisation); return resource_start_config(_config, _resource); } @@ -86,9 +96,9 @@ /* A convenience method starting a thread and returning the server capability employed via the given parameter. */ -long ResourceServer::start_thread(l4_cap_idx_t *server) +long ResourceServer::start_thread(l4_cap_idx_t *server, bool finalisation) { - long err = start_thread(); + long err = start_thread(finalisation); if (!err) *server = _config->server; @@ -113,12 +123,13 @@ /* Set a configuration to be threaded. */ void resource_set_config_threaded(ipc_server_config_type *config, - l4_cap_idx_t thread, int new_thread) + l4_cap_idx_t thread, int new_thread, + int finalisation) { config->finaliser = resource_thread_finaliser; config->config_thread = new_thread; config->thread = thread; - config->notifications = 1; + config->notifications = finalisation; } /* Activate a resource and start a server for it. */