From a4fe773cba66a94513ce266010050ecbfa5f5210 Mon Sep 17 00:00:00 2001 From: Michael Kolupaev Date: Fri, 22 Feb 2013 12:18:08 +0000 Subject: [PATCH] Merge --- dbms/include/DB/Storages/StoragePtr.h | 5 +++++ dbms/src/Storages/StorageChunkMerger.cpp | 11 +++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/dbms/include/DB/Storages/StoragePtr.h b/dbms/include/DB/Storages/StoragePtr.h index 103b572c4ee..74ce9e331e3 100644 --- a/dbms/include/DB/Storages/StoragePtr.h +++ b/dbms/include/DB/Storages/StoragePtr.h @@ -52,6 +52,11 @@ public: return ptr->storage.get(); } + size_t use_count() const + { + return ptr.use_count(); + } + bool operator == (const IStorage * p) const { return get() == p; diff --git a/dbms/src/Storages/StorageChunkMerger.cpp b/dbms/src/Storages/StorageChunkMerger.cpp index 3de6aa88249..fba4f6e475f 100644 --- a/dbms/src/Storages/StorageChunkMerger.cpp +++ b/dbms/src/Storages/StorageChunkMerger.cpp @@ -151,16 +151,15 @@ void StorageChunkMerger::dropImpl() StorageChunkMerger::~StorageChunkMerger() { - if (!thread_should_quit) - { - thread_should_quit = true; - merge_thread.join(); - } + merge_thread.detach(); } void StorageChunkMerger::mergeThread() { - while (!thread_should_quit) + /// Не дает удалить this посреди итерации. + StoragePtr this_ptr = thisPtr(); + + while (!thread_should_quit && this_ptr.use_count() > 1) { bool merged = false; bool error = true;