Commit 047ce0dc authored by unknown's avatar unknown

Problems of partially freed waiting quque fixed (BUG#35040)


mysys/wqueue.c:
  Problems of partially freed waiting quque fixed.
storage/maria/unittest/ma_pagecache_rwconsist.c:
  Explicitly assigned initial value for increasing readability.
  Dbug file flush after each line for better debugging.
  Fixed code style.
parent 722a8ebe
...@@ -140,55 +140,58 @@ void wqueue_release_queue(WQUEUE *wqueue) ...@@ -140,55 +140,58 @@ void wqueue_release_queue(WQUEUE *wqueue)
@brief Removes all threads waiting for read or first one waiting for write. @brief Removes all threads waiting for read or first one waiting for write.
@param wqueue pointer to the queue structure @param wqueue pointer to the queue structure
@apram thread pointer to the thread to be added to the queue @param thread pointer to the thread to be added to the queue
@note This function is applicable only to single linked lists.
*/ */
void wqueue_release_one_locktype_from_queue(WQUEUE *wqueue) void wqueue_release_one_locktype_from_queue(WQUEUE *wqueue)
{ {
struct st_my_thread_var *last= wqueue->last_thread; struct st_my_thread_var *last= wqueue->last_thread;
struct st_my_thread_var *next= last->next; struct st_my_thread_var *next= last->next;
struct st_my_thread_var **prev= &last->next;
struct st_my_thread_var *thread; struct st_my_thread_var *thread;
struct st_my_thread_var *new_last= NULL; struct st_my_thread_var *new_list= NULL;
uint first_type= next->lock_type; uint first_type= next->lock_type;
if (first_type == MY_PTHREAD_LOCK_WRITE) if (first_type == MY_PTHREAD_LOCK_WRITE)
{ {
/* release first waiting for write lock */ /* release first waiting for write lock */
thread= next; pthread_cond_signal(&next->suspend);
pthread_cond_signal(&thread->suspend); #ifndef DBUG_OFF
if (thread == last) next->prev= NULL; /* force segfault if used */
#endif
if (next == last)
wqueue->last_thread= NULL; wqueue->last_thread= NULL;
*prev= thread->next; else
thread->next= NULL; last->next= next->next;
next->next= NULL;
return; return;
} }
do do
{ {
thread= next; thread= next;
next= thread->next; next= thread->next;
#ifndef DBUG_OFF
thread->prev= NULL; /* force segfault if used */
#endif
if (thread->lock_type == MY_PTHREAD_LOCK_WRITE) if (thread->lock_type == MY_PTHREAD_LOCK_WRITE)
{ {
/* skip waiting for write lock */ /* skip waiting for write lock */
*prev= thread; if (new_list)
prev= &thread->next; {
new_last= NULL; thread->next= new_list->next;
new_list= new_list->next= thread;
}
else
new_list= thread->next= thread;
} }
else else
{ {
/* release waiting for read lock */ /* release waiting for read lock */
pthread_cond_signal(&thread->suspend); pthread_cond_signal(&thread->suspend);
new_last= thread->next;
thread->next= NULL; thread->next= NULL;
} }
} while (thread != last); } while (thread != last);
if (new_last) wqueue->last_thread= new_list;
{
/* last was deleted */
if (new_last == last)
wqueue->last_thread= NULL; /* empty list */
else
wqueue->last_thread= new_last;
}
} }
......
...@@ -37,7 +37,7 @@ static char *file1_name= (char*)"page_cache_test_file_1"; ...@@ -37,7 +37,7 @@ static char *file1_name= (char*)"page_cache_test_file_1";
static PAGECACHE_FILE file1; static PAGECACHE_FILE file1;
static pthread_cond_t COND_thread_count; static pthread_cond_t COND_thread_count;
static pthread_mutex_t LOCK_thread_count; static pthread_mutex_t LOCK_thread_count;
static uint thread_count; static uint thread_count= 0;
static PAGECACHE pagecache; static PAGECACHE pagecache;
static uint number_of_readers= 5; static uint number_of_readers= 5;
...@@ -214,7 +214,7 @@ int main(int argc __attribute__((unused)), ...@@ -214,7 +214,7 @@ int main(int argc __attribute__((unused)),
#if defined(__WIN__) #if defined(__WIN__)
default_dbug_option= "d:t:i:O,\\test_pagecache_consist.trace"; default_dbug_option= "d:t:i:O,\\test_pagecache_consist.trace";
#else #else
default_dbug_option= "d:t:i:o,/tmp/test_pagecache_consist.trace"; default_dbug_option= "d:t:i:O,/tmp/test_pagecache_consist.trace";
#endif #endif
if (argc > 1) if (argc > 1)
{ {
...@@ -335,8 +335,8 @@ int main(int argc __attribute__((unused)), ...@@ -335,8 +335,8 @@ int main(int argc __attribute__((unused)),
pthread_mutex_lock(&LOCK_thread_count); pthread_mutex_lock(&LOCK_thread_count);
while (thread_count) while (thread_count)
{ {
if ((error= pthread_cond_wait(&COND_thread_count,&LOCK_thread_count))) if ((error= pthread_cond_wait(&COND_thread_count, &LOCK_thread_count)))
diag("COND_thread_count: %d from pthread_cond_wait\n",error); diag("COND_thread_count: %d from pthread_cond_wait\n", error);
} }
pthread_mutex_unlock(&LOCK_thread_count); pthread_mutex_unlock(&LOCK_thread_count);
DBUG_PRINT("info", ("thread ended")); DBUG_PRINT("info", ("thread ended"));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment