diff --git a/include/mutex.h b/include/mutex.h index 2418974..cedfd85 100644 --- a/include/mutex.h +++ b/include/mutex.h @@ -12,6 +12,7 @@ #include #include #include +#include #include "timer.h" namespace baidu { @@ -27,7 +28,7 @@ static void PthreadCall(const char* label, int result) { } // A Mutex represents an exclusive lock. -class Mutex { +class Mutex : boost::noncopyable { public: Mutex() : owner_(0), msg_(NULL), msg_threshold_(0), lock_time_(0) { @@ -94,8 +95,6 @@ class Mutex { } private: friend class CondVar; - Mutex(const Mutex&); - void operator=(const Mutex&); pthread_mutex_t mu_; pthread_t owner_; const char* msg_; @@ -104,7 +103,7 @@ class Mutex { }; // Mutex lock guard -class MutexLock { +class MutexLock : boost::noncopyable { public: explicit MutexLock(Mutex *mu, const char* msg = NULL, int64_t msg_threshold = 5000) : mu_(mu) { @@ -115,12 +114,10 @@ class MutexLock { } private: Mutex *const mu_; - MutexLock(const MutexLock&); - void operator=(const MutexLock&); }; // Conditional variable -class CondVar { +class CondVar : boost::noncopyable { public: explicit CondVar(Mutex* mu) : mu_(mu) { PthreadCall("init condvar", pthread_cond_init(&cond_, NULL)); @@ -155,8 +152,6 @@ class CondVar { PthreadCall("broadcast", pthread_cond_broadcast(&cond_)); } private: - CondVar(const CondVar&); - void operator=(const CondVar&); Mutex* mu_; pthread_cond_t cond_; }; diff --git a/include/sliding_window.h b/include/sliding_window.h index f5dc8a4..2c1ddd2 100644 --- a/include/sliding_window.h +++ b/include/sliding_window.h @@ -11,6 +11,7 @@ #include #include #include +#include #include "mutex.h" @@ -18,17 +19,14 @@ namespace baidu { namespace common { template -class SlidingWindow { +class SlidingWindow : boost::noncopyable { public: typedef boost::function SlidingCallback; SlidingWindow(int32_t size, SlidingCallback callback) - : bitmap_(NULL), items_(NULL), item_count_(0), - callback_(callback), size_(size), + : bitmap_(new char[size]), items_(new Item[size]), + item_count_(0), callback_(callback), size_(size), base_offset_(0), max_offset_(-1), ready_(0), notifying_(false) { - bitmap_ = new char[size]; memset(bitmap_, 0, size); - items_ = new Item[size]; - size_ = size; } ~SlidingWindow() { delete[] bitmap_; diff --git a/include/thread.h b/include/thread.h index 17ecb5c..bfeaea4 100644 --- a/include/thread.h +++ b/include/thread.h @@ -11,11 +11,12 @@ #include #include +#include namespace baidu { namespace common { -class Thread { +class Thread : boost::noncopyable { public: Thread() { memset(&tid_, 0, sizeof(tid_)); @@ -35,8 +36,6 @@ class Thread { return (ret == 0); } private: - Thread(const Thread&); - void operator=(const Thread&); static void* ProcWrapper(void* arg) { reinterpret_cast(arg)->user_proc_(); return NULL; diff --git a/include/thread_pool.h b/include/thread_pool.h index d060d3b..8be7145 100644 --- a/include/thread_pool.h +++ b/include/thread_pool.h @@ -13,6 +13,7 @@ #include #include #include +#include #include "mutex.h" #include "timer.h" @@ -22,7 +23,7 @@ namespace common { static const int kDebugCheckTime = 5000; // An unscalable thread pool implimention. -class ThreadPool { +class ThreadPool :boost::noncopyable { public: ThreadPool(int thread_num = 10) : threads_num_(thread_num), @@ -173,9 +174,6 @@ class ThreadPool { } private: - ThreadPool(const ThreadPool&); - void operator=(const ThreadPool&); - static void* ThreadWrapper(void* arg) { reinterpret_cast(arg)->ThreadProc(); return NULL; diff --git a/include/util.h b/include/util.h index a5ca282..add2648 100644 --- a/include/util.h +++ b/include/util.h @@ -23,8 +23,7 @@ static inline std::string GetLocalHostName() { if (0 != gethostname(str, kMaxHostNameSize + 1)) { return ""; } - std::string hostname(str); - return hostname; + return std::string(str); } static const uint32_t MAX_PATH_LENGHT = 10240;