From 69d78cd3f858748c0ee5ccd6ae1e77cfc063d57b Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Thu, 23 Nov 2023 09:56:56 +0100 Subject: [PATCH] move MEM_ROOT::read_only into flags --- include/my_alloc.h | 6 ++---- mysys/my_alloc.c | 9 ++------- sql/sp_head.cc | 6 +++--- sql/sql_prepare.cc | 8 ++++---- 4 files changed, 11 insertions(+), 18 deletions(-) diff --git a/include/my_alloc.h b/include/my_alloc.h index 6161f5cdb2a..8d7ebe013db 100644 --- a/include/my_alloc.h +++ b/include/my_alloc.h @@ -23,6 +23,8 @@ #define ALLOC_MAX_BLOCK_TO_DROP 4096 #define ALLOC_MAX_BLOCK_USAGE_BEFORE_DROP 10 +#define ROOT_FLAG_READ_ONLY 4 + #ifdef __cplusplus extern "C" { #endif @@ -52,10 +54,6 @@ typedef struct st_mem_root unsigned short first_block_usage; unsigned short flags; -#ifdef PROTECT_STATEMENT_MEMROOT - int read_only; -#endif - void (*error_handler)(void); const char *name; } MEM_ROOT; diff --git a/mysys/my_alloc.c b/mysys/my_alloc.c index 493fb92aa52..beda4d50480 100644 --- a/mysys/my_alloc.c +++ b/mysys/my_alloc.c @@ -24,6 +24,7 @@ #define EXTRA_DEBUG #define ROOT_FLAG_THREAD_SPECIFIC 1 +#define ROOT_FLAG_READ_ONLY 4 /* data packed in MEM_ROOT -> min_malloc */ @@ -74,9 +75,6 @@ void init_alloc_root(MEM_ROOT *mem_root, const char *name, size_t block_size, mem_root->first_block_usage= 0; mem_root->total_alloc= 0; mem_root->name= name; -#ifdef PROTECT_STATEMENT_MEMROOT - mem_root->read_only= 0; -#endif #if !(defined(HAVE_valgrind) && defined(EXTRA_DEBUG)) if (pre_alloc_size) @@ -218,10 +216,7 @@ void *alloc_root(MEM_ROOT *mem_root, size_t length) DBUG_ENTER("alloc_root"); DBUG_PRINT("enter",("root: %p name: %s", mem_root, mem_root->name)); DBUG_ASSERT(alloc_root_inited(mem_root)); - -#ifdef PROTECT_STATEMENT_MEMROOT - DBUG_ASSERT(mem_root->read_only == 0); -#endif + DBUG_ASSERT((mem_root->flags & ROOT_FLAG_READ_ONLY) == 0); DBUG_EXECUTE_IF("simulate_out_of_memory", { diff --git a/sql/sp_head.cc b/sql/sp_head.cc index b1a697ada2a..312d779b05a 100644 --- a/sql/sp_head.cc +++ b/sql/sp_head.cc @@ -1477,7 +1477,7 @@ sp_head::execute(THD *thd, bool merge_da_on_success) { // Don't count a call ended with an error as normal run executed_counter= 0; - main_mem_root.read_only= 0; + main_mem_root.flags &= ~ROOT_FLAG_READ_ONLY; reset_instrs_executed_counter(); } #endif @@ -1597,10 +1597,10 @@ sp_head::execute(THD *thd, bool merge_da_on_success) #ifdef PROTECT_STATEMENT_MEMROOT if (!err_status) { - if (!main_mem_root.read_only && + if (!(main_mem_root.flags & ROOT_FLAG_READ_ONLY) && has_all_instrs_executed()) { - main_mem_root.read_only= 1; + main_mem_root.flags |= ROOT_FLAG_READ_ONLY; } ++executed_counter; DBUG_PRINT("info", ("execute counter: %lu", executed_counter)); diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index 5a2c39b160d..47de393e795 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -176,7 +176,7 @@ public: /* The following data member is wholly for debugging purpose. It can be used for possible crash analysis to determine how many times - the stored routine was executed before the mem_root marked read_only + the stored routine was executed before the mem_root marked ROOT_FLAG_READ_ONLY was requested for a memory chunk. Additionally, a value of this data member is output to the log with DBUG_PRINT. */ @@ -4489,7 +4489,7 @@ reexecute: #ifdef PROTECT_STATEMENT_MEMROOT // There was reprepare so the counter of runs should be reset executed_counter= 0; - mem_root->read_only= 0; + mem_root->flags &= ~ROOT_FLAG_READ_ONLY; #endif goto reexecute; } @@ -4498,7 +4498,7 @@ reexecute: #ifdef PROTECT_STATEMENT_MEMROOT if (!error) { - mem_root->read_only= 1; + mem_root->flags |= ROOT_FLAG_READ_ONLY; ++executed_counter; DBUG_PRINT("info", ("execute counter: %lu", executed_counter)); @@ -4507,7 +4507,7 @@ reexecute: { // Error on call shouldn't be counted as a normal run executed_counter= 0; - mem_root->read_only= 0; + mem_root->flags &= ~ROOT_FLAG_READ_ONLY; } #endif