Skip to content

Commit

Permalink
macro name LOG and CHECK in Logging.hpp is so easy to confict with ot…
Browse files Browse the repository at this point in the history
…her lib, so I have to rename them to XLOG and XCHECK for avoiding those macro name conflicts.
  • Loading branch information
yanyiwu committed Feb 19, 2016
1 parent ffba80a commit 65285c2
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 36 deletions.
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# limonp ChangeLog

## next version

+ macro name LOG and CHECK in Logging.hpp is so easy to confict with other lib, so I have to rename them to XLOG and XCHECK for avoiding those macro name conflicts.

## v0.5.4

+ add ForcePublic.hpp
Expand Down
10 changes: 5 additions & 5 deletions include/limonp/Condition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 8 additions & 8 deletions include/limonp/Logging.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
10 changes: 5 additions & 5 deletions include/limonp/MutexLock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ 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_;
}

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;

Expand All @@ -44,7 +44,7 @@ class MutexLockGuard: NonCopyable {
MutexLock & mutex_;
}; // class MutexLockGuard

#define MutexLockGuard(x) CHECK(false);
#define MutexLockGuard(x) XCHECK(false);

} // namespace limonp

Expand Down
10 changes: 5 additions & 5 deletions include/limonp/Thread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions include/limonp/ThreadPool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion test/demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ int main(int argc, char** argv) {
limonp::Split(str, buf, ",");
print(buf); //["hello", "world"];

LOG(INFO) << "hello, world"; //2014-04-05 20:52:37 demo.cpp:20 INFO hello, world
XLOG(INFO) << "hello, world"; //2014-04-05 20:52:37 demo.cpp:20 INFO hello, world
//In the same way, `LOG(DEBUG),LOG(WARNING),LOG(ERROR),LOG(FATAL)`.
return EXIT_SUCCESS;
}
4 changes: 2 additions & 2 deletions test/unittest/TBlockingQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ class CBlockingQueueTest1 {
public:
CBlockingQueueTest1(const size_t threadSum, void* arg): pthreads_(threadSum) {
for(size_t i = 0; i < pthreads_.size(); i++) {
CHECK(!pthread_create(&pthreads_[i], NULL, workerLocked, arg));
XCHECK(!pthread_create(&pthreads_[i], NULL, workerLocked, arg));
}
}
~CBlockingQueueTest1() {
}
public:
void Wait() {
for(size_t i = 0; i < pthreads_.size(); i++) {
CHECK(!pthread_join(pthreads_[i], NULL));
XCHECK(!pthread_join(pthreads_[i], NULL));
}
}

Expand Down
4 changes: 2 additions & 2 deletions test/unittest/TColorPrint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ using namespace limonp;
TEST(ColorPrint, Test1) {
ColorPrintln(RED, "hello %s", "world");
ColorPrintln(RED, "hello %s", "world");
LOG(INFO) << "hello world";
XLOG(INFO) << "hello world";
ColorPrintln(RED, "hello %s", "world");
ColorPrintln(GREEN, "hello %s", "world");
LOG(INFO) << "hello world";
XLOG(INFO) << "hello world";
ColorPrintln(BLACK, "hello %s", "world");
ColorPrintln(YELLOW, "hello %s", "world");
ColorPrintln(BLUE, "hello %s", "world");
Expand Down
12 changes: 6 additions & 6 deletions test/unittest/TLogging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
#include "gtest/gtest.h"

TEST(Logging, Test1) {
LOG(DEBUG) << "xxx" << " yyy";
LOG(INFO) << "hello";
LOG(WARNING) << "hello";
LOG(ERROR) << "hello";
//CHECK(false) << "hello, " << "world";
//LOG(FATAL) << "hello";
XLOG(DEBUG) << "xxx" << " yyy";
XLOG(INFO) << "hello";
XLOG(WARNING) << "hello";
XLOG(ERROR) << "hello";
//XCHECK(false) << "hello, " << "world";
//XLOG(FATAL) << "hello";
}

0 comments on commit 65285c2

Please sign in to comment.