upgrade limonp to v0.5.5

This commit is contained in:
yanyiwu 2016-02-19 16:14:33 +08:00
parent 9d7da4864a
commit fc04cf750a
5 changed files with 25 additions and 25 deletions

View File

@ -9,23 +9,23 @@ class Condition : NonCopyable {
public:
explicit Condition(MutexLock& mutex)
: mutex_(mutex) {
CHECK(!pthread_cond_init(&pcond_, NULL));
XCHECK(!pthread_cond_init(&pcond_, NULL));
}
~Condition() {
CHECK(!pthread_cond_destroy(&pcond_));
XCHECK(!pthread_cond_destroy(&pcond_));
}
void Wait() {
CHECK(!pthread_cond_wait(&pcond_, mutex_.GetPthreadMutex()));
XCHECK(!pthread_cond_wait(&pcond_, mutex_.GetPthreadMutex()));
}
void Notify() {
CHECK(!pthread_cond_signal(&pcond_));
XCHECK(!pthread_cond_signal(&pcond_));
}
void NotifyAll() {
CHECK(!pthread_cond_broadcast(&pcond_));
XCHECK(!pthread_cond_broadcast(&pcond_));
}
private:

View File

@ -7,15 +7,15 @@
#include <cstdlib>
#include <ctime>
#ifdef LOG
#error "LOG has been defined already"
#endif // LOG
#ifdef CHECK
#error "CHECK has been defined already"
#endif // CHECK
#ifdef XLOG
#error "XLOG has been defined already"
#endif // XLOG
#ifdef XCHECK
#error "XCHECK has been defined already"
#endif // XCHECK
#define LOG(level) limonp::Logger(limonp::LL_##level, __FILE__, __LINE__).Stream()
#define CHECK(exp) if(!(exp)) LOG(FATAL) << "exp: ["#exp << "] false. "
#define XLOG(level) limonp::Logger(limonp::LL_##level, __FILE__, __LINE__).Stream()
#define XCHECK(exp) if(!(exp)) XLOG(FATAL) << "exp: ["#exp << "] false. "
namespace limonp {

View File

@ -10,10 +10,10 @@ namespace limonp {
class MutexLock: NonCopyable {
public:
MutexLock() {
CHECK(!pthread_mutex_init(&mutex_, NULL));
XCHECK(!pthread_mutex_init(&mutex_, NULL));
}
~MutexLock() {
CHECK(!pthread_mutex_destroy(&mutex_));
XCHECK(!pthread_mutex_destroy(&mutex_));
}
pthread_mutex_t* GetPthreadMutex() {
return &mutex_;
@ -21,10 +21,10 @@ class MutexLock: NonCopyable {
private:
void Lock() {
CHECK(!pthread_mutex_lock(&mutex_));
XCHECK(!pthread_mutex_lock(&mutex_));
}
void Unlock() {
CHECK(!pthread_mutex_unlock(&mutex_));
XCHECK(!pthread_mutex_unlock(&mutex_));
}
friend class MutexLockGuard;
@ -44,7 +44,7 @@ class MutexLockGuard: NonCopyable {
MutexLock & mutex_;
}; // class MutexLockGuard
#define MutexLockGuard(x) CHECK(false);
#define MutexLockGuard(x) XCHECK(false);
} // namespace limonp

View File

@ -12,19 +12,19 @@ class IThread: NonCopyable {
}
virtual ~IThread() {
if(isStarted && !isJoined) {
CHECK(!pthread_detach(thread_));
XCHECK(!pthread_detach(thread_));
}
};
virtual void Run() = 0;
void Start() {
CHECK(!isStarted);
CHECK(!pthread_create(&thread_, NULL, Worker, this));
XCHECK(!isStarted);
XCHECK(!pthread_create(&thread_, NULL, Worker, this));
isStarted = true;
}
void Join() {
CHECK(!isJoined);
CHECK(!pthread_join(thread_, NULL));
XCHECK(!isJoined);
XCHECK(!pthread_join(thread_, NULL));
isJoined = true;
}
private:

View File

@ -30,9 +30,9 @@ class ThreadPool: NonCopyable {
try {
closure->Run();
} catch(std::exception& e) {
LOG(ERROR) << e.what();
XLOG(ERROR) << e.what();
} catch(...) {
LOG(ERROR) << " unknown exception.";
XLOG(ERROR) << " unknown exception.";
}
delete closure;
}