summaryrefslogtreecommitdiff
path: root/src/til_setup.h
AgeCommit message (Collapse)Author
2023-05-11til_setup: refcount til_setup_tVito Caputo
The whole point of til_setup_t is to represent the baked, most conveniently usable form of a setup derived from one or more settings instances. Things generally go from the serialization format "settings string" to til_settings_t eventually culminating in a til_setup_t. So the process of making a til_setup_t is rather tedious and kind of costly. Once into a til_setup_t it's desirable to just hang on to this form and reuse it if possible. The way a til_setup_t baked setup is put to use is in a read-only fashion where it basically just informs behavior, so it makes a lot of sense to enable refcounting the thing and letting whatever can make use of it bump the refcount and hold onto the pointer, accessing the contents whenever it needs to answer a question about that particular setup. The immediate impetus for this is actually rtv's snow_module setup. In rtv every channel switch may recreate the context, if the context has expired. In the case of the snow module, the context always expires, and we definitely want to discard the context while playing the next channel. But when the snow resumes, in order to recreate the context as configured, we need the same setup again. It just becomes clear that what's needed is a way to pin the snow_module's setup for this reuse to be safe. There's also plenty of other modules that have been piecemeal copying settings into their context, when what would really make more sense is to just ref it and stow the pointer, then unref on their context destroy. They can just access the setup via the pointer as needed, instead of having to duplicate the setup in their context. Indeed, some module contexts even embed the entire setup just to copy its contents over by value. In simple/small scenarios that's fine, and I'm sure in those particular cases it's perfectly safe to do. It just seems unnecessary altogether. Another small change made is supporting NULL free_func, which will default to libc's free(). Most til_setup_new() call sites are passing free() with an annoying cast, those can be changed to NULL.
2022-04-24til_setup: introduce til_setup_free()Vito Caputo
simple wrapper around til_setup_t.free()
2022-04-24til_setup: add til_setup_new() helperVito Caputo
For use when setup functions allocate their private setup to return in *res_setup. They specify the size of their private setup, and supply the free function to use. This may be libc's free() when it's a simple setup struct, or a bespoke free function when deep/complex freeing is required for cleanup. It's expected that callers will be embedding til_setup_t at the start of their private setup struct, and returning a pointer to this in *res_setup which would be the same value as a pointer to to their private setup struct.
2022-04-24til_setup: introduce til_setup_tVito Caputo
Preparatory commit for providing a res_setup type to replace void*. The impetus for this isn't just pursuit of less void*, but primarily implementing setup freeing by embedding this struct into the private setup types. An alternative method of adding setup freeing would have been to introduce something like til_module_t.free_setup(). But that would require having the til_module_t on hand, and the whole setup machinery is more generalized than til_module_t anyways. This way anything can simply embed the struct in their private setup instance and return the pointer to that in *res_setup. They should always be able to find their containing struct's offset from the til_setup_t* they returned. Either by using container_of(), or simply placing it at the start of the private setup struct.
© All Rights Reserved