3350 Marko Mäkelä 2011-03-22
Bug#11766305 - 59392: Remove thr0loc.c and ibuf_inside() [part 3]
Remove the slot_no member of struct thr_local_struct.
enum srv_thread_type: Remove unused thread types.
srv_get_thread_type(): Unused function, remove.
thr_local_get_slot_no(), thr_local_set_slot_no(): Remove.
srv_thread_type_validate(), srv_slot_get_type(): New functions, for debugging.
srv_table_reserve_slot(): Return the srv_slot_t* directly. Do not create
thread-local storage.
srv_suspend_thread(): Get the srv_slot_t* as parameter. Return void;
the caller knows slot->event already.
srv_thread_has_reserved_slot(), srv_release_threads(): Assert
srv_thread_type_validate(type).
srv_init(): Use mem_zalloc() instead of mem_alloc(). Replace
srv_table_get_nth_slot(), because it now asserts that the kernel_mutex
is being held.
srv_master_thread(), srv_purge_thread(): Remember the slot from
srv_table_reserve_slot().
rb:629 approved by Inaam Rana
modified:
storage/innobase/include/srv0srv.h
storage/innobase/include/thr0loc.h
storage/innobase/srv/srv0srv.c
storage/innobase/thr/thr0loc.c
3349 Marko Mäkel and ibuf_inside() [part 2]
Add some const qualifiers to accessor and validator functions.
btr_pcur_get_up_match(), btr_pcur_get_low_match(): Add const qualifiers.
btr_pcur_get_page(), btr_pcur_get_block(), btr_pcur_get_rec(),
rec_get_start(), rec_get_end(): Define as constness-preserving macros.
In debug builds, discard the const qualifier.
page_rec_validate(), page_simple_validate_old(), page_simple_validate_new(),
page_dir_slot_check(), page_validate(): Add const qualifiers.
rb:626 approved by Sunny Bains
modified:
storage/innobase/include/btr0pcur.h
storage/innobase/include/btr0pcur.ic
storage/innobase/include/page0page.h
storage/innobase/include/rem0rec.h
storage/innobase/include/rem0rec.ic
storage/innobase/page/page0page.c
3348 Marko Mäkelä 2011-03-21
Bug#11766305 - 59392: Remove thr0loc.c and ibuf_inside() [part 1]
Remove unused member mtr from btr_pcur_struct.
rb:624 approved by Sunny Bains
modified:
storage/innobase/include/btr0pcur.h
storage/innobase/include/btr0pcur.ic
3347 Marko Mäkelä 2011-03-15
Remove trailing white space.
modified:
storage/innobase/buf/buf0buf.c
=== modified file 'storage/innobase/include/btr0pcur.h'
--- a/storage/innobase/include/btr0pcur.h revid:marko.makela@strippedtq5gce4947
+++ b/storage/innobase/include/btr0pcur.h revid:marko.makela@stripped
@@ -150,7 +150,7 @@ UNIV_INLINE
ulint
btr_pcur_get_up_match(
/*==================*/
- btr_pcur_t* cursor); /*!< in: memory buffer for persistent cursor */
+ const btr_pcur_t* cursor); /*!< in: persistent cursor */
/**************************************************************//**
Gets the low_match value for a pcur after a search.
@return number of matched fields at the cursor or to the right if
@@ -159,7 +159,7 @@ UNIV_INLINE
ulint
btr_pcur_get_low_match(
/*===================*/
- btr_pcur_t* cursor); /*!< in: memory buffer for persistent cursor */
+ const btr_pcur_t* cursor); /*!< in: persistent cursor */
/**************************************************************//**
If mode is PAGE_CUR_G or PAGE_CUR_GE, opens a persistent cursor on the first
user record satisfying the search condition, in the case PAGE_CUR_L or
@@ -264,22 +264,6 @@ ulint
btr_pcur_get_rel_pos(
/*=================*/
const btr_pcur_t* cursor);/*!< in: persistent cursor */
-/*********************************************************//**
-Sets the mtr field for a pcur. */
-UNIV_INLINE
-void
-btr_pcur_set_mtr(
-/*=============*/
- btr_pcur_t* cursor, /*!< in: persistent cursor */
- mtr_t* mtr); /*!< in, own: mtr */
-/*********************************************************//**
-Gets the mtr field for a pcur.
-@return mtr */
-UNIV_INLINE
-mtr_t*
-btr_pcur_get_mtr(
-/*=============*/
- btr_pcur_t* cursor); /*!< in: persistent cursor */
/**************************************************************//**
Commits the mtr and sets the pcur latch mode to BTR_NO_LATCHES,
that is, the cursor becomes detached. If there have been modifications
@@ -387,10 +371,6 @@ page_cur_t*
btr_pcur_get_page_cur(
/*==================*/
const btr_pcur_t* cursor); /*!< in: persistent cursor */
-#else /* UNIV_DEBUG */
-# define btr_pcur_get_btr_cur(cursor) (&(cursor)->btr_cur)
-# define btr_pcur_get_page_cur(cursor) (&(cursor)->btr_cur.page_cur)
-#endif /* UNIV_DEBUG */
/*********************************************************//**
Returns the page of a persistent cursor.
@return pointer to the page */
@@ -398,7 +378,7 @@ UNIV_INLINE
page_t*
btr_pcur_get_page(
/*==============*/
- btr_pcur_t* cursor);/*!< in: persistent cursor */
+ const btr_pcur_t* cursor);/*!< in: persistent cursor */
/*********************************************************//**
Returns the buffer block of a persistent cursor.
@return pointer to the block */
@@ -406,7 +386,7 @@ UNIV_INLINE
buf_block_t*
btr_pcur_get_block(
/*===============*/
- btr_pcur_t* cursor);/*!< in: persistent cursor */
+ const btr_pcur_t* cursor);/*!< in: persistent cursor */
/*********************************************************//**
Returns the record of a persistent cursor.
@return pointer to the record */
@@ -414,7 +394,14 @@ UNIV_INLINE
rec_t*
btr_pcur_get_rec(
/*=============*/
- btr_pcur_t* cursor);/*!< in: persistent cursor */
+ const btr_pcur_t* cursor);/*!< in: persistent cursor */
+#else /* UNIV_DEBUG */
+# define btr_pcur_get_btr_cur(cursor) (&(cursor)->btr_cur)
+# define btr_pcur_get_page_cur(cursor) (&(cursor)->btr_cur.page_cur)
+# define btr_pcur_get_page(cursor) ((cursor)->btr_cur.page_cur.block->frame)
+# define btr_pcur_get_block(cursor) ((cursor)->btr_cur.page_cur.block)
+# define btr_pcur_get_rec(cursor) ((cursor)->btr_cur.page_cur.rec)
+#endif /* UNIV_DEBUG */
/*********************************************************//**
Checks if the persistent cursor is on a user record. */
UNIV_INLINE
@@ -517,9 +504,6 @@ struct btr_pcur_struct{
/* NOTE that the following fields may possess dynamically allocated
memory which should be freed if not needed anymore! */
- mtr_t* mtr; /*!< NULL, or this field may contain
- a mini-transaction which holds the
- latch on the cursor page */
byte* old_rec_buf; /*!< NULL, or a dynamically allocated
buffer for old_rec */
ulint buf_size; /*!< old_rec_buf size if old_rec_buf
=== modified file 'storage/innobase/include/btr0pcur.ic'
--- a/storage/innobase/include/btr0pcur.ic revid:marko.makela@strippedq5gce4947
+++ b/storage/innobase/include/btr0pcur.ic revid:marko.makela@stripped
@@ -42,34 +42,6 @@ btr_pcur_get_rel_pos(
return(cursor->rel_pos);
}
-/*********************************************************//**
-Sets the mtr field for a pcur. */
-UNIV_INLINE
-void
-btr_pcur_set_mtr(
-/*=============*/
- btr_pcur_t* cursor, /*!< in: persistent cursor */
- mtr_t* mtr) /*!< in, own: mtr */
-{
- ut_ad(cursor);
-
- cursor->mtr = mtr;
-}
-
-/*********************************************************//**
-Gets the mtr field for a pcur.
-@return mtr */
-UNIV_INLINE
-mtr_t*
-btr_pcur_get_mtr(
-/*=============*/
- btr_pcur_t* cursor) /*!< in: persistent cursor */
-{
- ut_ad(cursor);
-
- return(cursor->mtr);
-}
-
#ifdef UNIV_DEBUG
/*********************************************************//**
Returns the btr cursor component of a persistent cursor.
@@ -95,7 +67,7 @@ btr_pcur_get_page_cur(
{
return(btr_cur_get_page_cur(btr_pcur_get_btr_cur(cursor)));
}
-#endif /* UNIV_DEBUG */
+
/*********************************************************//**
Returns the page of a persistent cursor.
@return pointer to the page */
@@ -103,7 +75,7 @@ UNIV_INLINE
page_t*
btr_pcur_get_page(
/*==============*/
- btr_pcur_t* cursor) /*!< in: persistent cursor */
+ const btr_pcur_t* cursor) /*!< in: persistent cursor */
{
ut_ad(cursor->pos_state == BTR_PCUR_IS_POSITIONED);
@@ -117,7 +89,7 @@ UNIV_INLINE
buf_block_t*
btr_pcur_get_block(
/*===============*/
- btr_pcur_t* cursor) /*!< in: persistent cursor */
+ const btr_pcur_t* cursor) /*!< in: persistent cursor */
{
ut_ad(cursor->pos_state == BTR_PCUR_IS_POSITIONED);
@@ -131,13 +103,14 @@ UNIV_INLINE
rec_t*
btr_pcur_get_rec(
/*=============*/
- btr_pcur_t* cursor) /*!< in: persistent cursor */
+ const btr_pcur_t* cursor) /*!< in: persistent cursor */
{
ut_ad(cursor->pos_state == BTR_PCUR_IS_POSITIONED);
ut_ad(cursor->latch_mode != BTR_NO_LATCHES);
return(btr_cur_get_rec(btr_pcur_get_btr_cur(cursor)));
}
+#endif /* UNIV_DEBUG */
/**************************************************************//**
Gets the up_match value for a pcur after a search.
@@ -147,9 +120,9 @@ UNIV_INLINE
ulint
btr_pcur_get_up_match(
/*==================*/
- btr_pcur_t* cursor) /*!< in: memory buffer for persistent cursor */
+ const btr_pcur_t* cursor) /*!< in: persistent cursor */
{
- btr_cur_t* btr_cursor;
+ const btr_cur_t* btr_cursor;
ut_ad((cursor->pos_state == BTR_PCUR_WAS_POSITIONED)
|| (cursor->pos_state == BTR_PCUR_IS_POSITIONED));
@@ -169,9 +142,9 @@ UNIV_INLINE
ulint
btr_pcur_get_low_match(
/*===================*/
- btr_pcur_t* cursor) /*!< in: memory buffer for persistent cursor */
+ const btr_pcur_t* cursor) /*!< in: persistent cursor */
{
- btr_cur_t* btr_cursor;
+ const btr_cur_t* btr_cursor;
ut_ad((cursor->pos_state == BTR_PCUR_WAS_POSITIONED)
|| (cursor->pos_state == BTR_PCUR_IS_POSITIONED));
=== modified file 'storage/innobase/include/page0page.h'
--- a/storage/innobase/include/page0page.h revid:marko.makela@oracle.com-20110315132451-phdr7rtq5gce4947
+++ b/storage/innobase/include/page0page.h revid:marko.makela@strippedom-20110322113916-oricw02qg3tzvim8
@@ -952,7 +952,7 @@ UNIV_INTERN
ibool
page_rec_validate(
/*==============*/
- rec_t* rec, /*!< in: physical record */
+ const rec_t* rec, /*!< in: physical record */
const ulint* offsets);/*!< in: array returned by rec_get_offsets() */
/***************************************************************//**
Checks that the first directory slot points to the infimum record and
@@ -972,7 +972,7 @@ UNIV_INTERN
ibool
page_simple_validate_old(
/*=====================*/
- page_t* page); /*!< in: old-style index page */
+ const page_t* page); /*!< in: index page in ROW_FORMAT=REDUNDANT */
/***************************************************************//**
This function checks the consistency of an index page when we do not
know the index. This is also resilient so that this should never crash
@@ -982,7 +982,7 @@ UNIV_INTERN
ibool
page_simple_validate_new(
/*=====================*/
- page_t* block); /*!< in: new-style index page */
+ const page_t* page); /*!< in: index page in ROW_FORMAT!=REDUNDANT */
/***************************************************************//**
This function checks the consistency of an index page.
@return TRUE if ok */
@@ -990,7 +990,7 @@ UNIV_INTERN
ibool
page_validate(
/*==========*/
- page_t* page, /*!< in: index page */
+ const page_t* page, /*!< in: index page */
dict_index_t* index); /*!< in: data dictionary index containing
the page record type definition */
/***************************************************************//**
=== modified file 'storage/innobase/include/rem0rec.h'
--- a/storage/innobase/include/rem0rec.h revid:marko.makela@stripped
+++ b/storage/innobase/include/rem0rec.h revid:marko.makela@strippedm-20110322113916-oricw02qg3tzvim8
@@ -600,6 +600,7 @@ ulint
rec_offs_size(
/*==========*/
const ulint* offsets);/*!< in: array returned by rec_get_offsets() */
+#ifdef UNIV_DEBUG
/**********************************************************//**
Returns a pointer to the start of the record.
@return pointer to start */
@@ -607,7 +608,7 @@ UNIV_INLINE
byte*
rec_get_start(
/*==========*/
- rec_t* rec, /*!< in: pointer to record */
+ const rec_t* rec, /*!< in: pointer to record */
const ulint* offsets);/*!< in: array returned by rec_get_offsets() */
/**********************************************************//**
Returns a pointer to the end of the record.
@@ -616,8 +617,12 @@ UNIV_INLINE
byte*
rec_get_end(
/*========*/
- rec_t* rec, /*!< in: pointer to record */
+ const rec_t* rec, /*!< in: pointer to record */
const ulint* offsets);/*!< in: array returned by rec_get_offsets() */
+#else /* UNIV_DEBUG */
+# define rec_get_start(rec, offsets) ((rec) - rec_offs_extra_size(offsets))
+# define rec_get_end(rec, offsets) ((rec) + rec_offs_data_size(offsets))
+#endif /* UNIV_DEBUG */
/***************************************************************//**
Copies a physical record to a buffer.
@return pointer to the origin of the copy */
=== modified file 'storage/innobase/include/rem0rec.ic'
--- a/storage/innobase/include/rem0rec.ic revid:marko.makela@stripped
+++ b/storage/innobase/include/rem0rec.ic revid:marko.makela@stripped
@@ -1462,6 +1462,7 @@ rec_offs_size(
return(rec_offs_data_size(offsets) + rec_offs_extra_size(offsets));
}
+#ifdef UNIV_DEBUG
/**********************************************************//**
Returns a pointer to the end of the record.
@return pointer to end */
@@ -1469,11 +1470,11 @@ UNIV_INLINE
byte*
rec_get_end(
/*========*/
- rec_t* rec, /*!< in: pointer to record */
+ const rec_t* rec, /*!< in: pointer to record */
const ulint* offsets)/*!< in: array returned by rec_get_offsets() */
{
ut_ad(rec_offs_validate(rec, NULL, offsets));
- return(rec + rec_offs_data_size(offsets));
+ return((rec_t*) rec + rec_offs_data_size(offsets));
}
/**********************************************************//**
@@ -1483,12 +1484,13 @@ UNIV_INLINE
byte*
rec_get_start(
/*==========*/
- rec_t* rec, /*!< in: pointer to record */
+ const rec_t* rec, /*!< in: pointer to record */
const ulint* offsets)/*!< in: array returned by rec_get_offsets() */
{
ut_ad(rec_offs_validate(rec, NULL, offsets));
- return(rec - rec_offs_extra_size(offsets));
+ return((rec_t*) rec - rec_offs_extra_size(offsets));
}
+#endif /* UNIV_DEBUG */
/***************************************************************//**
Copies a physical record to a buffer.
=== modified file 'storage/innobase/include/srv0srv.h'
--- a/storage/innobase/include/srv0srv.h revid:marko.makela@oracle.com-20110315132451-phdr7rtq5gce4947
+++ b/storage/innobase/include/srv0srv.h revid:marko.makela@stripped2113916-oricw02qg3tzvim8
@@ -442,16 +442,8 @@ typedef enum srv_stats_method_name_enum
#ifndef UNIV_HOTBACKUP
/** Types of threads existing in the system. */
enum srv_thread_type {
- SRV_COM = 1, /**< threads serving communication and queries */
- SRV_CONSOLE, /**< thread serving console */
- SRV_WORKER, /**< threads serving parallelized queries and
+ SRV_WORKER = 0, /**< threads serving parallelized queries and
queries released from lock wait */
-#if 0
- /* Utility threads */
- SRV_BUFFER, /**< thread flushing dirty buffer blocks */
- SRV_RECOVERY, /**< threads finishing a recovery */
- SRV_INSERT, /**< thread flushing the insert buffer to disk */
-#endif
SRV_MASTER /**< the master thread, (whose type number must
be biggest) */
};
@@ -490,13 +482,6 @@ ulint
srv_get_n_threads(void);
/*===================*/
/*********************************************************************//**
-Returns the calling thread type.
-@return SRV_COM, ... */
-
-enum srv_thread_type
-srv_get_thread_type(void);
-/*=====================*/
-/*********************************************************************//**
Check whether thread type has reserved a slot.
@return slot number or UNDEFINED if not found*/
UNIV_INTERN
=== modified file 'storage/innobase/include/thr0loc.h'
--- a/storage/innobase/include/thr0loc.h revid:marko.makela@stripped132451-phdr7rtq5gce4947
+++ b/storage/innobase/include/thr0loc.h revid:marko.makela@strippedw02qg3tzvim8
@@ -59,22 +59,6 @@ thr_local_free(
/*===========*/
os_thread_id_t id); /*!< in: thread id */
/*******************************************************************//**
-Gets the slot number in the thread table of a thread.
-@return slot number */
-UNIV_INTERN
-ulint
-thr_local_get_slot_no(
-/*==================*/
- os_thread_id_t id); /*!< in: thread id of the thread */
-/*******************************************************************//**
-Sets in the local storage the slot number in the thread table of a thread. */
-UNIV_INTERN
-void
-thr_local_set_slot_no(
-/*==================*/
- os_thread_id_t id, /*!< in: thread id of the thread */
- ulint slot_no);/*!< in: slot number */
-/*******************************************************************//**
Returns pointer to the 'in_ibuf' field within the current thread local
storage.
@return pointer to the in_ibuf field */
=== modified file 'storage/innobase/page/page0page.c'
--- a/storage/innobase/page/page0page.c revid:marko.makela@strippedom-20110315132451-phdr7rtq5gce4947
+++ b/storage/innobase/page/page0page.c revid:marko.makela@stripped13916-oricw02qg3tzvim8
@@ -166,11 +166,11 @@ static
ibool
page_dir_slot_check(
/*================*/
- page_dir_slot_t* slot) /*!< in: slot */
+ const page_dir_slot_t* slot) /*!< in: slot */
{
- page_t* page;
- ulint n_slots;
- ulint n_owned;
+ const page_t* page;
+ ulint n_slots;
+ ulint n_owned;
ut_a(slot);
@@ -1803,12 +1803,12 @@ UNIV_INTERN
ibool
page_rec_validate(
/*==============*/
- rec_t* rec, /*!< in: physical record */
+ const rec_t* rec, /*!< in: physical record */
const ulint* offsets)/*!< in: array returned by rec_get_offsets() */
{
- ulint n_owned;
- ulint heap_no;
- page_t* page;
+ ulint n_owned;
+ ulint heap_no;
+ const page_t* page;
page = page_align(rec);
ut_a(!page_is_comp(page) == !rec_offs_comp(offsets));
@@ -1889,16 +1889,16 @@ UNIV_INTERN
ibool
page_simple_validate_old(
/*=====================*/
- page_t* page) /*!< in: old-style index page */
+ const page_t* page) /*!< in: index page in ROW_FORMAT=REDUNDANT */
{
- page_dir_slot_t* slot;
- ulint slot_no;
- ulint n_slots;
- rec_t* rec;
- byte* rec_heap_top;
- ulint count;
- ulint own_count;
- ibool ret = FALSE;
+ const page_dir_slot_t* slot;
+ ulint slot_no;
+ ulint n_slots;
+ const rec_t* rec;
+ const byte* rec_heap_top;
+ ulint count;
+ ulint own_count;
+ ibool ret = FALSE;
ut_a(!page_is_comp(page));
@@ -2011,7 +2011,7 @@ page_simple_validate_old(
goto func_exit;
}
- rec = page_rec_get_next(rec);
+ rec = page_rec_get_next_const(rec);
own_count++;
}
@@ -2072,7 +2072,7 @@ page_simple_validate_old(
goto func_exit;
}
- rec = page_rec_get_next(rec);
+ rec = page_rec_get_next_const(rec);
}
if (UNIV_UNLIKELY(page_dir_get_n_heap(page) != count + 1)) {
@@ -2099,16 +2099,16 @@ UNIV_INTERN
ibool
page_simple_validate_new(
/*=====================*/
- page_t* page) /*!< in: new-style index page */
+ const page_t* page) /*!< in: index page in ROW_FORMAT!=REDUNDANT */
{
- page_dir_slot_t* slot;
- ulint slot_no;
- ulint n_slots;
- rec_t* rec;
- byte* rec_heap_top;
- ulint count;
- ulint own_count;
- ibool ret = FALSE;
+ const page_dir_slot_t* slot;
+ ulint slot_no;
+ ulint n_slots;
+ const rec_t* rec;
+ const byte* rec_heap_top;
+ ulint count;
+ ulint own_count;
+ ibool ret = FALSE;
ut_a(page_is_comp(page));
@@ -2221,7 +2221,7 @@ page_simple_validate_new(
goto func_exit;
}
- rec = page_rec_get_next(rec);
+ rec = page_rec_get_next_const(rec);
own_count++;
}
@@ -2283,7 +2283,7 @@ page_simple_validate_new(
goto func_exit;
}
- rec = page_rec_get_next(rec);
+ rec = page_rec_get_next_const(rec);
}
if (UNIV_UNLIKELY(page_dir_get_n_heap(page) != count + 1)) {
@@ -2308,26 +2308,26 @@ UNIV_INTERN
ibool
page_validate(
/*==========*/
- page_t* page, /*!< in: index page */
+ const page_t* page, /*!< in: index page */
dict_index_t* index) /*!< in: data dictionary index containing
the page record type definition */
{
- page_dir_slot_t*slot;
- mem_heap_t* heap;
- byte* buf;
- ulint count;
- ulint own_count;
- ulint rec_own_count;
- ulint slot_no;
- ulint data_size;
- rec_t* rec;
- rec_t* old_rec = NULL;
- ulint offs;
- ulint n_slots;
- ibool ret = FALSE;
- ulint i;
- ulint* offsets = NULL;
- ulint* old_offsets = NULL;
+ const page_dir_slot_t* slot;
+ mem_heap_t* heap;
+ byte* buf;
+ ulint count;
+ ulint own_count;
+ ulint rec_own_count;
+ ulint slot_no;
+ ulint data_size;
+ const rec_t* rec;
+ const rec_t* old_rec = NULL;
+ ulint offs;
+ ulint n_slots;
+ ibool ret = FALSE;
+ ulint i;
+ ulint* offsets = NULL;
+ ulint* old_offsets = NULL;
if (UNIV_UNLIKELY((ibool) !!page_is_comp(page)
!= dict_table_is_comp(index->table))) {
@@ -2482,7 +2482,7 @@ page_validate(
count++;
own_count++;
old_rec = rec;
- rec = page_rec_get_next(rec);
+ rec = page_rec_get_next_const(rec);
/* set old_offsets to offsets; recycle offsets */
{
@@ -2556,7 +2556,7 @@ n_owned_zero:
buf[offs + i] = 1;
}
- rec = page_rec_get_next(rec);
+ rec = page_rec_get_next_const(rec);
}
if (UNIV_UNLIKELY(page_dir_get_n_heap(page) != count + 1)) {
=== modified file 'storage/innobase/srv/srv0srv.c'
--- a/storage/innobase/srv/srv0srv.c revid:marko.makela@stripped
+++ b/storage/innobase/srv/srv0srv.c revid:marko.makela@strippedm-20110322113916-oricw02qg3tzvim8
@@ -690,7 +690,7 @@ Unix.*/
struct srv_slot_struct{
os_thread_id_t id; /*!< thread id */
os_thread_t handle; /*!< thread handle */
- unsigned type:3; /*!< thread type: user, utility etc. */
+ unsigned type:1; /*!< thread type: user, utility etc. */
unsigned in_use:1; /*!< TRUE if this slot is in use */
unsigned suspended:1; /*!< TRUE if the thread is waiting
for the event of this slot */
@@ -797,6 +797,7 @@ srv_table_get_nth_slot(
/*===================*/
ulint index) /*!< in: index of the slot */
{
+ ut_ad(mutex_own(&kernel_mutex));
ut_a(index < OS_THREAD_MAX_N);
return(srv_sys->threads + index);
@@ -815,7 +816,7 @@ srv_get_n_threads(void)
mutex_enter(&kernel_mutex);
- for (i = SRV_COM; i < SRV_MASTER + 1; i++) {
+ for (i = 0; i < SRV_MASTER + 1; i++) {
n_threads += srv_n_threads[i];
}
@@ -825,13 +826,46 @@ srv_get_n_threads(void)
return(n_threads);
}
+#ifdef UNIV_DEBUG
/*********************************************************************//**
-Reserves a slot in the thread table for the current thread. Also creates the
-thread local storage struct for the current thread. NOTE! The server mutex
-has to be reserved by the caller!
-@return reserved slot index */
+Validates the type of a thread table slot.
+@return TRUE if ok */
static
-ulint
+ibool
+srv_thread_type_validate(
+/*=====================*/
+ enum srv_thread_type type) /*!< in: thread type */
+{
+ switch (type) {
+ case SRV_WORKER:
+ case SRV_MASTER:
+ return(TRUE);
+ }
+ ut_error;
+ return(FALSE);
+}
+#endif /* UNIV_DEBUG */
+
+/*********************************************************************//**
+Gets the type of a thread table slot.
+@return thread type */
+static
+enum srv_thread_type
+srv_slot_get_type(
+/*==============*/
+ const srv_slot_t* slot) /*!< in: thread slot */
+{
+ enum srv_thread_type type = (enum srv_thread_type) slot->type;
+ ut_ad(srv_thread_type_validate(type));
+ return(type);
+}
+
+/*********************************************************************//**
+Reserves a slot in the thread table for the current thread.
+NOTE! The server mutex has to be reserved by the caller!
+@return reserved slot */
+static
+srv_slot_t*
srv_table_reserve_slot(
/*===================*/
enum srv_thread_type type) /*!< in: type of the thread */
@@ -839,8 +873,7 @@ srv_table_reserve_slot(
srv_slot_t* slot;
ulint i;
- ut_a(type > 0);
- ut_a(type <= SRV_MASTER);
+ ut_ad(srv_thread_type_validate(type));
ut_ad(mutex_own(&kernel_mutex));
i = 0;
@@ -851,53 +884,40 @@ srv_table_reserve_slot(
slot = srv_table_get_nth_slot(i);
}
- ut_a(slot->in_use == FALSE);
-
slot->in_use = TRUE;
slot->suspended = FALSE;
slot->type = type;
+ ut_ad(srv_slot_get_type(slot) == type);
slot->id = os_thread_get_curr_id();
slot->handle = os_thread_get_curr();
- thr_local_create();
-
- thr_local_set_slot_no(os_thread_get_curr_id(), i);
-
- return(i);
+ return(slot);
}
/*********************************************************************//**
Suspends the calling thread to wait for the event in its thread slot.
-NOTE! The server mutex has to be reserved by the caller!
-@return event for the calling thread to wait */
+NOTE! The server mutex has to be reserved by the caller! */
static
-os_event_t
-srv_suspend_thread(void)
-/*====================*/
+void
+srv_suspend_thread(
+/*===============*/
+ srv_slot_t* slot) /*!< in/out: thread slot */
{
- srv_slot_t* slot;
- os_event_t event;
- ulint slot_no;
enum srv_thread_type type;
ut_ad(mutex_own(&kernel_mutex));
-
- slot_no = thr_local_get_slot_no(os_thread_get_curr_id());
+ ut_ad(slot->in_use);
+ ut_ad(!slot->suspended);
+ ut_ad(slot->id == os_thread_get_curr_id());
if (srv_print_thread_releases) {
fprintf(stderr,
"Suspending thread %lu to slot %lu\n",
- (ulong) os_thread_get_curr_id(), (ulong) slot_no);
+ (ulong) os_thread_get_curr_id(),
+ (ulong) (slot - srv_sys->threads));
}
- slot = srv_table_get_nth_slot(slot_no);
-
- type = slot->type;
-
- ut_ad(type >= SRV_WORKER);
- ut_ad(type <= SRV_MASTER);
-
- event = slot->event;
+ type = srv_slot_get_type(slot);
slot->suspended = TRUE;
@@ -905,9 +925,7 @@ srv_suspend_thread(void)
srv_n_threads_active[type]--;
- os_event_reset(event);
-
- return(event);
+ os_event_reset(slot->event);
}
/*********************************************************************//**
@@ -926,8 +944,7 @@ srv_release_threads(
ulint i;
ulint count = 0;
- ut_ad(type >= SRV_WORKER);
- ut_ad(type <= SRV_MASTER);
+ ut_ad(srv_thread_type_validate(type));
ut_ad(n > 0);
ut_ad(mutex_own(&kernel_mutex));
@@ -935,7 +952,8 @@ srv_release_threads(
slot = srv_table_get_nth_slot(i);
- if (slot->in_use && slot->type == type && slot->suspended) {
+ if (slot->in_use && slot->suspended
+ && srv_slot_get_type(slot) == type) {
slot->suspended = FALSE;
@@ -963,34 +981,6 @@ srv_release_threads(
}
/*********************************************************************//**
-Returns the calling thread type.
-@return SRV_COM, ... */
-UNIV_INTERN
-enum srv_thread_type
-srv_get_thread_type(void)
-/*=====================*/
-{
- ulint slot_no;
- srv_slot_t* slot;
- enum srv_thread_type type;
-
- mutex_enter(&kernel_mutex);
-
- slot_no = thr_local_get_slot_no(os_thread_get_curr_id());
-
- slot = srv_table_get_nth_slot(slot_no);
-
- type = slot->type;
-
- ut_ad(type >= SRV_WORKER);
- ut_ad(type <= SRV_MASTER);
-
- mutex_exit(&kernel_mutex);
-
- return(type);
-}
-
-/*********************************************************************//**
Check whether thread type has reserved a slot. Return the first slot that
is found. This works because we currently have only 1 thread of each type.
@return slot number or ULINT_UNDEFINED if not found*/
@@ -1003,6 +993,7 @@ srv_thread_has_reserved_slot(
ulint i;
ulint slot_no = ULINT_UNDEFINED;
+ ut_ad(srv_thread_type_validate(type));
mutex_enter(&kernel_mutex);
for (i = 0; i < OS_THREAD_MAX_N; i++) {
@@ -1040,22 +1031,18 @@ srv_init(void)
mutex_create(srv_innodb_monitor_mutex_key,
&srv_innodb_monitor_mutex, SYNC_NO_ORDER_CHECK);
- srv_sys->threads = mem_alloc(OS_THREAD_MAX_N * sizeof(srv_slot_t));
+ srv_sys->threads = mem_zalloc(OS_THREAD_MAX_N * sizeof(srv_slot_t));
for (i = 0; i < OS_THREAD_MAX_N; i++) {
- slot = srv_table_get_nth_slot(i);
- slot->in_use = FALSE;
- slot->type=0; /* Avoid purify errors */
+ slot = srv_sys->threads + i;
slot->event = os_event_create(NULL);
ut_a(slot->event);
}
- srv_mysql_table = mem_alloc(OS_THREAD_MAX_N * sizeof(srv_slot_t));
+ srv_mysql_table = mem_zalloc(OS_THREAD_MAX_N * sizeof(srv_slot_t));
for (i = 0; i < OS_THREAD_MAX_N; i++) {
slot = srv_mysql_table + i;
- slot->in_use = FALSE;
- slot->type = 0;
slot->event = os_event_create(NULL);
ut_a(slot->event);
}
@@ -1501,7 +1488,7 @@ srv_table_reserve_slot_for_mysql(void)
while (slot->in_use) {
i++;
- if (i >= OS_THREAD_MAX_N) {
+ if (UNIV_UNLIKELY(i >= OS_THREAD_MAX_N)) {
ut_print_timestamp(stderr);
@@ -2489,7 +2476,7 @@ srv_is_any_background_thread_active(void
mutex_enter(&kernel_mutex);
- for (i = SRV_COM; i <= SRV_MASTER; ++i) {
+ for (i = 0; i <= SRV_MASTER; ++i) {
if (srv_n_threads_active[i] != 0) {
ret = TRUE;
break;
@@ -2643,7 +2630,7 @@ srv_master_thread(
os_thread_create */
{
buf_pool_stat_t buf_stat;
- os_event_t event;
+ srv_slot_t* slot;
ulint old_activity_count;
ulint n_pages_purged = 0;
ulint n_bytes_merged;
@@ -2671,7 +2658,7 @@ srv_master_thread(
mutex_enter(&kernel_mutex);
- srv_table_reserve_slot(SRV_MASTER);
+ slot = srv_table_reserve_slot(SRV_MASTER);
srv_n_threads_active[SRV_MASTER]++;
@@ -3060,7 +3047,7 @@ suspend_thread:
goto loop;
}
- event = srv_suspend_thread();
+ srv_suspend_thread(slot);
mutex_exit(&kernel_mutex);
@@ -3070,7 +3057,7 @@ suspend_thread:
manual also mentions this string in several places. */
srv_main_thread_op_info = "waiting for server activity";
- os_event_wait(event);
+ os_event_wait(slot->event);
if (srv_shutdown_state == SRV_SHUTDOWN_EXIT_THREADS) {
/* This is only extra safety, the thread should exit
@@ -3100,7 +3087,6 @@ srv_purge_thread(
{
srv_slot_t* slot;
ulint retries = 0;
- ulint slot_no = ULINT_UNDEFINED;
ulint n_total_purged = ULINT_UNDEFINED;
ut_a(srv_n_purge_threads == 1);
@@ -3116,9 +3102,7 @@ srv_purge_thread(
mutex_enter(&kernel_mutex);
- slot_no = srv_table_reserve_slot(SRV_WORKER);
-
- slot = srv_table_get_nth_slot(slot_no);
+ slot = srv_table_reserve_slot(SRV_WORKER);
++srv_n_threads_active[SRV_WORKER];
@@ -3137,15 +3121,13 @@ srv_purge_thread(
|| (n_total_purged == 0
&& retries >= TRX_SYS_N_RSEGS)) {
- os_event_t event;
-
mutex_enter(&kernel_mutex);
- event = srv_suspend_thread();
+ srv_suspend_thread(slot);
mutex_exit(&kernel_mutex);
- os_event_wait(event);
+ os_event_wait(slot->event);
retries = 0;
}
@@ -3179,16 +3161,11 @@ srv_purge_thread(
mutex_enter(&kernel_mutex);
- ut_ad(srv_table_get_nth_slot(slot_no) == slot);
-
/* Decrement the active count. */
- srv_suspend_thread();
+ srv_suspend_thread(slot);
slot->in_use = FALSE;
- /* Free the thread local memory. */
- thr_local_free(os_thread_get_curr_id());
-
mutex_exit(&kernel_mutex);
#ifdef UNIV_DEBUG_THREAD_CREATION
=== modified file 'storage/innobase/thr/thr0loc.c'
--- a/storage/innobase/thr/thr0loc.c revid:marko.makela@stripped2451-phdr7rtq5gce4947
+++ b/storage/innobase/thr/thr0loc.c revid:marko.makela@strippedtzvim8
@@ -65,8 +65,6 @@ for the field. */
struct thr_local_struct{
os_thread_id_t id; /*!< id of the thread which owns this struct */
os_thread_t handle; /*!< operating system handle to the thread */
- ulint slot_no;/*!< the index of the slot in the thread table
- for this thread */
ibool in_ibuf;/*!< TRUE if the thread is doing an ibuf
operation */
hash_node_t hash; /*!< hash chain node */
@@ -87,8 +85,6 @@ thr_local_validate(
const thr_local_t* local) /*!< in: data to validate */
{
ut_ad(local->magic_n == THR_LOCAL_MAGIC_N);
- ut_ad(local->slot_no == ULINT_UNDEFINED
- || local->slot_no < OS_THREAD_MAX_N);
ut_ad(local->in_ibuf == FALSE || local->in_ibuf == TRUE);
return(TRUE);
}
@@ -132,49 +128,6 @@ try_again:
}
/*******************************************************************//**
-Gets the slot number in the thread table of a thread.
-@return slot number */
-UNIV_INTERN
-ulint
-thr_local_get_slot_no(
-/*==================*/
- os_thread_id_t id) /*!< in: thread id of the thread */
-{
- ulint slot_no;
- thr_local_t* local;
-
- mutex_enter(&thr_local_mutex);
-
- local = thr_local_get(id);
-
- slot_no = local->slot_no;
-
- mutex_exit(&thr_local_mutex);
-
- return(slot_no);
-}
-
-/*******************************************************************//**
-Sets the slot number in the thread table of a thread. */
-UNIV_INTERN
-void
-thr_local_set_slot_no(
-/*==================*/
- os_thread_id_t id, /*!< in: thread id of the thread */
- ulint slot_no)/*!< in: slot number */
-{
- thr_local_t* local;
-
- mutex_enter(&thr_local_mutex);
-
- local = thr_local_get(id);
-
- local->slot_no = slot_no;
-
- mutex_exit(&thr_local_mutex);
-}
-
-/*******************************************************************//**
Returns pointer to the 'in_ibuf' field within the current thread local
storage.
@return pointer to the in_ibuf field */
@@ -212,7 +165,6 @@ thr_local_create(void)
local->id = os_thread_get_curr_id();
local->handle = os_thread_get_curr();
local->magic_n = THR_LOCAL_MAGIC_N;
- local->slot_no = ULINT_UNDEFINED;
local->in_ibuf = FALSE;
mutex_enter(&thr_local_mutex);
Attachment: [text/bzr-bundle] bzr/marko.makela@oracle.com-20110322113916-oricw02qg3tzvim8.bundle
| Thread |
|---|
| • bzr push into mysql-5.5-innodb branch (marko.makela:3347 to 3350)Bug#11766305 | marko.makela | 22 Mar |