Browse Source

修正了一些bug,ThreadPoolTest正常了

Ubuntu 15 years ago
parent
commit
833e21e1c3
7 changed files with 22 additions and 17 deletions
  1. 2 2
      .gitignore
  2. 5 4
      SConstruct
  3. 11 0
      Src/Base/Typedefs.h
  4. 1 2
      Src/SConscript
  5. 0 1
      Src/Thread/ThreadPool.cc
  6. 1 0
      Src/Thread/ThreadPool.h
  7. 2 8
      Src/Thread/ThreadPoolTest.cc

+ 2 - 2
.gitignore

@@ -5,5 +5,5 @@
 .sconsign.dblite
 
 .settings/
-dbg/
-opt/
+Dbg/
+Opt/

+ 5 - 4
SConstruct

@@ -20,16 +20,17 @@ env.Append(LIBS=[
 	'glog',
 ])
 
-env['MODE'] = GetOption('mode')
-env['NTEST'] = GetOption('ntest')
-
-if env['MODE'] == 'opt':
+if GetOption('mode') == 'opt':
+	env['MODE'] = 'Opt'
 	env.Append(CCFLAGS='-O2 -g')
 	env.Append(LIBS='tcmalloc')
 else:
+	env['MODE'] = 'Dbg'
 	env.Append(CCFLAGS='-g')
 	env.Append(LIBS='tcmalloc_debug')
 
+env['NTEST'] = GetOption('ntest')
+
 env.Append(CPPPATH=Dir(env['MODE']).abspath)
 
 def Test(env, target, source):

+ 11 - 0
Src/Base/Typedefs.h

@@ -14,7 +14,18 @@ typedef boost::uint64_t uint64;
 // smart_ptr typedef
 typedef boost::shared_ptr<int> IntPtr;
 typedef boost::shared_ptr<std::string> StringPtr;
+
+namespace boost {
+class thread;
+}
 typedef boost::shared_ptr<boost::thread> ThreadPtr;
+
+namespace google {
+namespace protobuf {
+class Service;
+class Message;
+}
+}
 typedef boost::shared_ptr<google::protobuf::Service> ProtobufServicePtr;
 typedef boost::shared_ptr<google::protobuf::Message> ProtobufMessagePtr;
 

+ 1 - 2
Src/SConscript

@@ -1,8 +1,7 @@
 Import('env')
 
 subdirs = [
-	'experimental',
-	'thread',
+	'Thread',
 ]
 
 for subdir in subdirs:

+ 0 - 1
Src/Thread/ThreadPool.cc

@@ -1,4 +1,3 @@
-#include <boost/detail/atomic_count.hpp>
 #include <glog/logging.h>
 #include "Thread/ThreadPool.h"
 

+ 1 - 0
Src/Thread/ThreadPool.h

@@ -5,6 +5,7 @@
 #include <boost/thread.hpp>
 #include <boost/function.hpp>
 #include <boost/bind.hpp>
+#include <boost/detail/atomic_count.hpp>
 #include "Base/Base.h"
 
 namespace Hainan {

+ 2 - 8
Src/Thread/ThreadPoolTest.cc

@@ -9,13 +9,6 @@ namespace Hainan {
 
 class ThreadPoolTest: public testing::Test
 {
-	void SetUp()
-	{
-		pool.Start();
-	}
-	void TearDown()
-	{
-	}
 protected:
 	ThreadPool pool;
 public:
@@ -30,12 +23,13 @@ public:
 
 TEST_F(ThreadPoolTest, Test1)
 {
+	pool.Start();
 	std::vector<int> x(100, 8);
 	std::vector<int> y(100, 9);
 	std::vector<int> z(100, 0);
 	for (int i = 0; i < 100; ++i)
 	{
-		pool.push_task(
+		pool.PushTask(
 				boost::bind(&ThreadPoolTest::Max, this, x[i], y[i], &z[i]));
 	}
 	pool.Stop();