1.1 --- a/libfsserver/lib/generic/resource_server.cc Tue Mar 15 17:36:39 2022 +0100
1.2 +++ b/libfsserver/lib/generic/resource_server.cc Tue Mar 15 23:38:30 2022 +0100
1.3 @@ -99,7 +99,7 @@
1.4 l4_cap_idx_t thread, int new_thread)
1.5 {
1.6 config->finaliser = resource_thread_finaliser;
1.7 - config->new_thread = new_thread;
1.8 + config->config_thread = new_thread;
1.9 config->thread = thread;
1.10 config->notifications = 1;
1.11 }
2.1 --- a/libipc/include/ipc/server.h Tue Mar 15 17:36:39 2022 +0100
2.2 +++ b/libipc/include/ipc/server.h Tue Mar 15 23:38:30 2022 +0100
2.3 @@ -34,6 +34,13 @@
2.4 (ipc_server_handler_type) handle_##TYPE, \
2.5 NAME)
2.6
2.7 +/* A convenience macro for adding a configuration to an existing server. */
2.8 +
2.9 +#define ipc_server_add_config(CONFIG, TYPE, POINTER, THREAD) \
2.10 + _ipc_server_add_config(CONFIG, TYPE##_expected_items, (TYPE *) POINTER, \
2.11 + (ipc_server_handler_type) handle_##TYPE, \
2.12 + THREAD)
2.13 +
2.14 /* A handler function type. */
2.15
2.16 typedef void (*ipc_server_handler_type)(ipc_message_t *, void *);
2.17 @@ -64,9 +71,9 @@
2.18 ipc_server_handler_type handler;
2.19 ipc_server_finaliser_type finaliser;
2.20
2.21 - /* Create a new thread. */
2.22 + /* Configure a thread instead of using the current thread. */
2.23
2.24 - int new_thread;
2.25 + int config_thread;
2.26
2.27 /* Thread and IPC capabilities. */
2.28
2.29 @@ -117,6 +124,12 @@
2.30 long _ipc_server_loop_for(int expected_items, void *handler_obj,
2.31 ipc_server_handler_type handler, const char *name);
2.32
2.33 +/* Add handling of incoming messages to an existing server. */
2.34 +
2.35 +long _ipc_server_add_config(ipc_server_config_type *config, int expected_items,
2.36 + void *handler_obj, ipc_server_handler_type handler,
2.37 + l4_cap_idx_t thread);
2.38 +
2.39 /* Handle incoming messages and IRQ notifications for a server. */
2.40
2.41 long ipc_server_managed_loop(int expected_items, ipc_server_config_type *config);
2.42 @@ -148,3 +161,6 @@
2.43 long ipc_server_start_config(ipc_server_config_type *config);
2.44
2.45 EXTERN_C_END
2.46 +
2.47 +/* vim: tabstop=2 expandtab shiftwidth=2
2.48 +*/
3.1 --- a/libipc/lib/src/server.c Tue Mar 15 17:36:39 2022 +0100
3.2 +++ b/libipc/lib/src/server.c Tue Mar 15 23:38:30 2022 +0100
3.3 @@ -1,7 +1,7 @@
3.4 /*
3.5 * Server binding/registration.
3.6 *
3.7 - * Copyright (C) 2018, 2019, 2020, 2021 Paul Boddie <paul@boddie.org.uk>
3.8 + * Copyright (C) 2018, 2019, 2020, 2021, 2022 Paul Boddie <paul@boddie.org.uk>
3.9 *
3.10 * This program is free software; you can redistribute it and/or
3.11 * modify it under the terms of the GNU General Public License as
3.12 @@ -174,6 +174,24 @@
3.13 return ipc_server_start_config(&config);
3.14 }
3.15
3.16 +/* Associate a new configuration with an existing server endpoint. */
3.17 +
3.18 +long _ipc_server_add_config(ipc_server_config_type *config, int expected_items,
3.19 + void *handler_obj, ipc_server_handler_type handler,
3.20 + l4_cap_idx_t thread)
3.21 +{
3.22 + ipc_server_init_config(config);
3.23 + config->expected_items = expected_items;
3.24 + config->handler = handler;
3.25 + config->handler_obj = handler_obj;
3.26 + config->thread = thread;
3.27 + config->config_thread = 1;
3.28 +
3.29 + return ipc_server_start_config(config);
3.30 +}
3.31 +
3.32 +
3.33 +
3.34 /* A server main loop handling endpoint deletion for an IPC gate dedicated to
3.35 a particular object within its own thread. */
3.36
3.37 @@ -283,11 +301,11 @@
3.38 }
3.39 }
3.40
3.41 -/* Discard any thread created but not initiated. */
3.42 +/* Discard any uninitiated thread. */
3.43
3.44 void ipc_server_discard_thread(ipc_server_config_type *config)
3.45 {
3.46 - if (config->new_thread && l4_is_valid_cap(config->thread))
3.47 + if (config->config_thread && l4_is_valid_cap(config->thread))
3.48 {
3.49 ipc_cap_free_um(config->thread);
3.50 config->thread = L4_INVALID_CAP;
3.51 @@ -312,9 +330,9 @@
3.52 config->handler = NULL;
3.53 config->finaliser = NULL;
3.54
3.55 - /* No new thread for the mainloop. */
3.56 + /* No separate thread for the main loop. */
3.57
3.58 - config->new_thread = 0;
3.59 + config->config_thread = 0;
3.60
3.61 /* Main thread by default with IPC gate to be allocated. */
3.62
3.63 @@ -353,11 +371,14 @@
3.64 return err;
3.65 }
3.66
3.67 - /* With a new thread, return the last status value. Otherwise, invoke the main
3.68 - loop. */
3.69 + /* With a separate thread, return the last status value. Otherwise, invoke the
3.70 + main loop. */
3.71
3.72 - if (config->new_thread)
3.73 + if (config->config_thread)
3.74 return L4_EOK;
3.75 else
3.76 return (long) ipc_server_start_mainloop(config);
3.77 }
3.78 +
3.79 +/* vim: tabstop=2 expandtab shiftwidth=2
3.80 +*/