| 87 | void Recycle::unlock() { pthread_mutex_unlock(&_recycle_mutex); } |
| 88 | |
| 89 | void* Recycle::recycle_func(void* arg) { |
| 90 | Recycle* recycle = reinterpret_cast<Recycle*>(arg); |
| 91 | std::queue<VirtualDict*>& recycle_list = recycle->_recycle_list; |
| 92 | |
| 93 | while (recycle->_running) { |
| 94 | recycle->lock(); |
| 95 | if (recycle_list.empty()) { |
| 96 | recycle->unlock(); |
| 97 | sleep(1); |
| 98 | continue; |
| 99 | } |
| 100 | |
| 101 | VirtualDict* dict = recycle_list.front(); |
| 102 | recycle_list.pop(); |
| 103 | recycle->unlock(); |
| 104 | |
| 105 | while (dict->atom_seek_num() != 0) { |
| 106 | sleep(1); |
| 107 | } |
| 108 | |
| 109 | int ret = dict->destroy(); |
| 110 | if (ret != 0) { |
| 111 | LOG(WARNING) << "destroy dict failed"; |
| 112 | } |
| 113 | |
| 114 | delete dict; |
| 115 | } |
| 116 | |
| 117 | return NULL; |
| 118 | } |
| 119 | |
| 120 | } // namespace mcube |
| 121 | } // namespace rec |