diff options
author | Robert Guo <robert.guo@10gen.com> | 2017-08-24 09:48:21 -0400 |
---|---|---|
committer | Robert Guo <robert.guo@10gen.com> | 2017-08-24 09:48:21 -0400 |
commit | 82b9a76cd28d1687583c2ff98c63897c4d434668 (patch) | |
tree | 2cb659a273a71920592ecf0b7789c5d769b55310 /src/mongo/util/concurrency | |
parent | 6826796245219c5aaa9209487413b60afebb1bb7 (diff) | |
download | mongo-82b9a76cd28d1687583c2ff98c63897c4d434668.tar.gz |
Revert "SERVER-30748 WithLock to replace _inlock"
This reverts commit 200d56c6eec8acdc6cddf0541f31c60f4ed2e760.
Diffstat (limited to 'src/mongo/util/concurrency')
-rw-r--r-- | src/mongo/util/concurrency/with_lock.h | 98 |
1 files changed, 0 insertions, 98 deletions
diff --git a/src/mongo/util/concurrency/with_lock.h b/src/mongo/util/concurrency/with_lock.h deleted file mode 100644 index d26c675e293..00000000000 --- a/src/mongo/util/concurrency/with_lock.h +++ /dev/null @@ -1,98 +0,0 @@ -/** Copyright 2017 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. - */ - -#pragma once - -#include "mongo/stdx/mutex.h" -#include "mongo/util/invariant.h" - -#include <utility> - -namespace mongo { - -/** - * WithLock is an attestion to pass as an argument to functions that must be called only while - * holding a lock, as a rigorous alternative to an unchecked naming convention and/or stern - * comments. It helps prevent a common usage error. - * - * It may be used to modernize code from (something like) this - * - * // Member _mutex MUST be held when calling this: - * void _clobber_inlock(OperationContext* opCtx) { - * _stuff = makeStuff(opCtx); - * } - * - * into - * - * void _clobber(WithLock, OperationContext* opCtx) { - * _stuff = makeStuff(opCtx); - * } - * - * A call to such a function looks like this: - * - * stdx::lock_guard<stdx::mutex> lk(_mutex); - * _clobber(lk, opCtx); // instead of _clobber_inlock(opCtx) - * - * Note that the formal argument need not (and should not) be named unless it is needed to pass - * the attestation along to another function: - * - * void _clobber(WithLock lock, OperationContext* opCtx) { - * _really_clobber(lock, opCtx); - * } - * - */ -struct WithLock { - template <typename Mutex> - WithLock(stdx::lock_guard<Mutex> const&) noexcept {} - - template <typename Mutex> - WithLock(stdx::unique_lock<Mutex> const& lock) noexcept { - invariant(lock.owns_lock()); - } - - // Pass by value is OK. - WithLock(WithLock const&) noexcept {} - WithLock(WithLock&&) noexcept {} - - WithLock() = delete; - - // No assigning WithLocks. - void operator=(WithLock const&) = delete; - void operator=(WithLock&&) = delete; - - // No accidentally moving a unique_lock<> in. - template <typename Mutex> - WithLock(stdx::unique_lock<Mutex>&&) = delete; -}; - -} // namespace mongo - -namespace std { -// No moving a WithLock: -template <> -mongo::WithLock&& move<mongo::WithLock>(mongo::WithLock&&) = delete; -} // namespace std |