Closures: add closure struct definition to closure_type() macro #2006
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
With this change, the closure_type() macro includes both a typedef statement and a struct definition; the struct can be used by any basic closure (i.e. a closure without any closure-specific fields in its struct) that uses the type.
This change makes it unnecessary to define a closure struct for each basic closure, and by reusing basic closure structs allows removing several declare_closure_struct() macro invocations. In order to be able to include both a typedef and a struct in the closure_type() macro, the different macros in the closure templates have been changed so that each function parameter in the signature of closure functions is written as
<type> <name>
(i.e. as a single macro argument) instead of<type>, <name>
(i.e. as 2 separate macro arguments).In order to support the different types of closure instantiations when using a basic closure, 2 new macros have been added: closure_func (for allocating basic closures from a heap) and stack_closure_func (for allocating basic closures on the stack). Various non-basic closures have been replaced with basic closures (embedded in other structs) in different parts of the kernel, which simplifies the code and minimizes the number of allocations and deallocations required when setting up and tearing down the larger structs.