1.1 --- a/libfsserver/lib/generic/resource_server.cc Fri Mar 03 18:15:38 2023 +0100
1.2 +++ b/libfsserver/lib/generic/resource_server.cc Fri Mar 03 19:29:33 2023 +0100
1.3 @@ -37,12 +37,20 @@
1.4 return ipc_server_bind(name, (l4_umword_t) _config, &_config->server);
1.5 }
1.6
1.7 -/* Start in the same thread with no deletion notifications or finalisation. */
1.8 +/* Start in the same thread indicating whether deletion notifications and
1.9 + finalisation are to be used. */
1.10
1.11 -long ResourceServer::start()
1.12 +long ResourceServer::start(bool finalisation)
1.13 {
1.14 resource_init_config(_config, _resource);
1.15 _config->thread = pthread_l4_cap(pthread_self());
1.16 +
1.17 + if (finalisation)
1.18 + {
1.19 + _config->finaliser = resource_same_thread_finaliser;
1.20 + _config->notifications = 1;
1.21 + }
1.22 +
1.23 return resource_start_config(_config, _resource);
1.24 }
1.25
1.26 @@ -126,7 +134,24 @@
1.27
1.28
1.29
1.30 -/* A finaliser for exposed resources. */
1.31 +/* A finaliser for exposed resources in the same thread. */
1.32 +
1.33 +void resource_same_thread_finaliser(ipc_server_config_type *config)
1.34 +{
1.35 + Resource *resource = reinterpret_cast<Resource *>(config->finaliser_obj);
1.36 +
1.37 + /* Close but do not delete the resource since it is assumed that it is being
1.38 + managed by the thread. */
1.39 +
1.40 + resource->close();
1.41 +
1.42 + /* Release the capabilities. */
1.43 +
1.44 + ipc_server_finalise_config(config);
1.45 + delete config;
1.46 +}
1.47 +
1.48 +/* A finaliser for exposed resources in a different thread. */
1.49
1.50 void resource_thread_finaliser(ipc_server_config_type *config)
1.51 {