~mysql/mysql-server/mysql-6.0

« back to all changes in this revision

Viewing changes to include/thr_lock.h

  • Committer: bk at mysql
  • Date: 2000-07-31 19:29:14 UTC
  • Revision ID: sp1r-bk@work.mysql.com-20000731192914-08846
Import changeset

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
 
2
   
 
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.
 
7
   
 
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.
 
12
   
 
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,
 
16
   MA 02111-1307, USA */
 
17
 
 
18
/* For use with thr_lock:s */
 
19
 
 
20
#ifndef _thr_lock_h
 
21
#define _thr_lock_h
 
22
#ifdef  __cplusplus
 
23
extern "C" {
 
24
#endif
 
25
 
 
26
#include <my_pthread.h>
 
27
#include <my_list.h>
 
28
 
 
29
struct st_thr_lock;
 
30
 
 
31
enum thr_lock_type { TL_IGNORE=-1,
 
32
                     TL_UNLOCK, TL_READ,  TL_READ_HIGH_PRIORITY,
 
33
                     TL_READ_NO_INSERT,
 
34
                     TL_WRITE_ALLOW_WRITE, TL_WRITE_ALLOW_READ,
 
35
                     TL_WRITE_CONCURRENT_INSERT,
 
36
                     TL_WRITE_DELAYED, TL_WRITE_LOW_PRIORITY, TL_WRITE,
 
37
                     TL_WRITE_ONLY};
 
38
 
 
39
extern ulong max_write_lock_count;
 
40
extern my_bool thr_lock_inited;
 
41
 
 
42
typedef struct st_thr_lock_data {
 
43
  pthread_t thread;
 
44
  struct st_thr_lock_data *next,**prev;
 
45
  struct st_thr_lock *lock;
 
46
  pthread_cond_t *cond;
 
47
  enum thr_lock_type type;
 
48
  ulong thread_id;
 
49
  void *status_param;                   /* Param to status functions */
 
50
} THR_LOCK_DATA;
 
51
 
 
52
struct st_lock_list {
 
53
  THR_LOCK_DATA *data,**last;
 
54
};
 
55
 
 
56
typedef struct st_thr_lock {
 
57
  LIST list;
 
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 *);
 
70
} THR_LOCK;
 
71
 
 
72
 
 
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,
 
77
                        void *status_param);
 
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);
 
86
#ifdef  __cplusplus
 
87
}
 
88
#endif
 
89
#endif /* _thr_lock_h */