Skip to content

Commit

Permalink
Added easy way to assert if another thread has died.
Browse files Browse the repository at this point in the history
Added some extra safety asserts in MyISAM key cache.

my_thread_var->init is now:
0 at startup
1 at init
2 when thread dies
  • Loading branch information
montywi committed Jul 26, 2015
1 parent f3e578a commit 517ef2b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 6 additions & 4 deletions mysys/mf_keycache.c
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,7 @@ static void wait_on_queue(KEYCACHE_WQUEUE *wqueue,
struct st_my_thread_var *thread= my_thread_var;
DBUG_ASSERT(!thread->next);
DBUG_ASSERT(!thread->prev); /* Not required, but must be true anyway. */
mysql_mutex_assert_owner(mutex);

/* Add to queue. */
if (! (last= wqueue->last_thread))
Expand Down Expand Up @@ -1177,14 +1178,15 @@ static void release_whole_queue(KEYCACHE_WQUEUE *wqueue)
do
{
thread=next;
DBUG_ASSERT(thread);
DBUG_ASSERT(thread && thread->init == 1);
KEYCACHE_DBUG_PRINT("release_whole_queue: signal",
("thread %ld", thread->id));
/* Signal the thread. */
keycache_pthread_cond_signal(&thread->suspend);
/* Take thread from queue. */
next=thread->next;
next= thread->next;
thread->next= NULL;

/* Signal the thread. */
keycache_pthread_cond_signal(&thread->suspend);
}
while (thread != last);

Expand Down
2 changes: 2 additions & 0 deletions mysys/my_thr_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,8 @@ void my_thread_end(void)
mysql_cond_signal(&THR_COND_threads);
mysql_mutex_unlock(&THR_LOCK_threads);

/* Trash variable so that we can detect false accesses to my_thread_var */
tmp->init= 2;
TRASH(tmp, sizeof(*tmp));
free(tmp);
}
Expand Down

0 comments on commit 517ef2b

Please sign in to comment.