Jelajahi Sumber

成员变量改成不使用下划线结尾

tanghai 15 tahun lalu
induk
melakukan
134e8920e1

+ 3 - 3
src/net/rpc_channel.cc

@@ -6,7 +6,7 @@ namespace hainan {
 google::protobuf::Closure* to_closure();
 google::protobuf::Closure* to_closure();
 
 
 rpc_channel::rpc_channel(std::string& host, int port):
 rpc_channel::rpc_channel(std::string& host, int port):
-		id_(0)
+		id(0)
 {
 {
 }
 }
 
 
@@ -29,11 +29,11 @@ void rpc_channel::CallMethod(
 		google::protobuf::Message* response,
 		google::protobuf::Message* response,
 		google::protobuf::Closure* done) {
 		google::protobuf::Closure* done) {
 	rpc_request req;
 	rpc_request req;
-	req.set_id(++id_);
+	req.set_id(++id);
 	req.set_method(method->full_name());
 	req.set_method(method->full_name());
 	req.set_request(request->SerializeAsString());
 	req.set_request(request->SerializeAsString());
 	rpc_callback callback(controller, response, done);
 	rpc_callback callback(controller, response, done);
-	communicator_.send_message(req, callback);
+	communicator.send_message(req, callback);
 }
 }
 
 
 } // namespace hainan
 } // namespace hainan

+ 2 - 2
src/net/rpc_channel.h

