00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 #include "w_defines.h"
00055
00056
00057
00058 #include "store_latch_manager.h"
00059 #include <vector>
00060
00061
00062
00063 #if defined(USE_OCC_LOCK_SLMGR)
00064 #define OCCWRITE .write_lock()
00065 #define OCCREAD .read_lock()
00066 #else
00067 #define OCCWRITE
00068 #define OCCREAD
00069 #endif
00070
00071 void store_latch_manager::shutdown()
00072 {
00073 CRITICAL_SECTION(cs, _latch_lock OCCWRITE);
00074 for(latch_map::iterator it=_latches.begin(); it != _latches.end(); ++it)
00075 {
00076 w_assert1(it->second->mode() == LATCH_NL);
00077 delete it->second;
00078 }
00079 _latches.clear();
00080 }
00081
00082 latch_t &store_latch_manager::find_latch(stid_t const &store)
00083 {
00084 latch_t *latch=NULL;
00085 {
00086 CRITICAL_SECTION(cs, _latch_lock OCCREAD);
00087 latch_map::iterator pos=_latches.find(store);
00088 if(pos != _latches.end()) {
00089 stid_t xxx = pos->first;
00090 w_assert1(store==xxx);
00091 latch=pos->second;
00092 return *latch;
00093 }
00094 }
00095
00096
00097 CRITICAL_SECTION(cs, _latch_lock OCCWRITE);
00098 if( (latch=_latches[store]) ) {
00099 return *latch;
00100 }
00101
00102 latch = new latch_t;
00103 _latches[store] = latch;
00104 return *latch;
00105 }
00106
00107
00108 void store_latch_manager::_destroy_latches(stid_t const &store)
00109 {
00110 latch_map::iterator pos=_latches.find(store);
00111 if(pos != _latches.end())
00112 {
00113 w_assert1(store == pos->first);
00114 latch_t *latch = pos->second;
00115 _latches.erase(pos);
00116 delete latch;
00117 }
00118
00119 }
00120
00121 void store_latch_manager::destroy_latches(stid_t const &store)
00122 {
00123 CRITICAL_SECTION(cs, _latch_lock OCCWRITE);
00124 _destroy_latches(store);
00125 }
00126
00127
00128 void store_latch_manager::destroy_latches(vid_t const &vol)
00129 {
00130 unsigned int i=0;
00131 std::vector<stid_t> _tmp;
00132 _tmp.reserve(30);
00133
00134 CRITICAL_SECTION(cs, _latch_lock OCCWRITE);
00135
00136 {
00137 for(
00138 latch_map::iterator pos=_latches.begin();
00139 pos != _latches.end();
00140 pos++
00141 )
00142 {
00143 stid_t stid = pos->first;
00144 if(stid.vol == vol) {
00145 _tmp.push_back(stid);
00146 }
00147 }
00148 }
00149
00150
00151 for(i=0; i < _tmp.size(); i++)
00152 {
00153 _destroy_latches(_tmp[i]);
00154 }
00155 }
00156
00157 store_latch_manager::~store_latch_manager()
00158 {
00159 shutdown();
00160 }