diff options
Diffstat (limited to 'src/mongo')
-rw-r--r-- | src/mongo/db/clientcursor.h | 5 | ||||
-rw-r--r-- | src/mongo/dbtests/threadedtests.cpp | 1 | ||||
-rw-r--r-- | src/mongo/pch.h | 7 | ||||
-rw-r--r-- | src/mongo/s/chunk.cpp | 1 | ||||
-rw-r--r-- | src/mongo/s/chunk.h | 1 | ||||
-rw-r--r-- | src/mongo/s/d_logic.h | 1 | ||||
-rw-r--r-- | src/mongo/s/d_state.cpp | 1 | ||||
-rw-r--r-- | src/mongo/scripting/engine_spidermonkey.cpp | 6 | ||||
-rw-r--r-- | src/mongo/util/background.cpp | 2 | ||||
-rw-r--r-- | src/mongo/util/concurrency/msg.h | 2 | ||||
-rw-r--r-- | src/mongo/util/concurrency/mvar.h | 3 | ||||
-rw-r--r-- | src/mongo/util/concurrency/thread_pool.cpp | 3 | ||||
-rw-r--r-- | src/mongo/util/concurrency/thread_pool.h | 9 | ||||
-rw-r--r-- | src/mongo/util/concurrency/ticketholder.h | 110 | ||||
-rw-r--r-- | src/mongo/util/file_allocator.h | 8 | ||||
-rw-r--r-- | src/mongo/util/goodies.h | 88 | ||||
-rw-r--r-- | src/mongo/util/net/listen.h | 1 | ||||
-rw-r--r-- | src/mongo/util/net/message_server_port.cpp | 1 | ||||
-rw-r--r-- | src/mongo/util/optime.h | 2 |
19 files changed, 149 insertions, 103 deletions
diff --git a/src/mongo/db/clientcursor.h b/src/mongo/db/clientcursor.h index e413bb1862e..039b6f56efd 100644 --- a/src/mongo/db/clientcursor.h +++ b/src/mongo/db/clientcursor.h @@ -24,7 +24,10 @@ #pragma once -#include "../pch.h" +#include "pch.h" + +#include <boost/thread/recursive_mutex.hpp> + #include "cursor.h" #include "jsobj.h" #include "../util/net/message.h" diff --git a/src/mongo/dbtests/threadedtests.cpp b/src/mongo/dbtests/threadedtests.cpp index a1db20bee58..da4ec475736 100644 --- a/src/mongo/dbtests/threadedtests.cpp +++ b/src/mongo/dbtests/threadedtests.cpp @@ -30,6 +30,7 @@ #include "../util/concurrency/synchronization.h" #include "../util/concurrency/qlock.h" #include "dbtests.h" +#include "mongo/util/concurrency/ticketholder.h" namespace mongo { void testNonGreedy(); diff --git a/src/mongo/pch.h b/src/mongo/pch.h index 652cd079994..4dc3c99369a 100644 --- a/src/mongo/pch.h +++ b/src/mongo/pch.h @@ -74,14 +74,7 @@ #include <boost/smart_ptr.hpp> #include <boost/function.hpp> #include <boost/bind.hpp> -#include <boost/thread/tss.hpp> -#include <boost/detail/endian.hpp> #include <boost/version.hpp> -#include <boost/thread/thread.hpp> -#include <boost/thread/condition.hpp> -#include <boost/thread/recursive_mutex.hpp> -#include <boost/thread/xtime.hpp> - #include "mongo/client/redef_macros.h" diff --git a/src/mongo/s/chunk.cpp b/src/mongo/s/chunk.cpp index 6697b73dfaf..11a734650d4 100644 --- a/src/mongo/s/chunk.cpp +++ b/src/mongo/s/chunk.cpp @@ -31,6 +31,7 @@ #include "grid.h" #include "strategy.h" #include "client.h" +#include "mongo/util/concurrency/ticketholder.h" namespace mongo { diff --git a/src/mongo/s/chunk.h b/src/mongo/s/chunk.h index 0cfdb135f9e..8d9edab1ae4 100644 --- a/src/mongo/s/chunk.h +++ b/src/mongo/s/chunk.h @@ -26,6 +26,7 @@ #include "shardkey.h" #include "shard.h" #include "util.h" +#include "mongo/util/concurrency/ticketholder.h" namespace mongo { diff --git a/src/mongo/s/d_logic.h b/src/mongo/s/d_logic.h index 7c5bbfb52e9..48a3e48cdb2 100644 --- a/src/mongo/s/d_logic.h +++ b/src/mongo/s/d_logic.h @@ -24,6 +24,7 @@ #include "d_chunk_manager.h" #include "util.h" +#include "mongo/util/concurrency/ticketholder.h" namespace mongo { diff --git a/src/mongo/s/d_state.cpp b/src/mongo/s/d_state.cpp index 2f81f1aed09..47a0855f249 100644 --- a/src/mongo/s/d_state.cpp +++ b/src/mongo/s/d_state.cpp @@ -37,6 +37,7 @@ #include "shard.h" #include "d_logic.h" #include "config.h" +#include "mongo/util/concurrency/ticketholder.h" using namespace std; diff --git a/src/mongo/scripting/engine_spidermonkey.cpp b/src/mongo/scripting/engine_spidermonkey.cpp index 2b6b36a298f..2572ba2539a 100644 --- a/src/mongo/scripting/engine_spidermonkey.cpp +++ b/src/mongo/scripting/engine_spidermonkey.cpp @@ -16,7 +16,11 @@ */ #include "pch.h" -#include "engine_spidermonkey.h" + +#include "mongo/scripting/engine_spidermonkey.h" + +#include <boost/thread/recursive_mutex.hpp> + #include "mongo/util/mongoutils/str.h" #ifndef _WIN32 diff --git a/src/mongo/util/background.cpp b/src/mongo/util/background.cpp index 3d675421a4d..854060e6370 100644 --- a/src/mongo/util/background.cpp +++ b/src/mongo/util/background.cpp @@ -17,6 +17,8 @@ #include "pch.h" +#include <boost/thread/condition.hpp> + #include "concurrency/mutex.h" #include "concurrency/spin_lock.h" diff --git a/src/mongo/util/concurrency/msg.h b/src/mongo/util/concurrency/msg.h index 0b9a7c5048c..6e8a3980246 100644 --- a/src/mongo/util/concurrency/msg.h +++ b/src/mongo/util/concurrency/msg.h @@ -19,6 +19,8 @@ #pragma once #include <deque> + +#include <boost/thread/condition.hpp> #include "task.h" namespace mongo { diff --git a/src/mongo/util/concurrency/mvar.h b/src/mongo/util/concurrency/mvar.h index bc1855a85cc..d5ceb28ce30 100644 --- a/src/mongo/util/concurrency/mvar.h +++ b/src/mongo/util/concurrency/mvar.h @@ -17,6 +17,9 @@ #pragma once +#include <boost/thread/recursive_mutex.hpp> +#include <boost/thread/condition.hpp> + namespace mongo { /* This is based on haskell's MVar synchronization primitive: diff --git a/src/mongo/util/concurrency/thread_pool.cpp b/src/mongo/util/concurrency/thread_pool.cpp index b64a904cd4a..78eb05556a9 100644 --- a/src/mongo/util/concurrency/thread_pool.cpp +++ b/src/mongo/util/concurrency/thread_pool.cpp @@ -17,6 +17,9 @@ */ #include "pch.h" + +#include <boost/thread/thread.hpp> + #include "thread_pool.h" #include "mvar.h" diff --git a/src/mongo/util/concurrency/thread_pool.h b/src/mongo/util/concurrency/thread_pool.h index ea2f801b63c..62a9cac57d1 100644 --- a/src/mongo/util/concurrency/thread_pool.h +++ b/src/mongo/util/concurrency/thread_pool.h @@ -17,8 +17,11 @@ #pragma once -#include <boost/function.hpp> +#include <list> + #include <boost/bind.hpp> +#include <boost/function.hpp> +#include <boost/thread/condition.hpp> namespace mongo { @@ -63,8 +66,8 @@ namespace mongo { mongo::mutex _mutex; boost::condition _condition; - list<Worker*> _freeWorkers; //used as LIFO stack (always front) - list<Task> _tasks; //used as FIFO queue (push_back, pop_front) + std::list<Worker*> _freeWorkers; //used as LIFO stack (always front) + std::list<Task> _tasks; //used as FIFO queue (push_back, pop_front) int _tasksRemaining; // in queue + currently processing int _nThreads; // only used for sanity checking. could be removed in the future. diff --git a/src/mongo/util/concurrency/ticketholder.h b/src/mongo/util/concurrency/ticketholder.h new file mode 100644 index 00000000000..036d33fb9ef --- /dev/null +++ b/src/mongo/util/concurrency/ticketholder.h @@ -0,0 +1,110 @@ +/* Copyright 2009 10gen Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#pragma once + +#include <boost/thread/condition_variable.hpp> + +#include "mongo/util/concurrency/mutex.h" + +namespace mongo { + + class TicketHolder { + public: + TicketHolder( int num ) : _mutex("TicketHolder") { + _outof = num; + _num = num; + } + + bool tryAcquire() { + scoped_lock lk( _mutex ); + return _tryAcquire(); + } + + void waitForTicket() { + scoped_lock lk( _mutex ); + + while( ! _tryAcquire() ) { + _newTicket.wait( lk.boost() ); + } + } + + void release() { + { + scoped_lock lk( _mutex ); + _num++; + } + _newTicket.notify_one(); + } + + void resize( int newSize ) { + { + scoped_lock lk( _mutex ); + + int used = _outof - _num; + if ( used > newSize ) { + cout << "ERROR: can't resize since we're using (" << used << ") more than newSize(" << newSize << ")" << endl; + return; + } + + _outof = newSize; + _num = _outof - used; + } + + // Potentially wasteful, but easier to see is correct + _newTicket.notify_all(); + } + + int available() const { + return _num; + } + + int used() const { + return _outof - _num; + } + + int outof() const { return _outof; } + + private: + + bool _tryAcquire(){ + if ( _num <= 0 ) { + if ( _num < 0 ) { + cerr << "DISASTER! in TicketHolder" << endl; + } + return false; + } + _num--; + return true; + } + + int _outof; + int _num; + mongo::mutex _mutex; + boost::condition_variable_any _newTicket; + }; + + class TicketHolderReleaser { + public: + TicketHolderReleaser( TicketHolder * holder ) { + _holder = holder; + } + + ~TicketHolderReleaser() { + _holder->release(); + } + private: + TicketHolder * _holder; + }; +} diff --git a/src/mongo/util/file_allocator.h b/src/mongo/util/file_allocator.h index 27dda177440..aa6abd21d21 100644 --- a/src/mongo/util/file_allocator.h +++ b/src/mongo/util/file_allocator.h @@ -15,7 +15,11 @@ * limitations under the License. */ -#include "../pch.h" +#include "pch.h" + +#include <list> + +#include <boost/thread/condition.hpp> namespace mongo { @@ -75,7 +79,7 @@ namespace mongo { mutable mongo::mutex _pendingMutex; mutable boost::condition _pendingUpdated; - list< string > _pending; + std::list< string > _pending; mutable map< string, long > _pendingSize; bool _failed; diff --git a/src/mongo/util/goodies.h b/src/mongo/util/goodies.h index 3dcb74ef9d5..26e62d59396 100644 --- a/src/mongo/util/goodies.h +++ b/src/mongo/util/goodies.h @@ -154,94 +154,6 @@ namespace mongo { typedef void *HANDLE; #endif - class TicketHolder { - public: - TicketHolder( int num ) : _mutex("TicketHolder") { - _outof = num; - _num = num; - } - - bool tryAcquire() { - scoped_lock lk( _mutex ); - return _tryAcquire(); - } - - void waitForTicket() { - scoped_lock lk( _mutex ); - - while( ! _tryAcquire() ) { - _newTicket.wait( lk.boost() ); - } - } - - void release() { - { - scoped_lock lk( _mutex ); - _num++; - } - _newTicket.notify_one(); - } - - void resize( int newSize ) { - { - scoped_lock lk( _mutex ); - - int used = _outof - _num; - if ( used > newSize ) { - cout << "ERROR: can't resize since we're using (" << used << ") more than newSize(" << newSize << ")" << endl; - return; - } - - _outof = newSize; - _num = _outof - used; - } - - // Potentially wasteful, but easier to see is correct - _newTicket.notify_all(); - } - - int available() const { - return _num; - } - - int used() const { - return _outof - _num; - } - - int outof() const { return _outof; } - - private: - - bool _tryAcquire(){ - if ( _num <= 0 ) { - if ( _num < 0 ) { - cerr << "DISASTER! in TicketHolder" << endl; - } - return false; - } - _num--; - return true; - } - - int _outof; - int _num; - mongo::mutex _mutex; - boost::condition_variable_any _newTicket; - }; - - class TicketHolderReleaser { - public: - TicketHolderReleaser( TicketHolder * holder ) { - _holder = holder; - } - - ~TicketHolderReleaser() { - _holder->release(); - } - private: - TicketHolder * _holder; - }; - /** * this is a thread safe string diff --git a/src/mongo/util/net/listen.h b/src/mongo/util/net/listen.h index 234f5fad24c..c69f3b764f9 100644 --- a/src/mongo/util/net/listen.h +++ b/src/mongo/util/net/listen.h @@ -18,6 +18,7 @@ #pragma once #include "sock.h" +#include "mongo/util/concurrency/ticketholder.h" namespace mongo { diff --git a/src/mongo/util/net/message_server_port.cpp b/src/mongo/util/net/message_server_port.cpp index edb41bba37a..2dd0821cf3d 100644 --- a/src/mongo/util/net/message_server_port.cpp +++ b/src/mongo/util/net/message_server_port.cpp @@ -27,6 +27,7 @@ #include "../../db/cmdline.h" #include "../../db/lasterror.h" #include "../../db/stats/counters.h" +#include "mongo/util/concurrency/ticketholder.h" #ifdef __linux__ // TODO: consider making this ifndef _WIN32 # include <sys/resource.h> diff --git a/src/mongo/util/optime.h b/src/mongo/util/optime.h index 52f81b8e022..e5d5bb535d5 100644 --- a/src/mongo/util/optime.h +++ b/src/mongo/util/optime.h @@ -17,7 +17,7 @@ #pragma once -//#include "../db/concurrency.h" +#include <boost/thread/condition.hpp> namespace mongo { void exitCleanly( ExitCode code ); |