~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/innobase/mem/mem0pool.c

  • Committer: Brian Aker
  • Date: 2010-10-06 18:16:00 UTC
  • mto: (1818.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 1819.
  • Revision ID: brian@tangent.org-20101006181600-q7zuzw31zlq030ra
Convert sql_string to use size_t (this should clean up ICC warnings).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*****************************************************************************
2
2
 
3
 
Copyright (C) 1997, 2009, Innobase Oy. All Rights Reserved.
 
3
Copyright (c) 1997, 2009, Innobase Oy. All Rights Reserved.
4
4
 
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
34
34
#include "ut0lst.h"
35
35
#include "ut0byte.h"
36
36
#include "mem0mem.h"
37
 
#include "srv0start.h"
38
37
 
39
38
/* We would like to use also the buffer frames to allocate memory. This
40
39
would be desirable, because then the memory consumption of the database
115
114
/** The common memory pool */
116
115
UNIV_INTERN mem_pool_t* mem_comm_pool   = NULL;
117
116
 
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 */
122
 
 
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;
128
122
 
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. */
133
 
UNIV_INLINE
 
124
Reserves the mem pool mutex. */
 
125
UNIV_INTERN
134
126
void
135
 
mem_pool_mutex_enter(
136
 
/*=================*/
137
 
        mem_pool_t*     pool)           /*!< in: memory pool */
 
127
mem_pool_mutex_enter(void)
 
128
/*======================*/
138
129
{
139
 
        if (srv_shutdown_state < SRV_SHUTDOWN_EXIT_THREADS) {
140
 
                mutex_enter(&(pool->mutex));
141
 
        }
 
130
        mutex_enter(&(mem_comm_pool->mutex));
142
131
}
143
132
 
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 */
148
 
UNIV_INLINE
 
134
Releases the mem pool mutex. */
 
135
UNIV_INTERN
149
136
void
150
 
mem_pool_mutex_exit(
151
 
/*================*/
152
 
        mem_pool_t*     pool)           /*!< in: memory pool */
 
137
mem_pool_mutex_exit(void)
 
138
/*=====================*/
153
139
{
154
 
        if (srv_shutdown_state < SRV_SHUTDOWN_EXIT_THREADS) {
155
 
                mutex_exit(&(pool->mutex));
156
 
        }
 
140
        mutex_exit(&(mem_comm_pool->mutex));
157
141
}
158
142
 
159
143
/********************************************************************//**
226
210
        ulint           i;
227
211
        ulint           used;
228
212
 
229
 
        pool = static_cast<mem_pool_t *>(ut_malloc(sizeof(mem_pool_t)));
 
213
        pool = ut_malloc(sizeof(mem_pool_t));
230
214
 
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. */
234
218
 
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;
237
221
 
238
 
        mutex_create(mem_pool_mutex_key, &pool->mutex, SYNC_MEM_POOL);
 
222
        mutex_create(&pool->mutex, SYNC_MEM_POOL);
239
223
 
240
224
        /* Initialize the free lists */
241
225
 
277
261
}
278
262
 
279
263
/********************************************************************//**
280
 
Frees a memory pool. */
281
 
UNIV_INTERN
282
 
void
283
 
mem_pool_free(
284
 
/*==========*/
285
 
        mem_pool_t*     pool)   /*!< in, own: memory pool */
286
 
{
287
 
        ut_free(pool->buf);
288
 
        ut_free(pool);
289
 
}
290
 
 
291
 
/********************************************************************//**
292
264
Fills the specified free list.
293
265
@return TRUE if we were able to insert a block to the free list */
294
266
static
583
555
 
584
556
        n = ut_2_log(size);
585
557
 
586
 
        mem_pool_mutex_enter(pool);
 
558
        mutex_enter(&(pool->mutex));
587
559
        mem_n_threads_inside++;
588
560
 
589
561
        ut_a(mem_n_threads_inside == 1);
611
583
                pool->reserved += ut_2_exp(n);
612
584
 
613
585
                mem_n_threads_inside--;
614
 
                mem_pool_mutex_exit(pool);
 
586
                mutex_exit(&(pool->mutex));
615
587
 
616
588
                mem_area_free(new_ptr, pool);
617
589
 
627
599
        }
628
600
 
629
601
        mem_n_threads_inside--;
630
 
        mem_pool_mutex_exit(pool);
 
602
        mutex_exit(&(pool->mutex));
631
603
 
632
604
        ut_ad(mem_pool_validate(pool));
633
605
}
646
618
        ulint           free;
647
619
        ulint           i;
648
620
 
649
 
        mem_pool_mutex_enter(pool);
 
621
        mutex_enter(&(pool->mutex));
650
622
 
651
623
        free = 0;
652
624
 
674
646
 
675
647
        ut_a(free + pool->reserved == pool->size);
676
648
 
677
 
        mem_pool_mutex_exit(pool);
 
649
        mutex_exit(&(pool->mutex));
678
650
 
679
651
        return(TRUE);
680
652
}