Skip to content
This repository was archived by the owner on May 28, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions include/mutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <pthread.h>
#include <string.h>
#include <sys/time.h>
#include <boost/noncopyable.hpp>
#include "timer.h"

namespace baidu {
Expand All @@ -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) {
Expand Down Expand Up @@ -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_;
Expand All @@ -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) {
Expand All @@ -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));
Expand Down Expand Up @@ -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_;
};
Expand Down
10 changes: 4 additions & 6 deletions include/sliding_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,22 @@
#include <vector>
#include <map>
#include <boost/function.hpp>
#include <boost/noncopyable.hpp>

#include "mutex.h"

namespace baidu {
namespace common {

template <typename Item>
class SlidingWindow {
class SlidingWindow : boost::noncopyable {
public:
typedef boost::function<void (int32_t, Item)> 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_;
Expand Down
5 changes: 2 additions & 3 deletions include/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
#include <string.h>

#include <boost/function.hpp>
#include <boost/noncopyable.hpp>

namespace baidu {
namespace common {

class Thread {
class Thread : boost::noncopyable {
public:
Thread() {
memset(&tid_, 0, sizeof(tid_));
Expand All @@ -35,8 +36,6 @@ class Thread {
return (ret == 0);
}
private:
Thread(const Thread&);
void operator=(const Thread&);
static void* ProcWrapper(void* arg) {
reinterpret_cast<Thread*>(arg)->user_proc_();
return NULL;
Expand Down
6 changes: 2 additions & 4 deletions include/thread_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <sstream>
#include <vector>
#include <boost/function.hpp>
#include <boost/noncopyable.hpp>
#include "mutex.h"
#include "timer.h"

Expand All @@ -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),
Expand Down Expand Up @@ -173,9 +174,6 @@ class ThreadPool {
}

private:
ThreadPool(const ThreadPool&);
void operator=(const ThreadPool&);

static void* ThreadWrapper(void* arg) {
reinterpret_cast<ThreadPool*>(arg)->ThreadProc();
return NULL;
Expand Down
3 changes: 1 addition & 2 deletions include/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down