Ver código fonte

typedef thread_ptr
定义了一些通用的头文件

tanghai 15 anos atrás
pai
commit
393a2d30be
4 arquivos alterados com 23 adições e 8 exclusões
  1. 3 2
      src/base/base.h
  2. 6 0
      src/base/marcos.h
  3. 8 0
      src/base/typedefs.h
  4. 6 6
      src/thread/thread_pool.h

+ 3 - 2
src/base/base.h

@@ -1,6 +1,7 @@
 #ifndef BASE_BASE_H
 #define BASE_BASE_H
 
-#define foreach BOOST_FOREACH
+#include "base/typedefs.h"
+#include "base/marcos.h"
 
-#endif  // BASE_BASE_H
+#endif // BASE_BASE_H

+ 6 - 0
src/base/marcos.h

@@ -0,0 +1,6 @@
+#ifndef BASE_MARCOS_H
+#define BASE_MARCOS_H
+
+#define foreach BOOST_FOREACH
+
+#endif // BASE_MARCOS_H

+ 8 - 0
src/base/typedefs.h

@@ -0,0 +1,8 @@
+#ifndef BASE_TYPEDEFS_H
+#define BASE_TYPEDEFS_H
+#include <boost/smart_ptr.hpp>
+
+// smart_ptr typedef
+typedef boost::shared_ptr<boost::thread> thread_ptr;
+
+#endif // BASE_TYPEDEFS_H

+ 6 - 6
src/thread/thread_pool.h

@@ -5,12 +5,10 @@
 #include <boost/thread.hpp>
 #include <boost/function.hpp>
 #include <boost/bind.hpp>
-#include <boost/smart_ptr.hpp>
+#include "base/base.h"
 
 namespace hainan {
 
-typedef boost::shared_ptr<boost::thread> thread_ptr;
-
 class thread_pool: private boost::noncopyable
 {
 private:
@@ -21,7 +19,7 @@ private:
 	boost::condition_variable cond_;
 	boost::condition_variable done_;
 	std::list<thread_ptr> threads_;
-	std::list<boost::function<void(void)> > tasks_;
+	std::list<boost::function<void (void)> > tasks_;
 
 	void runner();
 public:
@@ -30,7 +28,9 @@ public:
 	void start();
 	void stop();
 	void set_num(int n);
-	bool push_task(boost::function<void(void)> task);
+	bool push_task(boost::function<void (void)> task);
 };
+
+typedef boost::shared_ptr<thread_pool> thread_pool_ptr;
 } // namespace hainan
-#endif  // THREAD_THREAD_POOL_H
+#endif // THREAD_THREAD_POOL_H