@@ -12,8 +12,8 @@ namespace hainan {
 class rpc_channel: public google::protobuf::RpcChannel
 class rpc_channel: public google::protobuf::RpcChannel
 {
 {
 private:
 private:
-	int32 id_;
-	rpc_communicator communicator_;
+	int32 id;
+	rpc_communicator communicator;
 public:
 public:
 	rpc_channel(std::string& host, int port);
 	rpc_channel(std::string& host, int port);
 	~rpc_channel();
 	~rpc_channel();

+ 1 - 1
src/net/rpc_communicator.h

@@ -11,7 +11,7 @@ class rpc_callback;
 class rpc_communicator
 class rpc_communicator
 {
 {
 private:
 private:
-	boost::asio::ip::tcp::socket socket_;
+	boost::asio::ip::tcp::socket socket;
 public:
 public:
 	rpc_communicator(boost::asio::ip::tcp::endpoint& endpoint);
 	rpc_communicator(boost::asio::ip::tcp::endpoint& endpoint);
 	~rpc_communicator();
 	~rpc_communicator();

+ 29 - 29
src/thread/thread_pool.cc

@@ -4,7 +4,7 @@
 namespace hainan {
 namespace hainan {
 
 
 thread_pool::thread_pool() :
 thread_pool::thread_pool() :
-	num_(0), running_(false), work_num_(0)
+	num(0), running(false), work_num(0)
 {
 {
 }
 }
 thread_pool::~thread_pool()
 thread_pool::~thread_pool()
@@ -13,27 +13,27 @@ thread_pool::~thread_pool()
 
 
 void thread_pool::start()
 void thread_pool::start()
 {
 {
-	running_ = true;
-	for (int i = 0; i < num_; ++i)
+	running = true;
+	for (int i = 0; i < num; ++i)
 	{
 	{
 		thread_ptr t(new boost::thread(
 		thread_ptr t(new boost::thread(
 				boost::bind(&thread_pool::runner, this)));
 				boost::bind(&thread_pool::runner, this)));
-		threads_.push_back(t);
+		threads.push_back(t);
 		t->detach();
 		t->detach();
 	}
 	}
-	work_num_ = num_;
+	work_num = num;
 }
 }
 
 
 void thread_pool::stop()
 void thread_pool::stop()
 {
 {
 	VLOG(3)<< "Stop";
 	VLOG(3)<< "Stop";
-	boost::mutex::scoped_lock lock(mutex_);
-	running_ = false;
-	cond_.notify_all();
-	while (work_num_ > 0)
+	boost::mutex::scoped_lock lock(mutex);
+	running = false;
+	cond.notify_all();
+	while (work_num > 0)
 	{
 	{
-		VLOG(3) << "done tasks size = " << tasks_.size();
-		done_.wait(lock);
+		VLOG(3) << "done tasks size = " << tasks.size();
+		done.wait(lock);
 	}
 	}
 }
 }
 
 
@@ -46,23 +46,23 @@ void thread_pool::runner()
 		boost::function<void (void)> task;
 		boost::function<void (void)> task;
 		{
 		{
 			VLOG(3) << "loop lock";
 			VLOG(3) << "loop lock";
-			boost::mutex::scoped_lock lock(mutex_);
+			boost::mutex::scoped_lock lock(mutex);
 			VLOG(3) << "loop lock ok";
 			VLOG(3) << "loop lock ok";
-			while (running_ && tasks_.empty())
+			while (running && tasks.empty())
 			{
 			{
-				cond_.wait(lock);
+				cond.wait(lock);
 				VLOG(3) << "cond";
 				VLOG(3) << "cond";
 			}
 			}
-			if (!tasks_.empty())
+			if (!tasks.empty())
 			{
 			{
 				VLOG(3) << "fetch task";
 				VLOG(3) << "fetch task";
-				task = tasks_.front();
-				tasks_.pop_front();
+				task = tasks.front();
+				tasks.pop_front();
 			}
 			}
-			continued = running_ || !tasks_.empty();
+			continued = running || !tasks.empty();
 			VLOG(3) << "continued = " << continued
 			VLOG(3) << "continued = " << continued
-			<< "running = " << running_
-			<< " tasks size = " << tasks_.size();
+			<< "running = " << running
+			<< " tasks size = " << tasks.size();
 			VLOG(3) << "loop unlock";
 			VLOG(3) << "loop unlock";
 		}
 		}
 
 
@@ -71,10 +71,10 @@ void thread_pool::runner()
 			task();
 			task();
 		}
 		}
 	}
 	}
-	if (__sync_sub_and_fetch(&work_num_, 1) == 0)
+	if (__sync_sub_and_fetch(&work_num, 1) == 0)
 	{
 	{
-		VLOG(3) << "work_num = " << work_num_;
-		done_.notify_one();
+		VLOG(3) << "work_num = " << work_num;
+		done.notify_one();
 	}
 	}
 }
 }
 
 
@@ -82,21 +82,21 @@ bool thread_pool::push_task(boost::function<void (void)> task)
 {
 {
 	VLOG(3) << "push task";
 	VLOG(3) << "push task";
 	{
 	{
-		boost::mutex::scoped_lock lock(mutex_);
-		if (!running_)
+		boost::mutex::scoped_lock lock(mutex);
+		if (!running)
 		{
 		{
 			return false;
 			return false;
 		}
 		}
-		tasks_.push_back(task);
+		tasks.push_back(task);
 	}
 	}
 	VLOG(3) << "push task unlock";
 	VLOG(3) << "push task unlock";
-	cond_.notify_one();
+	cond.notify_one();
 	return true;
 	return true;
 }
 }
 
 
-void thread_pool::set_num(int n)
+void thread_pool::set_num(int num)
 {
 {
-	num_ = n;
+	this->num = num;
 }
 }
 
 
 } // namespace hainan
 } // namespace hainan

+ 9 - 9
src/thread/thread_pool.h

@@ -12,14 +12,14 @@ namespace hainan {
 class thread_pool: private boost::noncopyable
 class thread_pool: private boost::noncopyable
 {
 {
 private:
 private:
-	int num_;
-	volatile int work_num_;
-	volatile bool running_;
-	boost::mutex mutex_;
-	boost::condition_variable cond_;
-	boost::condition_variable done_;
-	std::list<thread_ptr> threads_;
-	std::list<boost::function<void (void)> > tasks_;
+	int num;
+	volatile int work_num;
+	volatile bool running;
+	boost::mutex mutex;
+	boost::condition_variable cond;
+	boost::condition_variable done;
+	std::list<thread_ptr> threads;
+	std::list<boost::function<void (void)> > tasks;
 
 
 	void runner();
 	void runner();
 public:
 public:
@@ -27,7 +27,7 @@ public:
 	~thread_pool();
 	~thread_pool();
 	void start();
 	void start();
 	void stop();
 	void stop();
-	void set_num(int n);
+	void set_num(int num);
 	bool push_task(boost::function<void (void)> task);
 	bool push_task(boost::function<void (void)> task);
 };
 };