mariadb/mysys/wqueue.c
unknown 8224c76fbd Removed MARIA_BASE min_row_length (duplicate of min_block_length)
Cleanup of recent code changes in dbug and my_thr_init
Added name for each safe_mutex (for better DBUG and error reporting)
Fixed that sort_info.max_records is calculated correctly. This fixed a bug in maria_chk
Removed duplicate printing of mutex address in dbug log


dbug/dbug.c:
  Cleanup of recent code changes
include/my_pthread.h:
  Added name for each safe_mutex (for better DBUG and error reporting)
mysys/my_thr_init.c:
  Cleanup of recent code changes
mysys/thr_mutex.c:
  Added name for each safe_mutex (for better DBUG and error reporting)
mysys/wqueue.c:
  Removed some mutex printing (as it's done now when we take mutex)
storage/maria/Makefile.am:
  Fixed that 'make tags' works with xemacs
storage/maria/ma_blockrec.c:
  base.min_row_length -> base.min_block_length
  (As they where basicly the same variable)
storage/maria/ma_check.c:
  Moved more common stuff to initialize_variables_for_repair
  Fixed that sort_info.max_records is calculated correctly. This fixed a bug in maria_chk
storage/maria/ma_create.c:
  More comments
  Fixed that min_pack_length is calculated more correctly
  Removed duplicate variable base.min_row_length
storage/maria/ma_loghandler.c:
  Removed duplicate printing of mutex address
storage/maria/ma_open.c:
  Removed base.min_row_length
storage/maria/ma_packrec.c:
  Removed not anymore needed code
  (One should not change any .base variables as this will affect repair with unpack)
storage/maria/maria_def.h:
  Removed base.min_row_length
2007-12-12 23:57:28 +02:00

169 lines
4.2 KiB
C

#include <wqueue.h>
#define STRUCT_PTR(TYPE, MEMBER, a) \
(TYPE *) ((char *) (a) - offsetof(TYPE, MEMBER))
/*
Link a thread into double-linked queue of waiting threads.
SYNOPSIS
wqueue_link_into_queue()
wqueue pointer to the queue structure
thread pointer to the thread to be added to the queue
RETURN VALUE
none
NOTES.
Queue is represented by a circular list of the thread structures
The list is double-linked of the type (**prev,*next), accessed by
a pointer to the last element.
*/
void wqueue_link_into_queue(WQUEUE *wqueue, struct st_my_thread_var *thread)
{
struct st_my_thread_var *last;
if (!(last= wqueue->last_thread))
{
/* Queue is empty */
thread->next= thread;
thread->prev= &thread->next;
}
else
{
thread->prev= last->next->prev;
last->next->prev= &thread->next;
thread->next= last->next;
last->next= thread;
}
wqueue->last_thread= thread;
}
/*
Add a thread to single-linked queue of waiting threads
SYNOPSIS
wqueue_add_to_queue()
wqueue pointer to the queue structure
thread pointer to the thread to be added to the queue
RETURN VALUE
none
NOTES.
Queue is represented by a circular list of the thread structures
The list is single-linked of the type (*next), accessed by a pointer
to the last element.
*/
void wqueue_add_to_queue(WQUEUE *wqueue, struct st_my_thread_var *thread)
{
struct st_my_thread_var *last;
if (!(last= wqueue->last_thread))
thread->next= thread;
else
{
thread->next= last->next;
last->next= thread;
}
wqueue->last_thread= thread;
}
/*
Unlink a thread from double-linked queue of waiting threads
SYNOPSIS
wqueue_unlink_from_queue()
wqueue pointer to the queue structure
thread pointer to the thread to be removed from the queue
RETURN VALUE
none
NOTES.
See NOTES for link_into_queue
*/
void wqueue_unlink_from_queue(WQUEUE *wqueue, struct st_my_thread_var *thread)
{
if (thread->next == thread)
/* The queue contains only one member */
wqueue->last_thread= NULL;
else
{
thread->next->prev= thread->prev;
*thread->prev= thread->next;
if (wqueue->last_thread == thread)
wqueue->last_thread= STRUCT_PTR(struct st_my_thread_var, next,
thread->prev);
}
thread->next= NULL;
}
/*
Remove all threads from queue signaling them to proceed
SYNOPSIS
wqueue_realease_queue()
wqueue pointer to the queue structure
thread pointer to the thread to be added to the queue
RETURN VALUE
none
NOTES.
See notes for add_to_queue
When removed from the queue each thread is signaled via condition
variable thread->suspend.
*/
void wqueue_release_queue(WQUEUE *wqueue)
{
struct st_my_thread_var *last= wqueue->last_thread;
struct st_my_thread_var *next= last->next;
struct st_my_thread_var *thread;
do
{
thread= next;
pthread_cond_signal(&thread->suspend);
next= thread->next;
thread->next= NULL;
}
while (thread != last);
wqueue->last_thread= NULL;
}
/*
Add thread and wait
SYNOPSYS
wqueue_add_and_wait()
wqueue queue to add to
thread thread which is waiting
lock mutex need for the operation
*/
void wqueue_add_and_wait(WQUEUE *wqueue,
struct st_my_thread_var *thread,
pthread_mutex_t *lock)
{
DBUG_ENTER("wqueue_add_and_wait");
DBUG_PRINT("enter",
("thread: 0x%lx cond: 0x%lx mutex: 0x%lx",
(ulong) thread, (ulong) &thread->suspend, (ulong) lock));
wqueue_add_to_queue(wqueue, thread);
do
{
DBUG_PRINT("info", ("wait... cond: 0x%lx mutex: 0x%lx",
(ulong) &thread->suspend, (ulong) lock));
pthread_cond_wait(&thread->suspend, lock);
DBUG_PRINT("info", ("wait done cond: 0x%lx mutex: 0x%lx next: 0x%lx",
(ulong) &thread->suspend, (ulong) lock,
(ulong) thread->next));
}
while (thread->next);
DBUG_VOID_RETURN;
}