1
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
3
This library is free software; you can redistribute it and/or
4
modify it under the terms of the GNU Library General Public
5
License as published by the Free Software Foundation; either
6
version 2 of the License, or (at your option) any later version.
8
This library is distributed in the hope that it will be useful,
9
but WITHOUT ANY WARRANTY; without even the implied warranty of
10
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
Library General Public License for more details.
13
You should have received a copy of the GNU Library General Public
14
License along with this library; if not, write to the Free
15
Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18
/* For use with thr_lock:s */
26
#include <my_pthread.h>
31
enum thr_lock_type { TL_IGNORE=-1,
32
TL_UNLOCK, TL_READ, TL_READ_HIGH_PRIORITY,
34
TL_WRITE_ALLOW_WRITE, TL_WRITE_ALLOW_READ,
35
TL_WRITE_CONCURRENT_INSERT,
36
TL_WRITE_DELAYED, TL_WRITE_LOW_PRIORITY, TL_WRITE,
39
extern ulong max_write_lock_count;
40
extern my_bool thr_lock_inited;
42
typedef struct st_thr_lock_data {
44
struct st_thr_lock_data *next,**prev;
45
struct st_thr_lock *lock;
47
enum thr_lock_type type;
49
void *status_param; /* Param to status functions */
53
THR_LOCK_DATA *data,**last;
56
typedef struct st_thr_lock {
58
pthread_mutex_t mutex;
59
struct st_lock_list read_wait;
60
struct st_lock_list read;
61
struct st_lock_list write_wait;
62
struct st_lock_list write;
63
/* write_lock_count is incremented for write locks and reset on read locks */
64
ulong write_lock_count;
65
uint read_no_write_count;
66
void (*get_status)(void*); /* When one gets a lock */
67
void (*copy_status)(void*,void*);
68
void (*update_status)(void*); /* Before release of write */
69
my_bool (*check_status)(void *);
73
my_bool init_thr_lock(void); /* Must be called once/thread */
74
void thr_lock_init(THR_LOCK *lock);
75
void thr_lock_delete(THR_LOCK *lock);
76
void thr_lock_data_init(THR_LOCK *lock,THR_LOCK_DATA *data,
78
int thr_lock(THR_LOCK_DATA *data,enum thr_lock_type lock_type);
79
void thr_unlock(THR_LOCK_DATA *data);
80
int thr_multi_lock(THR_LOCK_DATA **data,uint count);
81
void thr_multi_unlock(THR_LOCK_DATA **data,uint count);
82
void thr_abort_locks(THR_LOCK *lock);
83
void thr_print_locks(void); /* For debugging */
84
my_bool thr_upgrade_write_delay_lock(THR_LOCK_DATA *data);
85
my_bool thr_reschedule_write_lock(THR_LOCK_DATA *data);
89
#endif /* _thr_lock_h */