summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndy Schwerin <schwerin@mongodb.com>2015-05-18 17:34:13 -0400
committerAndy Schwerin <schwerin@mongodb.com>2015-05-19 17:00:05 -0400
commite699454322eb5f02cc5ea865421188664382f150 (patch)
tree05e780d075cc12cd42fef033e365bd1f41666197 /src
parent95f2a43a398f07121d04af800bacd139eb43d7cd (diff)
downloadmongo-e699454322eb5f02cc5ea865421188664382f150.tar.gz
SERVER-17310 Add polyfills for types from the <thread>, <mutex> and <condition_variable> headers.
Demonstrate usage in mongo/util/concurrency/ticketholder.{h,cpp}.
Diffstat (limited to 'src')
-rw-r--r--src/mongo/stdx/condition_variable.h40
-rw-r--r--src/mongo/stdx/mutex.h59
-rw-r--r--src/mongo/stdx/thread.h2
-rw-r--r--src/mongo/util/concurrency/ticketholder.cpp10
-rw-r--r--src/mongo/util/concurrency/ticketholder.h10
5 files changed, 110 insertions, 11 deletions
diff --git a/src/mongo/stdx/condition_variable.h b/src/mongo/stdx/condition_variable.h
new file mode 100644
index 00000000000..5a494edf5b4
--- /dev/null
+++ b/src/mongo/stdx/condition_variable.h
@@ -0,0 +1,40 @@
+/**
+ * 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.
+ */
+
+#pragma once
+
+#include <boost/thread/condition_variable.hpp>
+
+namespace mongo {
+namespace stdx {
+
+ using condition_variable = boost::condition_variable;
+ using cv_status = boost::cv_status;
+
+} // namespace stdx
+} // namespace mongo
diff --git a/src/mongo/stdx/mutex.h b/src/mongo/stdx/mutex.h
new file mode 100644
index 00000000000..b495943b8b1
--- /dev/null
+++ b/src/mongo/stdx/mutex.h
@@ -0,0 +1,59 @@
+/**
+ * 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.
+ */
+
+#pragma once
+
+#include <boost/thread/mutex.hpp>
+
+namespace mongo {
+namespace stdx {
+
+ using boost::mutex;
+ using boost::timed_mutex;
+
+ using boost::adopt_lock_t;
+ using boost::defer_lock_t;
+ using boost::try_to_lock_t;
+
+ using boost::lock_guard;
+ using boost::unique_lock;
+
+#if _MSC_VER < 1900
+#define MONGO_STDX_CONSTEXPR const
+#else
+#define MONGO_STDX_CONSTEXPR constexpr
+#endif
+
+ MONGO_STDX_CONSTEXPR adopt_lock_t adopt_lock{};
+ MONGO_STDX_CONSTEXPR defer_lock_t defer_lock{};
+ MONGO_STDX_CONSTEXPR try_to_lock_t try_to_lock{};
+
+#undef MONGO_STDX_CONSTEXPR
+
+} // namespace stdx
+} // namespace mongo
diff --git a/src/mongo/stdx/thread.h b/src/mongo/stdx/thread.h
index 692dfbeb6a1..d38d696d1ff 100644
--- a/src/mongo/stdx/thread.h
+++ b/src/mongo/stdx/thread.h
@@ -33,8 +33,8 @@
namespace mongo {
namespace stdx {
+ using thread = boost::thread;
namespace this_thread = boost::this_thread;
} // namespace stdx
} // namespace mongo
-
diff --git a/src/mongo/util/concurrency/ticketholder.cpp b/src/mongo/util/concurrency/ticketholder.cpp
index 2bda04c5c10..ca0c2560ef0 100644
--- a/src/mongo/util/concurrency/ticketholder.cpp
+++ b/src/mongo/util/concurrency/ticketholder.cpp
@@ -80,7 +80,7 @@ namespace mongo {
}
Status TicketHolder::resize(int newSize) {
- boost::lock_guard<boost::mutex> lk(_resizeMutex);
+ stdx::lock_guard<stdx::mutex> lk(_resizeMutex);
if (newSize < 5)
return Status(ErrorCodes::BadValue,
@@ -127,12 +127,12 @@ namespace mongo {
TicketHolder::~TicketHolder() = default;
bool TicketHolder::tryAcquire() {
- boost::lock_guard<boost::mutex> lk( _mutex );
+ stdx::lock_guard<stdx::mutex> lk( _mutex );
return _tryAcquire();
}
void TicketHolder::waitForTicket() {
- boost::unique_lock<boost::mutex> lk( _mutex );
+ stdx::unique_lock<stdx::mutex> lk( _mutex );
while( ! _tryAcquire() ) {
_newTicket.wait( lk );
@@ -141,14 +141,14 @@ namespace mongo {
void TicketHolder::release() {
{
- boost::lock_guard<boost::mutex> lk( _mutex );
+ stdx::lock_guard<stdx::mutex> lk( _mutex );
_num++;
}
_newTicket.notify_one();
}
Status TicketHolder::resize( int newSize ) {
- boost::lock_guard<boost::mutex> lk( _mutex );
+ stdx::lock_guard<stdx::mutex> lk( _mutex );
int used = _outof.load() - _num;
if ( used > newSize ) {
diff --git a/src/mongo/util/concurrency/ticketholder.h b/src/mongo/util/concurrency/ticketholder.h
index e9058675ec9..31d8a989fde 100644
--- a/src/mongo/util/concurrency/ticketholder.h
+++ b/src/mongo/util/concurrency/ticketholder.h
@@ -30,9 +30,9 @@
#include <semaphore.h>
#endif
-#include <boost/thread/condition_variable.hpp>
-
#include "mongo/base/disallow_copying.h"
+#include "mongo/stdx/condition_variable.h"
+#include "mongo/stdx/mutex.h"
#include "mongo/util/concurrency/mutex.h"
namespace mongo {
@@ -63,14 +63,14 @@ namespace mongo {
// You can read _outof without a lock, but have to hold _resizeMutex to change.
AtomicInt32 _outof;
- boost::mutex _resizeMutex;
+ stdx::mutex _resizeMutex;
#else
bool _tryAcquire();
AtomicInt32 _outof;
int _num;
- mongo::mutex _mutex;
- boost::condition_variable_any _newTicket;
+ stdx::mutex _mutex;
+ stdx::condition_variable _newTicket;
#endif
};