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: public:
explicit Condition(MutexLock& mutex) explicit Condition(MutexLock& mutex)
: mutex_(mutex) { : mutex_(mutex) {
CHECK(!pthread_cond_init(&pcond_, NULL)); XCHECK(!pthread_cond_init(&pcond_, NULL));
} }
~Condition() { ~Condition() {
CHECK(!pthread_cond_destroy(&pcond_)); XCHECK(!pthread_cond_destroy(&pcond_));
} }
void Wait() { void Wait() {
CHECK(!pthread_cond_wait(&pcond_, mutex_.GetPthreadMutex())); XCHECK(!pthread_cond_wait(&pcond_, mutex_.GetPthreadMutex()));
} }
void Notify() { void Notify() {
CHECK(!pthread_cond_signal(&pcond_)); XCHECK(!pthread_cond_signal(&pcond_));
} }
void NotifyAll() { void NotifyAll() {
CHECK(!pthread_cond_broadcast(&pcond_)); XCHECK(!pthread_cond_broadcast(&pcond_));
} }
private: private:

View File

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

View File

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

View File

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

View File

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