1
/* Copyright (C) 2006 MySQL AB
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.
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.
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 */
23
N - "no lock", not a lock, used sometimes internally to simplify the code
27
IX - Intention eXclusive
28
SIX - Shared + Intention eXclusive
31
SLX - Shared + Loose eXclusive
32
LSIX - Loose Shared + Intention eXclusive
34
enum lockman_lock_type { N, S, X, IS, IX, SIX, LS, LX, SLX, LSIX, LOCK_TYPE_LAST };
38
typedef struct st_lock_owner LOCK_OWNER;
39
struct st_lock_owner {
40
LF_PINS *pins; /* must be allocated from lockman's pinbox */
41
struct lockman_lock *all_locks; /* a LIFO */
42
LOCK_OWNER *waiting_for;
43
pthread_cond_t *cond; /* transactions waiting for this, wait on 'cond' */
44
pthread_mutex_t *mutex; /* mutex is required to use 'cond' */
48
typedef LOCK_OWNER *loid_to_lo_func(uint16);
50
LF_DYNARRAY array; /* hash itself */
51
LF_ALLOCATOR alloc; /* allocator for elements */
52
int32 volatile size; /* size of array */
53
int32 volatile count; /* number of elements in the hash */
55
loid_to_lo_func *loid_to_lo;
57
#define DIDNT_GET_THE_LOCK 0
58
enum lockman_getlock_result {
59
NO_MEMORY_FOR_LOCK=1, DEADLOCK, LOCK_TIMEOUT,
61
GOT_THE_LOCK_NEED_TO_LOCK_A_SUBRESOURCE,
62
GOT_THE_LOCK_NEED_TO_INSTANT_LOCK_A_SUBRESOURCE
65
void lockman_init(LOCKMAN *, loid_to_lo_func *, uint);
66
void lockman_destroy(LOCKMAN *);
67
enum lockman_getlock_result lockman_getlock(LOCKMAN *lm, LOCK_OWNER *lo,
69
enum lockman_lock_type lock);
70
int lockman_release_locks(LOCKMAN *, LOCK_OWNER *);
73
void print_lockhash(LOCKMAN *lm);