~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/innobase/thr/thr0loc.c

  • Committer: Barry.Leslie at PrimeBase
  • Date: 2010-10-20 20:41:00 UTC
  • mfrom: (1863 staging)
  • mto: This revision was merged to the branch mainline in revision 1871.
  • Revision ID: barry.leslie@primebase.com-20101020204100-oyj6p5cfssjw3p62
Merged with trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*****************************************************************************
2
2
 
3
 
Copyright (C) 1995, 2009, Innobase Oy. All Rights Reserved.
 
3
Copyright (c) 1995, 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
53
53
/** Thread local data */
54
54
typedef struct thr_local_struct thr_local_t;
55
55
 
56
 
#ifdef UNIV_PFS_MUTEX
57
 
/* Key to register the mutex with performance schema */
58
 
UNIV_INTERN mysql_pfs_key_t     thr_local_mutex_key;
59
 
#endif /* UNIV_PFS_MUTEX */
60
 
 
61
56
/** @brief Thread local data.
62
57
The private data for each thread should be put to
63
58
the structure below and the accessor functions written
76
71
/** The value of thr_local_struct::magic_n */
77
72
#define THR_LOCAL_MAGIC_N       1231234
78
73
 
79
 
#ifdef UNIV_DEBUG
80
 
/*******************************************************************//**
81
 
Validates thread local data.
82
 
@return TRUE if valid */
83
 
static
84
 
ibool
85
 
thr_local_validate(
86
 
/*===============*/
87
 
        const thr_local_t*      local)  /*!< in: data to validate */
88
 
{
89
 
        ut_ad(local->magic_n == THR_LOCAL_MAGIC_N);
90
 
        ut_ad(local->slot_no == ULINT_UNDEFINED
91
 
              || local->slot_no < OS_THREAD_MAX_N);
92
 
        ut_ad(local->in_ibuf == FALSE || local->in_ibuf == TRUE);
93
 
        return(TRUE);
94
 
}
95
 
#endif /* UNIV_DEBUG */
96
 
 
97
74
/*******************************************************************//**
98
75
Returns the local storage struct for a thread.
99
76
@return local storage */
114
91
        local = NULL;
115
92
 
116
93
        HASH_SEARCH(hash, thr_local_hash, os_thread_pf(id),
117
 
                    thr_local_t*, local, ut_ad(thr_local_validate(local)),
118
 
                    os_thread_eq(local->id, id));
 
94
                    thr_local_t*, local,, os_thread_eq(local->id, id));
119
95
        if (local == NULL) {
120
96
                mutex_exit(&thr_local_mutex);
121
97
 
126
102
                goto try_again;
127
103
        }
128
104
 
129
 
        ut_ad(thr_local_validate(local));
 
105
        ut_ad(local->magic_n == THR_LOCAL_MAGIC_N);
130
106
 
131
107
        return(local);
132
108
}
207
183
                thr_local_init();
208
184
        }
209
185
 
210
 
        local = static_cast<thr_local_t *>(mem_alloc(sizeof(thr_local_t)));
 
186
        local = mem_alloc(sizeof(thr_local_t));
211
187
 
212
188
        local->id = os_thread_get_curr_id();
213
189
        local->handle = os_thread_get_curr();
214
190
        local->magic_n = THR_LOCAL_MAGIC_N;
215
 
        local->slot_no = ULINT_UNDEFINED;
 
191
 
216
192
        local->in_ibuf = FALSE;
217
193
 
218
194
        mutex_enter(&thr_local_mutex);
239
215
        /* Look for the local struct in the hash table */
240
216
 
241
217
        HASH_SEARCH(hash, thr_local_hash, os_thread_pf(id),
242
 
                    thr_local_t*, local, ut_ad(thr_local_validate(local)),
243
 
                    os_thread_eq(local->id, id));
 
218
                    thr_local_t*, local,, os_thread_eq(local->id, id));
244
219
        if (local == NULL) {
245
220
                mutex_exit(&thr_local_mutex);
246
221
 
253
228
        mutex_exit(&thr_local_mutex);
254
229
 
255
230
        ut_a(local->magic_n == THR_LOCAL_MAGIC_N);
256
 
        ut_ad(thr_local_validate(local));
257
231
 
258
232
        mem_free(local);
259
233
}
270
244
 
271
245
        thr_local_hash = hash_create(OS_THREAD_MAX_N + 100);
272
246
 
273
 
        mutex_create(thr_local_mutex_key,
274
 
                     &thr_local_mutex, SYNC_THR_LOCAL);
 
247
        mutex_create(&thr_local_mutex, SYNC_THR_LOCAL);
275
248
}
276
249
 
277
250
/********************************************************************
290
263
        for (i = 0; i < hash_get_n_cells(thr_local_hash); i++) {
291
264
                thr_local_t*    local;
292
265
 
293
 
                local = static_cast<thr_local_t *>(HASH_GET_FIRST(thr_local_hash, i));
 
266
                local = HASH_GET_FIRST(thr_local_hash, i);
294
267
 
295
268
                while (local) {
296
269
                        thr_local_t*    prev_local = local;
297
270
 
298
 
                        local = static_cast<thr_local_t *>(HASH_GET_NEXT(hash, prev_local));
 
271
                        local = HASH_GET_NEXT(hash, prev_local);
299
272
                        ut_a(prev_local->magic_n == THR_LOCAL_MAGIC_N);
300
 
                        ut_ad(thr_local_validate(prev_local));
301
273
                        mem_free(prev_local);
302
274
                }
303
275
        }