Просмотр исходного кода

修改了代码风格,所有的类和函数名均采用boost库的命名风格,即类和
函数名全小写,以下划线分割,test文件为了保持与gtest一致,采用
gtest的风格,类和函数名大写开头,以大写字母分割

tanghai 15 лет назад
Родитель
Сommit
c8f77a6dd2
3 измененных файлов с 21 добавлено и 21 удалено
  1. 8 8
      src/thread/thread_pool.cc
  2. 8 8
      src/thread/thread_pool.h
  3. 5 5
      src/thread/thread_pool_test.cc

+ 8 - 8
src/thread/thread_pool.cc

@@ -3,27 +3,27 @@
 
 namespace hainan {
 
-ThreadPool::ThreadPool() :
+thread_pool::thread_pool() :
 	num(0), running(false), work_num(0)
 {
 }
-ThreadPool::~ThreadPool()
+thread_pool::~thread_pool()
 {
 }
 
-void ThreadPool::Start()
+void thread_pool::start()
 {
 	running = true;
 	for (int i = 0; i < num; ++i)
 	{
-		thread_ptr t(new thread(bind(&ThreadPool::Runner, this)));
+		thread_ptr t(new thread(bind(&thread_pool::runner, this)));
 		threads.push_back(t);
 		t->detach();
 	}
 	work_num = num;
 }
 
-void ThreadPool::Stop()
+void thread_pool::stop()
 {
 	VLOG(3)<< "Stop";
 	mutex::scoped_lock lock(mtx);
@@ -36,7 +36,7 @@ void ThreadPool::Stop()
 	}
 }
 
-void ThreadPool::Runner()
+void thread_pool::runner()
 {
 	VLOG(3) << "thread start";
 	bool continued = true;
@@ -77,7 +77,7 @@ void ThreadPool::Runner()
 	}
 }
 
-bool ThreadPool::PushTask(function<void (void)> task)
+bool thread_pool::push_task(function<void (void)> task)
 {
 	VLOG(3) << "push task";
 	{
@@ -93,7 +93,7 @@ bool ThreadPool::PushTask(function<void (void)> task)
 	return true;
 }
 
-void ThreadPool::SetNum(int n)
+void thread_pool::set_num(int n)
 {
 	num = n;
 }

+ 8 - 8
src/thread/thread_pool.h

@@ -15,7 +15,7 @@ using namespace boost;
 
 typedef shared_ptr<thread> thread_ptr;
 
-class ThreadPool: private noncopyable
+class thread_pool: private noncopyable
 {
 private:
 	int num;
@@ -27,14 +27,14 @@ private:
 	list<thread_ptr> threads;
 	list<function<void(void)> > tasks;
 
-	void Runner();
+	void runner();
 public:
-	ThreadPool();
-	~ThreadPool();
-	void Start();
-	void Stop();
-	void SetNum(int n);
-	bool PushTask(function<void(void)> task);
+	thread_pool();
+	~thread_pool();
+	void start();
+	void stop();
+	void set_num(int n);
+	bool push_task(function<void(void)> task);
 };
 } // namespace hainan
 #endif  // THREAD_THREAD_POOL_H

+ 5 - 5
src/thread/thread_pool_test.cc

@@ -11,14 +11,14 @@ class ThreadPoolTest: public testing::Test
 {
 	void SetUp()
 	{
-		thread_pool.SetNum(10);
-		thread_pool.Start();
+		thread_pool.set_num(10);
+		thread_pool.start();
 	}
 	void TearDown()
 	{
 	}
 protected:
-	ThreadPool thread_pool;
+	thread_pool thread_pool;
 public:
 	ThreadPoolTest() :
 		thread_pool()
@@ -37,10 +37,10 @@ TEST_F(ThreadPoolTest, Test1)
 	vector<int> z(100, 0);
 	for (int i = 0; i < 100; ++i)
 	{
-		thread_pool.PushTask(
+		thread_pool.push_task(
 				bind(&ThreadPoolTest::Max, this, x[i], y[i], &z[i]));
 	}
-	thread_pool.Stop();
+	thread_pool.stop();
 	for (int i = 0; i < 100; ++i)
 	{
 		ASSERT_EQ(9, z[i])<< "i = " << i;