1
1
/*****************************************************************************
3
Copyright (C) 1997, 2009, Innobase Oy. All Rights Reserved.
3
Copyright (c) 1997, 2009, Innobase Oy. All Rights Reserved.
5
5
This program is free software; you can redistribute it and/or modify it under
6
6
the terms of the GNU General Public License as published by the Free Software
115
114
/** The common memory pool */
116
115
UNIV_INTERN mem_pool_t* mem_comm_pool = NULL;
118
#ifdef UNIV_PFS_MUTEX
119
/* Key to register mutex in mem_pool_struct with performance schema */
120
UNIV_INTERN mysql_pfs_key_t mem_pool_mutex_key;
121
#endif /* UNIV_PFS_MUTEX */
123
117
/* We use this counter to check that the mem pool mutex does not leak;
124
118
this is to track a strange assertion failure reported at
125
119
mysql@lists.mysql.com */
127
121
UNIV_INTERN ulint mem_n_threads_inside = 0;
129
123
/********************************************************************//**
130
Reserves the mem pool mutex if we are not in server shutdown. Use
131
this function only in memory free functions, since only memory
132
free functions are used during server shutdown. */
124
Reserves the mem pool mutex. */
135
mem_pool_mutex_enter(
136
/*=================*/
137
mem_pool_t* pool) /*!< in: memory pool */
127
mem_pool_mutex_enter(void)
128
/*======================*/
139
if (srv_shutdown_state < SRV_SHUTDOWN_EXIT_THREADS) {
140
mutex_enter(&(pool->mutex));
130
mutex_enter(&(mem_comm_pool->mutex));
144
133
/********************************************************************//**
145
Releases the mem pool mutex if we are not in server shutdown. As
146
its corresponding mem_pool_mutex_enter() function, use it only
147
in memory free functions */
134
Releases the mem pool mutex. */
152
mem_pool_t* pool) /*!< in: memory pool */
137
mem_pool_mutex_exit(void)
138
/*=====================*/
154
if (srv_shutdown_state < SRV_SHUTDOWN_EXIT_THREADS) {
155
mutex_exit(&(pool->mutex));
140
mutex_exit(&(mem_comm_pool->mutex));
159
143
/********************************************************************//**
229
pool = static_cast<mem_pool_t *>(ut_malloc(sizeof(mem_pool_t)));
213
pool = ut_malloc(sizeof(mem_pool_t));
231
215
/* We do not set the memory to zero (FALSE) in the pool,
232
216
but only when allocated at a higher level in mem0mem.c.
233
217
This is to avoid masking useful Purify warnings. */
235
pool->buf = static_cast<unsigned char *>(ut_malloc_low(size, FALSE, TRUE));
219
pool->buf = ut_malloc_low(size, FALSE, TRUE);
236
220
pool->size = size;
238
mutex_create(mem_pool_mutex_key, &pool->mutex, SYNC_MEM_POOL);
222
mutex_create(&pool->mutex, SYNC_MEM_POOL);
240
224
/* Initialize the free lists */
611
595
pool->reserved += ut_2_exp(n);
613
597
mem_n_threads_inside--;
614
mem_pool_mutex_exit(pool);
598
mutex_exit(&(pool->mutex));
616
600
mem_area_free(new_ptr, pool);