1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
#include <drizzled/server_includes.h>
22
#include <drizzled/functions/lock.h>
28
pthread_mutex_t LOCK_user_locks;
29
static HASH hash_user_locks;
40
my_thread_id thread_id;
41
void set_thread(Session *session) { thread_id= session->thread_id; }
43
User_level_lock(const unsigned char *key_arg,uint32_t length, ulong id)
44
:key_length(length),count(1),locked(1), thread_id(id)
46
key= (unsigned char*) my_memdup(key_arg,length,MYF(0));
47
pthread_cond_init(&cond,NULL);
50
if (my_hash_insert(&hash_user_locks,(unsigned char*) this))
61
hash_delete(&hash_user_locks,(unsigned char*) this);
64
pthread_cond_destroy(&cond);
66
inline bool initialized() { return key != 0; }
68
friend void item_user_lock_release(User_level_lock *ull);
69
friend unsigned char *ull_get_key(const User_level_lock *ull, size_t *length,
73
unsigned char *ull_get_key(const User_level_lock *ull, size_t *length,
74
bool not_used __attribute__((unused)))
76
*length= ull->key_length;
81
void item_user_lock_release(User_level_lock *ull)
86
pthread_cond_signal(&ull->cond);
94
Check a user level lock.
96
Sets null_value=true on error.
101
0 Already taken, or error
104
int64_t Item_func_is_free_lock::val_int()
107
String *res=args[0]->val_str(&value);
108
User_level_lock *ull;
111
if (!res || !res->length())
117
pthread_mutex_lock(&LOCK_user_locks);
118
ull= (User_level_lock *) hash_search(&hash_user_locks, (unsigned char*) res->ptr(),
119
(size_t) res->length());
120
pthread_mutex_unlock(&LOCK_user_locks);
121
if (!ull || !ull->locked)
126
int64_t Item_func_is_used_lock::val_int()
129
String *res=args[0]->val_str(&value);
130
User_level_lock *ull;
133
if (!res || !res->length())
136
pthread_mutex_lock(&LOCK_user_locks);
137
ull= (User_level_lock *) hash_search(&hash_user_locks, (unsigned char*) res->ptr(),
138
(size_t) res->length());
139
pthread_mutex_unlock(&LOCK_user_locks);
140
if (!ull || !ull->locked)
144
return ull->thread_id;