瀏覽代碼

增加线程池接口

tanghai 15 年之前
父節點
當前提交
8cddb62e42
共有 3 個文件被更改,包括 23 次插入2 次删除
  1. 3 1
      Src/Thread/ThreadPool.h
  2. 19 0
      Src/Thread/ThreadPoolIf.h
  3. 1 1
      Src/Thread/ThreadPoolTest.cc

+ 3 - 1
Src/Thread/ThreadPool.h

@@ -6,10 +6,11 @@
 #include <boost/function.hpp>
 #include <boost/detail/atomic_count.hpp>
 #include "Base/Base.h"
+#include "Thread/ThreadPoolIf.h"
 
 namespace Hainan {
 
-class ThreadPool: private boost::noncopyable
+class ThreadPool: public ThreadPoolIf, private boost::noncopyable
 {
 private:
 	int thread_num_;
@@ -25,6 +26,7 @@ private:
 public:
 	ThreadPool(int num = 0);
 	~ThreadPool();
+
 	void Start();
 	void Stop();
 	bool PushTask(boost::function<void (void)> task);

+ 19 - 0
Src/Thread/ThreadPoolIf.h

@@ -0,0 +1,19 @@
+#ifndef THREAD_THREAD_POOL_IF_H
+#define THREAD_THREAD_POOL_IF_H
+
+namespace Hainan {
+
+class ThreadPoolIf
+{
+public:
+    virtual void Start()
+    {};
+    virtual void Stop()
+    {};
+    virtual bool PushTask(boost::function<void (void)> task)
+    {};
+};
+
+} // namespace Hainan
+
+#endif // THREAD_THREAD_POOL_IF_H

+ 1 - 1
Src/Thread/ThreadPoolTest.cc

@@ -35,7 +35,7 @@ TEST_F(ThreadPoolTest, Test1)
 	pool_.Stop();
 	for (int i = 0; i < 100; ++i)
 	{
-		ASSERT_EQ(9, z[i])<< "i = " << i;
+		ASSERT_EQ(9, z[i]) << "i = " << i;
 	}
 }
 } // namespace Hainan