]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add support for allocating frame state pools
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 26 Sep 2019 23:04:08 +0000 (18:04 -0500)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 26 Sep 2019 23:04:08 +0000 (18:04 -0500)
src/lib/unlang/interpret.c
src/lib/unlang/interpret.h

index de13eb2846ef5ddb26a4267516479e08b040b0c8..479366c2db71ae04dac1a314a23c539fa7a26014 100644 (file)
@@ -215,10 +215,10 @@ uint64_t unlang_interpret_active_callers(unlang_t *instruction)
        return active_callers;
 }
 
-static inline void frame_setup(unlang_stack_t *stack, unlang_stack_frame_t *frame)
+static inline void frame_state_init(unlang_stack_t *stack, unlang_stack_frame_t *frame)
 {
-       unlang_t *instruction = frame->instruction;
-       unlang_op_t *op;
+       unlang_t        *instruction = frame->instruction;
+       unlang_op_t     *op;
 
        op = &unlang_ops[instruction->type];
 
@@ -229,8 +229,19 @@ static inline void frame_setup(unlang_stack_t *stack, unlang_stack_frame_t *fram
         *      The frame needs to track state.  Do so here.
         */
        if (op->frame_state_size) {
-               MEM(frame->state = talloc_zero_array(stack, uint8_t, op->frame_state_size));
-               talloc_set_name_const(frame->state, op->frame_state_name);
+               char const *name = op->frame_state_name ? op->frame_state_name : __location__;
+
+#ifdef HAVE_TALLOC_ZERO_POOLED_OBJECT
+               if (op->frame_state_pool_size) {
+                       MEM(frame->state = _talloc_zero_pooled_object(stack,
+                                                                     op->frame_state_size, name,
+                                                                     op->frame_state_pool_objects,
+                                                                     op->frame_state_pool_size));
+               }
+#endif
+               else {
+                       MEM(frame->state = _talloc_zero(stack, op->frame_state_size, name));
+               }
        }
 }
 
@@ -288,7 +299,7 @@ void unlang_interpret_push(REQUEST *request, unlang_t *instruction,
 
        if (!instruction) return;
 
-       frame_setup(stack, frame);
+       frame_state_init(stack, frame);
 }
 
 /** Update the current result after each instruction, and after popping each stack frame
@@ -442,7 +453,7 @@ static inline void frame_next(unlang_stack_t *stack, unlang_stack_frame_t *frame
 
        frame->next = frame->instruction->next;
 
-       frame_setup(stack, frame);
+       frame_state_init(stack, frame);
 }
 
 /** Pop a stack frame, removing any associated dynamically allocated state
index 1a5055506d91c07d398ed54941215d0b65a188f8..1d7ea26737786c24e2b3f6fd02ba2716a9b4e441 100644 (file)
@@ -93,9 +93,13 @@ typedef struct {
        bool                    debug_braces;                   //!< Whether the operation needs to print braces
                                                                ///< in debug mode.
 
-       size_t                  frame_state_size;                       //!< size of instance data in the stack frame
+       size_t                  frame_state_size;               //!< size of instance data in the stack frame
 
        char const              *frame_state_name;              //!< talloc name of the frame instance data
+
+       size_t                  frame_state_pool_objects;       //!< How many sub-allocations we expect.
+
+       size_t                  frame_state_pool_size;          //!< The total size of the pool to alloc.
 } unlang_op_t;
 
 void           unlang_interpret_push_function(REQUEST *request,