L4Re/departure

Changeset

533:2a71834ac302
2023-03-21 Paul Boddie raw files shortlog changelog graph Introduced a new method to start a resource in an existing thread, also providing control over resource finalisation in the existing methods.
libfsserver/include/fsserver/resource_server.h (file) libfsserver/lib/generic/resource_server.cc (file)
     1.1 --- a/libfsserver/include/fsserver/resource_server.h	Mon Mar 20 22:38:24 2023 +0100
     1.2 +++ b/libfsserver/include/fsserver/resource_server.h	Tue Mar 21 19:23:34 2023 +0100
     1.3 @@ -55,9 +55,11 @@
     1.4  
     1.5    long start(bool finalisation = false);
     1.6  
     1.7 -  long start_thread();
     1.8 +  long start_in_thread(l4_cap_idx_t thread, bool finalisation = false);
     1.9  
    1.10 -  long start_thread(l4_cap_idx_t *server);
    1.11 +  long start_thread(bool finalisation = true);
    1.12 +
    1.13 +  long start_thread(l4_cap_idx_t *server, bool finalisation = true);
    1.14  };
    1.15  
    1.16  
    1.17 @@ -67,7 +69,8 @@
    1.18  void resource_init_config(ipc_server_config_type *config, Resource *resource);
    1.19  
    1.20  void resource_set_config_threaded(ipc_server_config_type *config,
    1.21 -                                  l4_cap_idx_t thread, int new_thread);
    1.22 +                                  l4_cap_idx_t thread, int new_thread,
    1.23 +                                  int finalisation);
    1.24  
    1.25  /* Server initiation. */
    1.26  
     2.1 --- a/libfsserver/lib/generic/resource_server.cc	Mon Mar 20 22:38:24 2023 +0100
     2.2 +++ b/libfsserver/lib/generic/resource_server.cc	Tue Mar 21 19:23:34 2023 +0100
     2.3 @@ -61,9 +61,19 @@
     2.4    return resource_start_config(_config, _resource);
     2.5  }
     2.6  
     2.7 -/* Start a new thread with deletion notifications and finalisation. */
     2.8 +/* Start serving a resource in an existing thread. */
     2.9 +
    2.10 +long ResourceServer::start_in_thread(l4_cap_idx_t thread, bool finalisation)
    2.11 +{
    2.12 +  resource_init_config(_config, _resource);
    2.13 +  resource_set_config_threaded(_config, thread, 1, finalisation);
    2.14  
    2.15 -long ResourceServer::start_thread()
    2.16 +  return resource_start_config(_config, _resource);
    2.17 +}
    2.18 +
    2.19 +/* Start serving a resource in a new thread. */
    2.20 +
    2.21 +long ResourceServer::start_thread(bool finalisation)
    2.22  {
    2.23    pthread_t thread;
    2.24    pthread_attr_t attr;
    2.25 @@ -78,7 +88,7 @@
    2.26    if (err)
    2.27      return err;
    2.28  
    2.29 -  resource_set_config_threaded(_config, pthread_l4_cap(thread), 1);
    2.30 +  resource_set_config_threaded(_config, pthread_l4_cap(thread), 1, finalisation);
    2.31  
    2.32    return resource_start_config(_config, _resource);
    2.33  }
    2.34 @@ -86,9 +96,9 @@
    2.35  /* A convenience method starting a thread and returning the server capability
    2.36     employed via the given parameter. */
    2.37  
    2.38 -long ResourceServer::start_thread(l4_cap_idx_t *server)
    2.39 +long ResourceServer::start_thread(l4_cap_idx_t *server, bool finalisation)
    2.40  {
    2.41 -  long err = start_thread();
    2.42 +  long err = start_thread(finalisation);
    2.43  
    2.44    if (!err)
    2.45      *server = _config->server;
    2.46 @@ -113,12 +123,13 @@
    2.47  /* Set a configuration to be threaded. */
    2.48  
    2.49  void resource_set_config_threaded(ipc_server_config_type *config,
    2.50 -                                  l4_cap_idx_t thread, int new_thread)
    2.51 +                                  l4_cap_idx_t thread, int new_thread,
    2.52 +                                  int finalisation)
    2.53  {
    2.54    config->finaliser = resource_thread_finaliser;
    2.55    config->config_thread = new_thread;
    2.56    config->thread = thread;
    2.57 -  config->notifications = 1;
    2.58 +  config->notifications = finalisation;
    2.59  }
    2.60  
    2.61  /* Activate a resource and start a server for it. */