mirror of
https://github.com/drogonframework/drogon.git
synced 2025-09-10 00:00:38 -04:00
Make CacheMap safely destruct
This commit is contained in:
parent
b87276f4e4
commit
c0a0e74414
@ -110,6 +110,16 @@ public:
|
||||
};
|
||||
~CacheMap(){
|
||||
_loop->invalidateTimer(_timerId);
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(mtx_);
|
||||
_map.clear();
|
||||
}
|
||||
|
||||
for(int i=_wheels.size()-1;i>=0;i--)
|
||||
{
|
||||
_wheels[i].clear();
|
||||
}
|
||||
|
||||
LOG_TRACE<<"CacheMap destruct!";
|
||||
}
|
||||
typedef struct MapValue
|
||||
@ -210,6 +220,7 @@ private:
|
||||
//protected by bucketMutex;
|
||||
if(delay<=0)
|
||||
return;
|
||||
delay = delay/_tickInterval + 1;
|
||||
size_t t=_ticksCounter;
|
||||
for(size_t i=0;i<_wheelsNum;i++)
|
||||
{
|
||||
|
@ -13,7 +13,7 @@ int main()
|
||||
trantor::EventLoopThread loopThread;
|
||||
loopThread.run();
|
||||
|
||||
drogon::CacheMap<std::string,std::string> cache(loopThread.getLoop(),1,3,3);
|
||||
drogon::CacheMap<std::string,std::string> cache(loopThread.getLoop(),0.1,4,30);
|
||||
sleep(3);
|
||||
for(int i=0;i<40;i++)
|
||||
{
|
||||
|
@ -24,7 +24,7 @@ int main()
|
||||
{
|
||||
std::shared_ptr<drogon::CacheMap<std::string,std::string>> cachePtr
|
||||
=std::make_shared<drogon::CacheMap<std::string,std::string>>
|
||||
(loop,1,3,3);
|
||||
(loop,0.1,3,50);
|
||||
main_cachePtr=cachePtr;
|
||||
LOG_DEBUG<<"insert :usecount="<<main_cachePtr.use_count();
|
||||
cachePtr->insert("1","1",3,[=](){
|
||||
|
Loading…
x
Reference in New Issue
Block a user