~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Marisa Plumb
  • Date: 2010-12-04 02:38:29 UTC
  • mto: This revision was merged to the branch mainline in revision 1984.
  • Revision ID: marisa.plumb@gmail.com-20101204023829-2khzxh30wxi256db
updates to a few sql docs 

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
 
583
567
 
584
568
        n = ut_2_log(size);
585
569
 
586
 
        mem_pool_mutex_enter(pool);
 
570
        mutex_enter(&(pool->mutex));
587
571
        mem_n_threads_inside++;
588
572
 
589
573
        ut_a(mem_n_threads_inside == 1);
611
595
                pool->reserved += ut_2_exp(n);
612
596
 
613
597
                mem_n_threads_inside--;
614
 
                mem_pool_mutex_exit(pool);
 
598
                mutex_exit(&(pool->mutex));
615
599
 
616
600
                mem_area_free(new_ptr, pool);
617
601
 
627
611
        }
628
612
 
629
613
        mem_n_threads_inside--;
630
 
        mem_pool_mutex_exit(pool);
 
614
        mutex_exit(&(pool->mutex));
631
615
 
632
616
        ut_ad(mem_pool_validate(pool));
633
617
}
646
630
        ulint           free;
647
631
        ulint           i;
648
632
 
649
 
        mem_pool_mutex_enter(pool);
 
633
        mutex_enter(&(pool->mutex));
650
634
 
651
635
        free = 0;
652
636
 
674
658
 
675
659
        ut_a(free + pool->reserved == pool->size);
676
660
 
677
 
        mem_pool_mutex_exit(pool);
 
661
        mutex_exit(&(pool->mutex));
678
662
 
679
663
        return(TRUE);
680
664
}