~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
/* Copyright (C) 2000 MySQL AB
2
3
   This program is free software; you can redistribute it and/or modify
4
   it under the terms of the GNU General Public License as published by
5
   the Free Software Foundation; version 2 of the License.
6
7
   This program is distributed in the hope that it will be useful,
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
   GNU General Public License for more details.
11
12
   You should have received a copy of the GNU General Public License
13
   along with this program; if not, write to the Free Software
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
16
/* For use with thr_lock:s */
17
1122.2.10 by Monty Taylor
Fixed all of the include guards.
18
#ifndef MYSYS_THR_LOCK_H
19
#define MYSYS_THR_LOCK_H
20
1 by brian
clean slate
21
#ifdef	__cplusplus
22
extern "C" {
23
#endif
24
212.5.13 by Monty Taylor
Moved my_sys/my_pthread/my_nosys and mysys_err to mysys.
25
#include <mysys/my_pthread.h>
520.6.4 by Monty Taylor
Moved thr_lock.h out of common_includes.
26
#include <mysys/definitions.h>
1 by brian
clean slate
27
28
struct st_thr_lock;
298 by Brian Aker
ulong conversion.
29
extern uint32_t locks_immediate,locks_waited ;
53.2.23 by Monty Taylor
Fixed the thr_lock double define the right direction.
30
extern pthread_mutex_t THR_LOCK_lock;
1 by brian
clean slate
31
32
622.1.1 by Brian Aker
32bit fixes around vars
33
extern uint64_t max_write_lock_count;
34
extern uint64_t table_lock_wait_timeout;
146 by Brian Aker
my_bool cleanup.
35
extern bool thr_lock_inited;
1 by brian
clean slate
36
37
/*
38
  A description of the thread which owns the lock. The address
39
  of an instance of this structure is used to uniquely identify the thread.
40
*/
41
42
typedef struct st_thr_lock_info
43
{
44
  pthread_t thread;
45
  my_thread_id thread_id;
298 by Brian Aker
ulong conversion.
46
  uint32_t n_cursors;
1 by brian
clean slate
47
} THR_LOCK_INFO;
48
49
/*
50
  Lock owner identifier. Globally identifies the lock owner within the
51
  thread and among all the threads. The address of an instance of this
52
  structure is used as id.
53
*/
54
55
typedef struct st_thr_lock_owner
56
{
57
  THR_LOCK_INFO *info;
58
} THR_LOCK_OWNER;
59
60
61
typedef struct st_thr_lock_data {
62
  THR_LOCK_OWNER *owner;
63
  struct st_thr_lock_data *next,**prev;
64
  struct st_thr_lock *lock;
65
  pthread_cond_t *cond;
66
  enum thr_lock_type type;
67
  void *status_param;			/* Param to status functions */
68
} THR_LOCK_DATA;
69
70
struct st_lock_list {
71
  THR_LOCK_DATA *data,**last;
72
};
73
74
typedef struct st_thr_lock {
75
  pthread_mutex_t mutex;
76
  struct st_lock_list read_wait;
77
  struct st_lock_list read;
78
  struct st_lock_list write_wait;
79
  struct st_lock_list write;
80
  /* write_lock_count is incremented for write locks and reset on read locks */
298 by Brian Aker
ulong conversion.
81
  uint32_t write_lock_count;
482 by Brian Aker
Remove uint.
82
  uint32_t read_no_write_count;
1 by brian
clean slate
83
  void (*get_status)(void*, int);	/* When one gets a lock */
84
  void (*copy_status)(void*,void*);
85
  void (*update_status)(void*);		/* Before release of write */
86
  void (*restore_status)(void*);         /* Before release of read */
146 by Brian Aker
my_bool cleanup.
87
  bool (*check_status)(void *);
1 by brian
clean slate
88
} THR_LOCK;
89
90
146 by Brian Aker
my_bool cleanup.
91
bool init_thr_lock(void);		/* Must be called once/thread */
1 by brian
clean slate
92
#define thr_lock_owner_init(owner, info_arg) (owner)->info= (info_arg)
93
void thr_lock_info_init(THR_LOCK_INFO *info);
94
void thr_lock_init(THR_LOCK *lock);
95
void thr_lock_delete(THR_LOCK *lock);
96
void thr_lock_data_init(THR_LOCK *lock,THR_LOCK_DATA *data,
97
			void *status_param);
98
enum enum_thr_lock_result thr_multi_lock(THR_LOCK_DATA **data,
482 by Brian Aker
Remove uint.
99
                                         uint32_t count, THR_LOCK_OWNER *owner);
100
void thr_multi_unlock(THR_LOCK_DATA **data,uint32_t count);
1113.1.2 by Brian Aker
Refactor/kill some dead lock code.
101
void thr_abort_locks(THR_LOCK *lock);
146 by Brian Aker
my_bool cleanup.
102
bool thr_abort_locks_for_thread(THR_LOCK *lock, my_thread_id thread);
1 by brian
clean slate
103
#ifdef	__cplusplus
104
}
105
#endif
1122.2.10 by Monty Taylor
Fixed all of the include guards.
106
#endif /* MYSYS_THR_LOCK_H */