00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #pragma once
00019
00020 #include <boost/thread/mutex.hpp>
00021 #include <boost/thread/shared_mutex.hpp>
00022 #include <boost/thread/condition_variable.hpp>
00023
00024 #include <drizzled/visibility.h>
00025 #include <drizzled/common_fwd.h>
00026
00027 namespace drizzled {
00028
00029 extern uint64_t max_write_lock_count;
00030 extern uint64_t table_lock_wait_timeout;
00031
00032 enum thr_lock_type
00033 {
00034 TL_IGNORE=-1,
00035
00036 TL_UNLOCK,
00037
00038 TL_READ,
00039 TL_READ_WITH_SHARED_LOCKS,
00040
00041 TL_READ_NO_INSERT,
00042
00043
00044
00045
00046
00047 TL_WRITE_ALLOW_WRITE,
00048
00049
00050
00051
00052
00053 TL_WRITE_ALLOW_READ,
00054
00055
00056
00057
00058 TL_WRITE_CONCURRENT_INSERT,
00059
00060
00061
00062
00063 TL_WRITE_DEFAULT,
00064
00065 TL_WRITE,
00066
00067 TL_WRITE_ONLY
00068 };
00069
00070 enum enum_thr_lock_result
00071 {
00072 THR_LOCK_SUCCESS= 0,
00073 THR_LOCK_ABORTED= 1,
00074 THR_LOCK_WAIT_TIMEOUT= 2,
00075 THR_LOCK_DEADLOCK= 3
00076 };
00077
00078
00079
00080
00081
00082
00083 struct THR_LOCK_INFO
00084 {
00085 uint64_t thread_id;
00086 uint32_t n_cursors;
00087
00088 THR_LOCK_INFO() :
00089 thread_id(0),
00090 n_cursors(0)
00091 { }
00092
00093 void init();
00094
00095 };
00096
00097
00098
00099
00100
00101
00102
00103 struct THR_LOCK_OWNER
00104 {
00105 THR_LOCK_INFO *info;
00106
00107 THR_LOCK_OWNER() :
00108 info(NULL)
00109 { }
00110
00111 };
00112
00113 struct THR_LOCK;
00114 struct THR_LOCK_DATA;
00115
00116 struct DRIZZLED_API THR_LOCK_DATA
00117 {
00118 THR_LOCK_OWNER *owner;
00119 struct THR_LOCK_DATA *next,**prev;
00120 struct THR_LOCK *lock;
00121 boost::condition_variable_any *cond;
00122 enum thr_lock_type type;
00123 void *status_param;
00124
00125 THR_LOCK_DATA() :
00126 owner(0),
00127 next(0),
00128 prev(0),
00129 lock(0),
00130 cond(0),
00131 type(TL_UNLOCK),
00132 status_param(0)
00133 { }
00134
00135 void init(THR_LOCK*, void *status_param= NULL);
00136 };
00137
00138 struct st_lock_list
00139 {
00140 THR_LOCK_DATA *data,**last;
00141
00142 st_lock_list() :
00143 data(0),
00144 last(0)
00145 { }
00146 };
00147
00148 struct THR_LOCK
00149 {
00150 private:
00151 boost::mutex mutex;
00152 public:
00153 struct st_lock_list read_wait;
00154 struct st_lock_list read;
00155 struct st_lock_list write_wait;
00156 struct st_lock_list write;
00157
00158 uint32_t write_lock_count;
00159 uint32_t read_no_write_count;
00160
00161 THR_LOCK() :
00162 write_lock_count(0),
00163 read_no_write_count(0)
00164 { }
00165
00166 void abort_locks();
00167 bool abort_locks_for_thread(uint64_t thread);
00168
00169 void lock()
00170 {
00171 mutex.lock();
00172 }
00173
00174 void unlock()
00175 {
00176 mutex.unlock();
00177 }
00178
00179 boost::mutex *native_handle()
00180 {
00181 return &mutex;
00182 }
00183 };
00184
00185 DRIZZLED_API void thr_lock_init(THR_LOCK *lock);
00186 enum_thr_lock_result thr_multi_lock(Session&, THR_LOCK_DATA**, uint32_t count, THR_LOCK_OWNER*);
00187 void thr_multi_unlock(THR_LOCK_DATA**, uint32_t count);
00188
00189 }
00190