# HG changeset patch # User Paul Boddie # Date 1647383910 -3600 # Node ID 758a64edfae70264b56dfbe60cac1f23a0886635 # Parent 3aef1b268d2c76974dbaa431d3c252a6ebde1768 Renamed new_thread to config_thread and added support for associating more components with an existing server. diff -r 3aef1b268d2c -r 758a64edfae7 libfsserver/lib/generic/resource_server.cc --- a/libfsserver/lib/generic/resource_server.cc Tue Mar 15 17:36:39 2022 +0100 +++ b/libfsserver/lib/generic/resource_server.cc Tue Mar 15 23:38:30 2022 +0100 @@ -99,7 +99,7 @@ l4_cap_idx_t thread, int new_thread) { config->finaliser = resource_thread_finaliser; - config->new_thread = new_thread; + config->config_thread = new_thread; config->thread = thread; config->notifications = 1; } diff -r 3aef1b268d2c -r 758a64edfae7 libipc/include/ipc/server.h --- a/libipc/include/ipc/server.h Tue Mar 15 17:36:39 2022 +0100 +++ b/libipc/include/ipc/server.h Tue Mar 15 23:38:30 2022 +0100 @@ -34,6 +34,13 @@ (ipc_server_handler_type) handle_##TYPE, \ NAME) +/* A convenience macro for adding a configuration to an existing server. */ + +#define ipc_server_add_config(CONFIG, TYPE, POINTER, THREAD) \ + _ipc_server_add_config(CONFIG, TYPE##_expected_items, (TYPE *) POINTER, \ + (ipc_server_handler_type) handle_##TYPE, \ + THREAD) + /* A handler function type. */ typedef void (*ipc_server_handler_type)(ipc_message_t *, void *); @@ -64,9 +71,9 @@ ipc_server_handler_type handler; ipc_server_finaliser_type finaliser; - /* Create a new thread. */ + /* Configure a thread instead of using the current thread. */ - int new_thread; + int config_thread; /* Thread and IPC capabilities. */ @@ -117,6 +124,12 @@ long _ipc_server_loop_for(int expected_items, void *handler_obj, ipc_server_handler_type handler, const char *name); +/* Add handling of incoming messages to an existing server. */ + +long _ipc_server_add_config(ipc_server_config_type *config, int expected_items, + void *handler_obj, ipc_server_handler_type handler, + l4_cap_idx_t thread); + /* Handle incoming messages and IRQ notifications for a server. */ long ipc_server_managed_loop(int expected_items, ipc_server_config_type *config); @@ -148,3 +161,6 @@ long ipc_server_start_config(ipc_server_config_type *config); EXTERN_C_END + +/* vim: tabstop=2 expandtab shiftwidth=2 +*/ diff -r 3aef1b268d2c -r 758a64edfae7 libipc/lib/src/server.c --- a/libipc/lib/src/server.c Tue Mar 15 17:36:39 2022 +0100 +++ b/libipc/lib/src/server.c Tue Mar 15 23:38:30 2022 +0100 @@ -1,7 +1,7 @@ /* * Server binding/registration. * - * Copyright (C) 2018, 2019, 2020, 2021 Paul Boddie + * Copyright (C) 2018, 2019, 2020, 2021, 2022 Paul Boddie * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -174,6 +174,24 @@ return ipc_server_start_config(&config); } +/* Associate a new configuration with an existing server endpoint. */ + +long _ipc_server_add_config(ipc_server_config_type *config, int expected_items, + void *handler_obj, ipc_server_handler_type handler, + l4_cap_idx_t thread) +{ + ipc_server_init_config(config); + config->expected_items = expected_items; + config->handler = handler; + config->handler_obj = handler_obj; + config->thread = thread; + config->config_thread = 1; + + return ipc_server_start_config(config); +} + + + /* A server main loop handling endpoint deletion for an IPC gate dedicated to a particular object within its own thread. */ @@ -283,11 +301,11 @@ } } -/* Discard any thread created but not initiated. */ +/* Discard any uninitiated thread. */ void ipc_server_discard_thread(ipc_server_config_type *config) { - if (config->new_thread && l4_is_valid_cap(config->thread)) + if (config->config_thread && l4_is_valid_cap(config->thread)) { ipc_cap_free_um(config->thread); config->thread = L4_INVALID_CAP; @@ -312,9 +330,9 @@ config->handler = NULL; config->finaliser = NULL; - /* No new thread for the mainloop. */ + /* No separate thread for the main loop. */ - config->new_thread = 0; + config->config_thread = 0; /* Main thread by default with IPC gate to be allocated. */ @@ -353,11 +371,14 @@ return err; } - /* With a new thread, return the last status value. Otherwise, invoke the main - loop. */ + /* With a separate thread, return the last status value. Otherwise, invoke the + main loop. */ - if (config->new_thread) + if (config->config_thread) return L4_EOK; else return (long) ipc_server_start_mainloop(config); } + +/* vim: tabstop=2 expandtab shiftwidth=2 +*/