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