diff options
author | Alan Conway <aconway@apache.org> | 2007-08-21 23:35:23 +0000 |
---|---|---|
committer | Alan Conway <aconway@apache.org> | 2007-08-21 23:35:23 +0000 |
commit | 9ef0c3dc8bc5ef4af668a3c19f8e254fb5e01ada (patch) | |
tree | b8afa05ed63e9d2d05392df406053c0d69d2fc36 /cpp/src/tests/Serializer.cpp | |
parent | 9ebcf9839197cafe78beb8dfa14b803bd78f5a5e (diff) | |
download | qpid-python-9ef0c3dc8bc5ef4af668a3c19f8e254fb5e01ada.tar.gz |
* src/qpid/sys/Serializer.h, .cpp:
Template Serializer on functor for execute().
Old Serializer equivalent to Serializer<boost::function<void()> >
* src/qpid/broker/BrokerQueue.h, .cpp:
Use hand-written functor for Serializer instead of boost::function.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@568332 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/tests/Serializer.cpp')
-rw-r--r-- | cpp/src/tests/Serializer.cpp | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/cpp/src/tests/Serializer.cpp b/cpp/src/tests/Serializer.cpp index d7345acf06..0135822275 100644 --- a/cpp/src/tests/Serializer.cpp +++ b/cpp/src/tests/Serializer.cpp @@ -38,6 +38,7 @@ using namespace qpid::sys; using namespace qpid::framing; using namespace std; +typedef Serializer<boost::function<void()> > BoostFunctionSerializer; /** Test for concurrent calls */ struct Tester { @@ -61,7 +62,7 @@ struct Tester { } }; -void execute(Serializer& s, Serializer::Task t) +void execute(BoostFunctionSerializer& s, boost::function<void()> t) { s.execute(t); } @@ -69,7 +70,7 @@ void execute(Serializer& s, Serializer::Task t) BOOST_AUTO_TEST_CASE(testSingleThread) { // Verify that we call in the same thread by default. Tester tester; - Serializer s; + BoostFunctionSerializer s; for (int i = 0; i < 100; ++i) execute(s, boost::bind(&Tester::test, &tester)); // All should be executed in this thread. @@ -83,7 +84,7 @@ BOOST_AUTO_TEST_CASE(testSingleThread) { BOOST_AUTO_TEST_CASE(testSingleThreadNoImmediate) { // Verify that we call in different thread if immediate=false. Tester tester; - Serializer s(false); + BoostFunctionSerializer s(false); for (int i = 0; i < 100; ++i) execute(s, boost::bind(&Tester::test, &tester)); { @@ -99,13 +100,13 @@ BOOST_AUTO_TEST_CASE(testSingleThreadNoImmediate) { } struct Caller : public Runnable, public Tester { - Caller(Serializer& s) : serializer(s) {} + Caller(BoostFunctionSerializer& s) : serializer(s) {} void run() { execute(serializer, boost::bind(&Tester::test, this)); } - Serializer& serializer; + BoostFunctionSerializer& serializer; }; BOOST_AUTO_TEST_CASE(testDispatchThread) { - Serializer s; + BoostFunctionSerializer s; Caller caller(s); Thread threads[100]; // Concurrent calls. @@ -121,7 +122,7 @@ BOOST_AUTO_TEST_CASE(testDispatchThread) { } -std::auto_ptr<Serializer> serializer; +std::auto_ptr<BoostFunctionSerializer> serializer; struct CallDispatch : public Runnable { void run() { @@ -136,7 +137,7 @@ void notifyDispatch() { // Use externally created threads. BOOST_AUTO_TEST_CASE(testExternalDispatch) { - serializer.reset(new Serializer(false, ¬ifyDispatch)); + serializer.reset(new BoostFunctionSerializer(false, ¬ifyDispatch)); Tester tester; for (int i = 0; i < 100; ++i) execute(*serializer, boost::bind(&Tester::test, &tester)); |