diff options
author | Randolph Tan <randolph@10gen.com> | 2015-04-29 16:19:04 -0400 |
---|---|---|
committer | Randolph Tan <randolph@10gen.com> | 2015-05-05 11:15:53 -0400 |
commit | c4d7978fc00f5771ef3d6b65baf4375434df8999 (patch) | |
tree | 406ea1bed09a6c40a31c910804aebac37b9eb294 /src/mongo/s/catalog/dist_lock_manager.cpp | |
parent | 6923cb27e54fdaa10ad33748c472c5cf6e557630 (diff) | |
download | mongo-c4d7978fc00f5771ef3d6b65baf4375434df8999.tar.gz |
SERVER-17592 Move legacy dist lock code under catalog
Diffstat (limited to 'src/mongo/s/catalog/dist_lock_manager.cpp')
-rw-r--r-- | src/mongo/s/catalog/dist_lock_manager.cpp | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/src/mongo/s/catalog/dist_lock_manager.cpp b/src/mongo/s/catalog/dist_lock_manager.cpp new file mode 100644 index 00000000000..7803feb7423 --- /dev/null +++ b/src/mongo/s/catalog/dist_lock_manager.cpp @@ -0,0 +1,77 @@ +/** + * Copyright (C) 2015 MongoDB Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * As a special exception, the copyright holders give permission to link the + * code of portions of this program with the OpenSSL library under certain + * conditions as described in each individual source file and distribute + * linked combinations including the program with the OpenSSL library. You + * must comply with the GNU Affero General Public License in all respects for + * all of the code used other than as permitted herein. If you modify file(s) + * with this exception, you may extend this exception to your version of the + * file(s), but you are not obligated to do so. If you do not wish to do so, + * delete this exception statement from your version. If you delete this + * exception statement from all source files in the program, then also delete + * it in the license file. + */ + +#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kSharding + +#include "mongo/platform/basic.h" + +#include "mongo/s/catalog/dist_lock_manager.h" + +#include <memory> + +namespace mongo { + + DistLockManager::ScopedDistLock::ScopedDistLock(): _lockManager(nullptr) { + } + + DistLockManager::ScopedDistLock::ScopedDistLock(DistLockHandle lockHandle, + DistLockManager* lockManager): + _lockID(std::move(lockHandle)), _lockManager(lockManager) { + } + + DistLockManager::ScopedDistLock::~ScopedDistLock() { + if (_lockManager) { + _lockManager->unlock(_lockID); + } + } + + DistLockManager::ScopedDistLock::ScopedDistLock(ScopedDistLock&& other) { + *this = std::move(other); + } + + DistLockManager::ScopedDistLock& + DistLockManager::ScopedDistLock::operator=(ScopedDistLock&& other) { + if (this != &other) { + _lockID = std::move(other._lockID); + _lockManager = other._lockManager; + other._lockManager = nullptr; + } + + return *this; + } + + Status DistLockManager::ScopedDistLock::checkStatus() { + if (!_lockManager) { + return Status(ErrorCodes::IllegalOperation, + "no lock manager, lock was not acquired"); + } + + return _lockManager->checkStatus(_lockID); + } + +} |