Prefix LOG and CHECK with AOS_
This prepares us for introducing glog more widely and transitioning
things over where they make sense.
Change-Id: Ic6c208882407bc2153fe875ffc736d66f5c8ade5
diff --git a/aos/ipc_lib/BUILD b/aos/ipc_lib/BUILD
index 76c5324..1e8b118 100644
--- a/aos/ipc_lib/BUILD
+++ b/aos/ipc_lib/BUILD
@@ -192,6 +192,7 @@
"//aos/logging",
"//aos/time",
"//aos/util:compiler_memory_barrier",
+ "@com_github_google_glog//:glog",
],
)
diff --git a/aos/ipc_lib/aos_sync.cc b/aos/ipc_lib/aos_sync.cc
index 572b864..101a189 100644
--- a/aos/ipc_lib/aos_sync.cc
+++ b/aos/ipc_lib/aos_sync.cc
@@ -354,16 +354,16 @@
return r;
}
-// This gets called by functions before LOG(FATAL)ing with error messages that
-// would be incorrect if the error was caused by a process forking without
+// This gets called by functions before AOS_LOG(FATAL)ing with error messages
+// that would be incorrect if the error was caused by a process forking without
// initialize_in_new_thread getting called in the fork.
void check_cached_tid(pid_t tid) {
pid_t actual = do_get_tid();
if (tid != actual) {
- LOG(FATAL,
- "task %jd forked into %jd without letting aos_sync know"
- " so we're not really sure what's going on\n",
- static_cast<intmax_t>(tid), static_cast<intmax_t>(actual));
+ AOS_LOG(FATAL,
+ "task %jd forked into %jd without letting aos_sync know"
+ " so we're not really sure what's going on\n",
+ static_cast<intmax_t>(tid), static_cast<intmax_t>(actual));
}
}
@@ -379,7 +379,7 @@
void *InstallAtforkHook() {
if (pthread_atfork(NULL, NULL, atfork_child) != 0) {
- PLOG(FATAL, "pthread_atfork(NULL, NULL, %p) failed", atfork_child);
+ AOS_PLOG(FATAL, "pthread_atfork(NULL, NULL, %p) failed", atfork_child);
}
return nullptr;
}
@@ -475,8 +475,8 @@
robust_head.pending_next = 0;
if (syscall(SYS_set_robust_list, robust_head_next_value(), sizeof(robust_head)) !=
0) {
- PLOG(FATAL, "set_robust_list(%p, %zd) failed",
- reinterpret_cast<void *>(robust_head.next), sizeof(robust_head));
+ AOS_PLOG(FATAL, "set_robust_list(%p, %zd) failed",
+ reinterpret_cast<void *>(robust_head.next), sizeof(robust_head));
}
if (kRobustListDebug) {
printf("%" PRId32 ": init done\n", get_tid());
@@ -677,10 +677,11 @@
}
my_robust_list::robust_head.pending_next = 0;
if (ret == -EDEADLK) {
- LOG(FATAL, "multiple lock of %p by %" PRId32 "\n", m, tid);
+ AOS_LOG(FATAL, "multiple lock of %p by %" PRId32 "\n", m, tid);
}
- PELOG(FATAL, -ret, "FUTEX_LOCK_PI(%p(=%" PRIu32 "), 1, %p) failed",
- &m->futex, __atomic_load_n(&m->futex, __ATOMIC_SEQ_CST), timeout);
+ AOS_PELOG(FATAL, -ret, "FUTEX_LOCK_PI(%p(=%" PRIu32 "), 1, %p) failed",
+ &m->futex, __atomic_load_n(&m->futex, __ATOMIC_SEQ_CST),
+ timeout);
} else {
if (kLockDebug) {
printf("%" PRId32 ": %p kernel lock done\n", tid, m);
@@ -746,8 +747,8 @@
continue;
}
my_robust_list::robust_head.pending_next = 0;
- PELOG(FATAL, -ret, "FUTEX_CMP_REQUEUE_PI(%p, 1, %d, %p, *%p) failed", c,
- number_requeue, &m->futex, c);
+ AOS_PELOG(FATAL, -ret, "FUTEX_CMP_REQUEUE_PI(%p, 1, %d, %p, *%p) failed",
+ c, number_requeue, &m->futex, c);
} else {
return;
}
@@ -778,10 +779,11 @@
my_robust_list::robust_head.pending_next = 0;
check_cached_tid(tid);
if ((value & FUTEX_TID_MASK) == 0) {
- LOG(FATAL, "multiple unlock of aos_mutex %p by %" PRId32 "\n", m, tid);
+ AOS_LOG(FATAL, "multiple unlock of aos_mutex %p by %" PRId32 "\n", m,
+ tid);
} else {
- LOG(FATAL, "aos_mutex %p is locked by %" PRId32 ", not %" PRId32 "\n",
- m, value & FUTEX_TID_MASK, tid);
+ AOS_LOG(FATAL, "aos_mutex %p is locked by %" PRId32 ", not %" PRId32 "\n",
+ m, value & FUTEX_TID_MASK, tid);
}
}
@@ -794,7 +796,7 @@
const int ret = sys_futex_unlock_pi(&m->futex);
if (ret != 0) {
my_robust_list::robust_head.pending_next = 0;
- PELOG(FATAL, -ret, "FUTEX_UNLOCK_PI(%p) failed", &m->futex);
+ AOS_PELOG(FATAL, -ret, "FUTEX_UNLOCK_PI(%p) failed", &m->futex);
}
} else {
// There aren't any waiters, so no need to call into the kernel.
@@ -831,7 +833,8 @@
return 4;
}
my_robust_list::robust_head.pending_next = 0;
- PELOG(FATAL, -ret, "FUTEX_TRYLOCK_PI(%p, 0, NULL) failed", &m->futex);
+ AOS_PELOG(FATAL, -ret, "FUTEX_TRYLOCK_PI(%p, 0, NULL) failed",
+ &m->futex);
}
}
}
@@ -896,8 +899,9 @@
continue;
}
my_robust_list::robust_head.pending_next = 0;
- PELOG(FATAL, -ret, "FUTEX_WAIT_REQUEUE_PI(%p, %" PRIu32 ", %p) failed", c,
- wait_start, &m->futex);
+ AOS_PELOG(FATAL, -ret,
+ "FUTEX_WAIT_REQUEUE_PI(%p, %" PRIu32 ", %p) failed", c,
+ wait_start, &m->futex);
} else {
// Record that the kernel relocked it for us.
lock_pthread_mutex(m);
diff --git a/aos/ipc_lib/ipc_comparison.cc b/aos/ipc_lib/ipc_comparison.cc
index 2c73397..5ea1c8b 100644
--- a/aos/ipc_lib/ipc_comparison.cc
+++ b/aos/ipc_lib/ipc_comparison.cc
@@ -131,8 +131,8 @@
size_t remaining = sizeof(*data);
uint8_t *current = &(*data)[0];
while (remaining > 0) {
- const ssize_t result = PCHECK(read(fd, current, remaining));
- CHECK_LE(static_cast<size_t>(result), remaining);
+ const ssize_t result = AOS_PCHECK(read(fd, current, remaining));
+ AOS_CHECK_LE(static_cast<size_t>(result), remaining);
remaining -= result;
current += result;
}
@@ -142,8 +142,8 @@
size_t remaining = sizeof(data);
const uint8_t *current = &data[0];
while (remaining > 0) {
- const ssize_t result = PCHECK(write(fd, current, remaining));
- CHECK_LE(static_cast<size_t>(result), remaining);
+ const ssize_t result = AOS_PCHECK(write(fd, current, remaining));
+ AOS_CHECK_LE(static_cast<size_t>(result), remaining);
remaining -= result;
current += result;
}
@@ -157,15 +157,15 @@
class PipePingPonger : public FDPingPonger {
public:
PipePingPonger() {
- PCHECK(pipe(to_server));
- PCHECK(pipe(from_server));
+ AOS_PCHECK(pipe(to_server));
+ AOS_PCHECK(pipe(from_server));
Init(to_server[0], from_server[1], from_server[0], to_server[1]);
}
~PipePingPonger() {
- PCHECK(close(to_server[0]));
- PCHECK(close(to_server[1]));
- PCHECK(close(from_server[0]));
- PCHECK(close(from_server[1]));
+ AOS_PCHECK(close(to_server[0]));
+ AOS_PCHECK(close(to_server[1]));
+ AOS_PCHECK(close(from_server[0]));
+ AOS_PCHECK(close(from_server[1]));
}
private:
@@ -181,10 +181,10 @@
Init(server_read_, server_write_, client_read_, client_write_);
}
~NamedPipePingPonger() {
- PCHECK(close(server_read_));
- PCHECK(close(client_write_));
- PCHECK(close(client_read_));
- PCHECK(close(server_write_));
+ AOS_PCHECK(close(server_read_));
+ AOS_PCHECK(close(client_write_));
+ AOS_PCHECK(close(client_read_));
+ AOS_PCHECK(close(server_write_));
}
private:
@@ -192,15 +192,15 @@
{
const int ret = unlink(name);
if (ret == -1 && errno != ENOENT) {
- PLOG(FATAL, "unlink(%s)", name);
+ AOS_PLOG(FATAL, "unlink(%s)", name);
}
- PCHECK(mkfifo(name, S_IWUSR | S_IRUSR));
+ AOS_PCHECK(mkfifo(name, S_IWUSR | S_IRUSR));
// Have to open it nonblocking because the other end isn't open yet...
- *read = PCHECK(open(name, O_RDONLY | O_NONBLOCK));
- *write = PCHECK(open(name, O_WRONLY));
+ *read = AOS_PCHECK(open(name, O_RDONLY | O_NONBLOCK));
+ *write = AOS_PCHECK(open(name, O_WRONLY));
{
- const int flags = PCHECK(fcntl(*read, F_GETFL));
- PCHECK(fcntl(*read, F_SETFL, flags & ~O_NONBLOCK));
+ const int flags = AOS_PCHECK(fcntl(*read, F_GETFL));
+ AOS_PCHECK(fcntl(*read, F_SETFL, flags & ~O_NONBLOCK));
}
}
}
@@ -211,15 +211,15 @@
class UnixPingPonger : public FDPingPonger {
public:
UnixPingPonger(int type) {
- PCHECK(socketpair(AF_UNIX, type, 0, to_server));
- PCHECK(socketpair(AF_UNIX, type, 0, from_server));
+ AOS_PCHECK(socketpair(AF_UNIX, type, 0, to_server));
+ AOS_PCHECK(socketpair(AF_UNIX, type, 0, from_server));
Init(to_server[0], from_server[1], from_server[0], to_server[1]);
}
~UnixPingPonger() {
- PCHECK(close(to_server[0]));
- PCHECK(close(to_server[1]));
- PCHECK(close(from_server[0]));
- PCHECK(close(from_server[1]));
+ AOS_PCHECK(close(to_server[0]));
+ AOS_PCHECK(close(to_server[1]));
+ AOS_PCHECK(close(from_server[0]));
+ AOS_PCHECK(close(from_server[1]));
}
private:
@@ -229,42 +229,44 @@
class TCPPingPonger : public FDPingPonger {
public:
TCPPingPonger(bool nodelay) {
- server_ = PCHECK(socket(AF_INET, SOCK_STREAM, 0));
+ server_ = AOS_PCHECK(socket(AF_INET, SOCK_STREAM, 0));
if (nodelay) {
const int yes = 1;
- PCHECK(setsockopt(server_, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof(yes)));
+ AOS_PCHECK(
+ setsockopt(server_, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof(yes)));
}
{
sockaddr_in server_address;
memset(&server_address, 0, sizeof(server_address));
server_address.sin_family = AF_INET;
server_address.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
- PCHECK(bind(server_, reinterpret_cast<sockaddr *>(&server_address),
- sizeof(server_address)));
+ AOS_PCHECK(bind(server_, reinterpret_cast<sockaddr *>(&server_address),
+ sizeof(server_address)));
}
- PCHECK(listen(server_, 1));
+ AOS_PCHECK(listen(server_, 1));
- client_ = PCHECK(socket(AF_INET, SOCK_STREAM, 0));
+ client_ = AOS_PCHECK(socket(AF_INET, SOCK_STREAM, 0));
if (nodelay) {
const int yes = 1;
- PCHECK(setsockopt(client_, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof(yes)));
+ AOS_PCHECK(
+ setsockopt(client_, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof(yes)));
}
{
sockaddr_in client_address;
unsigned int length = sizeof(client_address);
- PCHECK(getsockname(server_, reinterpret_cast<sockaddr *>(&client_address),
- &length));
- PCHECK(connect(client_, reinterpret_cast<sockaddr *>(&client_address),
- length));
+ AOS_PCHECK(getsockname(
+ server_, reinterpret_cast<sockaddr *>(&client_address), &length));
+ AOS_PCHECK(connect(client_, reinterpret_cast<sockaddr *>(&client_address),
+ length));
}
- server_connection_ = PCHECK(accept(server_, nullptr, 0));
+ server_connection_ = AOS_PCHECK(accept(server_, nullptr, 0));
Init(server_connection_, server_connection_, client_, client_);
}
~TCPPingPonger() {
- PCHECK(close(client_));
- PCHECK(close(server_connection_));
- PCHECK(close(server_));
+ AOS_PCHECK(close(client_));
+ AOS_PCHECK(close(server_connection_));
+ AOS_PCHECK(close(server_));
}
private:
@@ -280,32 +282,32 @@
Init(server_read_, server_write_, client_read_, client_write_);
}
~UDPPingPonger() {
- PCHECK(close(server_read_));
- PCHECK(close(client_write_));
- PCHECK(close(client_read_));
- PCHECK(close(server_write_));
+ AOS_PCHECK(close(server_read_));
+ AOS_PCHECK(close(client_write_));
+ AOS_PCHECK(close(client_read_));
+ AOS_PCHECK(close(server_write_));
}
private:
void CreatePair(int *server, int *client) {
- *server = PCHECK(socket(AF_INET, SOCK_DGRAM, 0));
+ *server = AOS_PCHECK(socket(AF_INET, SOCK_DGRAM, 0));
{
sockaddr_in server_address;
memset(&server_address, 0, sizeof(server_address));
server_address.sin_family = AF_INET;
server_address.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
// server_address.sin_port = htons(server_ + 3000);
- PCHECK(bind(*server, reinterpret_cast<sockaddr *>(&server_address),
- sizeof(server_address)));
+ AOS_PCHECK(bind(*server, reinterpret_cast<sockaddr *>(&server_address),
+ sizeof(server_address)));
}
- *client = PCHECK(socket(AF_INET, SOCK_DGRAM, 0));
+ *client = AOS_PCHECK(socket(AF_INET, SOCK_DGRAM, 0));
{
sockaddr_in client_address;
unsigned int length = sizeof(client_address);
- PCHECK(getsockname(*server, reinterpret_cast<sockaddr *>(&client_address),
- &length));
- PCHECK(connect(*client, reinterpret_cast<sockaddr *>(&client_address),
- length));
+ AOS_PCHECK(getsockname(
+ *server, reinterpret_cast<sockaddr *>(&client_address), &length));
+ AOS_PCHECK(connect(*client, reinterpret_cast<sockaddr *>(&client_address),
+ length));
}
}
@@ -442,9 +444,9 @@
AOSConditionVariable() : condition_(&mutex_) {}
private:
- void Lock() override { CHECK(!mutex_.Lock()); }
+ void Lock() override { AOS_CHECK(!mutex_.Lock()); }
void Unlock() override { mutex_.Unlock(); }
- void Wait() override { CHECK(!condition_.Wait()); }
+ void Wait() override { AOS_CHECK(!condition_.Wait()); }
void Signal() override { condition_.Broadcast(); }
Mutex mutex_;
@@ -487,40 +489,42 @@
PthreadConditionVariable(bool pshared, bool pi) {
{
pthread_condattr_t cond_attr;
- PRCHECK(pthread_condattr_init(&cond_attr));
+ AOS_PRCHECK(pthread_condattr_init(&cond_attr));
if (pshared) {
- PRCHECK(
+ AOS_PRCHECK(
pthread_condattr_setpshared(&cond_attr, PTHREAD_PROCESS_SHARED));
}
- PRCHECK(pthread_cond_init(&condition_, &cond_attr));
- PRCHECK(pthread_condattr_destroy(&cond_attr));
+ AOS_PRCHECK(pthread_cond_init(&condition_, &cond_attr));
+ AOS_PRCHECK(pthread_condattr_destroy(&cond_attr));
}
{
pthread_mutexattr_t mutex_attr;
- PRCHECK(pthread_mutexattr_init(&mutex_attr));
+ AOS_PRCHECK(pthread_mutexattr_init(&mutex_attr));
if (pshared) {
- PRCHECK(pthread_mutexattr_setpshared(&mutex_attr,
- PTHREAD_PROCESS_SHARED));
+ AOS_PRCHECK(pthread_mutexattr_setpshared(&mutex_attr,
+ PTHREAD_PROCESS_SHARED));
}
if (pi) {
- PRCHECK(
+ AOS_PRCHECK(
pthread_mutexattr_setprotocol(&mutex_attr, PTHREAD_PRIO_INHERIT));
}
- PRCHECK(pthread_mutex_init(&mutex_, nullptr));
- PRCHECK(pthread_mutexattr_destroy(&mutex_attr));
+ AOS_PRCHECK(pthread_mutex_init(&mutex_, nullptr));
+ AOS_PRCHECK(pthread_mutexattr_destroy(&mutex_attr));
}
}
~PthreadConditionVariable() {
- PRCHECK(pthread_mutex_destroy(&mutex_));
- PRCHECK(pthread_cond_destroy(&condition_));
+ AOS_PRCHECK(pthread_mutex_destroy(&mutex_));
+ AOS_PRCHECK(pthread_cond_destroy(&condition_));
}
private:
- void Lock() override { PRCHECK(pthread_mutex_lock(&mutex_)); }
- void Unlock() override { PRCHECK(pthread_mutex_unlock(&mutex_)); }
- void Wait() override { PRCHECK(pthread_cond_wait(&condition_, &mutex_)); }
- void Signal() override { PRCHECK(pthread_cond_broadcast(&condition_)); }
+ void Lock() override { AOS_PRCHECK(pthread_mutex_lock(&mutex_)); }
+ void Unlock() override { AOS_PRCHECK(pthread_mutex_unlock(&mutex_)); }
+ void Wait() override {
+ AOS_PRCHECK(pthread_cond_wait(&condition_, &mutex_));
+ }
+ void Signal() override { AOS_PRCHECK(pthread_cond_broadcast(&condition_)); }
pthread_cond_t condition_;
pthread_mutex_t mutex_;
@@ -537,21 +541,21 @@
private:
class EventFDSemaphore : public SemaphoreInterface {
public:
- EventFDSemaphore() : fd_(PCHECK(eventfd(0, 0))) {}
- ~EventFDSemaphore() { PCHECK(close(fd_)); }
+ EventFDSemaphore() : fd_(AOS_PCHECK(eventfd(0, 0))) {}
+ ~EventFDSemaphore() { AOS_PCHECK(close(fd_)); }
private:
void Get() override {
uint64_t value;
if (read(fd_, &value, sizeof(value)) != sizeof(value)) {
- PLOG(FATAL, "reading from eventfd %d failed\n", fd_);
+ AOS_PLOG(FATAL, "reading from eventfd %d failed\n", fd_);
}
- CHECK_EQ(1u, value);
+ AOS_CHECK_EQ(1u, value);
}
void Put() override {
uint64_t value = 1;
if (write(fd_, &value, sizeof(value)) != sizeof(value)) {
- PLOG(FATAL, "writing to eventfd %d failed\n", fd_);
+ AOS_PLOG(FATAL, "writing to eventfd %d failed\n", fd_);
}
}
@@ -569,7 +573,7 @@
private:
class SysvSemaphore : public SemaphoreInterface {
public:
- SysvSemaphore() : sem_id_(PCHECK(semget(IPC_PRIVATE, 1, 0600))) {}
+ SysvSemaphore() : sem_id_(AOS_PCHECK(semget(IPC_PRIVATE, 1, 0600))) {}
private:
void Get() override {
@@ -577,14 +581,14 @@
op.sem_num = 0;
op.sem_op = -1;
op.sem_flg = 0;
- PCHECK(semop(sem_id_, &op, 1));
+ AOS_PCHECK(semop(sem_id_, &op, 1));
}
void Put() override {
struct sembuf op;
op.sem_num = 0;
op.sem_op = 1;
op.sem_flg = 0;
- PCHECK(semop(sem_id_, &op, 1));
+ AOS_PCHECK(semop(sem_id_, &op, 1));
}
const int sem_id_;
@@ -605,8 +609,8 @@
PosixSemaphore(sem_t *sem) : sem_(sem) {}
private:
- void Get() override { PCHECK(sem_wait(sem_)); }
- void Put() override { PCHECK(sem_post(sem_)); }
+ void Get() override { AOS_PCHECK(sem_wait(sem_)); }
+ void Put() override { AOS_PCHECK(sem_post(sem_)); }
sem_t *const sem_;
};
@@ -615,18 +619,18 @@
class SysvQueuePingPonger : public StaticPingPonger {
public:
SysvQueuePingPonger()
- : ping_(PCHECK(msgget(IPC_PRIVATE, 0600))),
- pong_(PCHECK(msgget(IPC_PRIVATE, 0600))) {}
+ : ping_(AOS_PCHECK(msgget(IPC_PRIVATE, 0600))),
+ pong_(AOS_PCHECK(msgget(IPC_PRIVATE, 0600))) {}
const Data *Ping() override {
{
Message to_send;
memcpy(&to_send.data, PingData(), sizeof(Data));
- PCHECK(msgsnd(ping_, &to_send, sizeof(Data), 0));
+ AOS_PCHECK(msgsnd(ping_, &to_send, sizeof(Data), 0));
}
{
Message received;
- PCHECK(msgrcv(pong_, &received, sizeof(Data), 1, 0));
+ AOS_PCHECK(msgrcv(pong_, &received, sizeof(Data), 1, 0));
memcpy(&pong_received_, &received.data, sizeof(Data));
}
return &pong_received_;
@@ -635,7 +639,7 @@
const Data *Wait() override {
{
Message received;
- PCHECK(msgrcv(ping_, &received, sizeof(Data), 1, 0));
+ AOS_PCHECK(msgrcv(ping_, &received, sizeof(Data), 1, 0));
memcpy(&ping_received_, &received.data, sizeof(Data));
}
return &ping_received_;
@@ -644,7 +648,7 @@
virtual void Pong() override {
Message to_send;
memcpy(&to_send.data, PongData(), sizeof(Data));
- PCHECK(msgsnd(pong_, &to_send, sizeof(Data), 0));
+ AOS_PCHECK(msgsnd(pong_, &to_send, sizeof(Data), 0));
}
private:
@@ -662,35 +666,37 @@
public:
PosixQueuePingPonger() : ping_(Open("/ping")), pong_(Open("/pong")) {}
~PosixQueuePingPonger() {
- PCHECK(mq_close(ping_));
- PCHECK(mq_close(pong_));
+ AOS_PCHECK(mq_close(ping_));
+ AOS_PCHECK(mq_close(pong_));
}
const Data *Ping() override {
- PCHECK(mq_send(ping_, static_cast<char *>(static_cast<void *>(PingData())),
- sizeof(Data), 1));
- PCHECK(mq_receive(pong_,
- static_cast<char *>(static_cast<void *>(&pong_received_)),
- sizeof(Data), nullptr));
+ AOS_PCHECK(mq_send(ping_,
+ static_cast<char *>(static_cast<void *>(PingData())),
+ sizeof(Data), 1));
+ AOS_PCHECK(mq_receive(
+ pong_, static_cast<char *>(static_cast<void *>(&pong_received_)),
+ sizeof(Data), nullptr));
return &pong_received_;
}
const Data *Wait() override {
- PCHECK(mq_receive(ping_,
- static_cast<char *>(static_cast<void *>(&ping_received_)),
- sizeof(Data), nullptr));
+ AOS_PCHECK(mq_receive(
+ ping_, static_cast<char *>(static_cast<void *>(&ping_received_)),
+ sizeof(Data), nullptr));
return &ping_received_;
}
virtual void Pong() override {
- PCHECK(mq_send(pong_, static_cast<char *>(static_cast<void *>(PongData())),
- sizeof(Data), 1));
+ AOS_PCHECK(mq_send(pong_,
+ static_cast<char *>(static_cast<void *>(PongData())),
+ sizeof(Data), 1));
}
private:
mqd_t Open(const char *name) {
if (mq_unlink(name) == -1 && errno != ENOENT) {
- PLOG(FATAL, "mq_unlink(%s) failed", name);
+ AOS_PLOG(FATAL, "mq_unlink(%s) failed", name);
}
struct mq_attr attr;
attr.mq_flags = 0;
@@ -699,7 +705,7 @@
attr.mq_curmsgs = 0;
const mqd_t r = mq_open(name, O_CREAT | O_RDWR | O_EXCL, 0600, &attr);
if (r == reinterpret_cast<mqd_t>(-1)) {
- PLOG(FATAL, "mq_open(%s, O_CREAT | O_RDWR | O_EXCL) failed", name);
+ AOS_PLOG(FATAL, "mq_open(%s, O_CREAT | O_RDWR | O_EXCL) failed", name);
}
return r;
}
@@ -712,12 +718,12 @@
public:
PosixUnnamedSemaphorePingPonger(int pshared)
: PosixSemaphorePingPonger(&ping_sem_, &pong_sem_) {
- PCHECK(sem_init(&ping_sem_, pshared, 0));
- PCHECK(sem_init(&pong_sem_, pshared, 0));
+ AOS_PCHECK(sem_init(&ping_sem_, pshared, 0));
+ AOS_PCHECK(sem_init(&pong_sem_, pshared, 0));
}
~PosixUnnamedSemaphorePingPonger() {
- PCHECK(sem_destroy(&ping_sem_));
- PCHECK(sem_destroy(&pong_sem_));
+ AOS_PCHECK(sem_destroy(&ping_sem_));
+ AOS_PCHECK(sem_destroy(&pong_sem_));
}
private:
@@ -730,18 +736,18 @@
: PosixSemaphorePingPonger(ping_sem_ = Open("/ping"),
pong_sem_ = Open("/pong")) {}
~PosixNamedSemaphorePingPonger() {
- PCHECK(sem_close(ping_sem_));
- PCHECK(sem_close(pong_sem_));
+ AOS_PCHECK(sem_close(ping_sem_));
+ AOS_PCHECK(sem_close(pong_sem_));
}
private:
sem_t *Open(const char *name) {
if (sem_unlink(name) == -1 && errno != ENOENT) {
- PLOG(FATAL, "shm_unlink(%s) failed", name);
+ AOS_PLOG(FATAL, "shm_unlink(%s) failed", name);
}
sem_t *const r = sem_open(name, O_CREAT | O_RDWR | O_EXCL, 0600, 0);
if (r == SEM_FAILED) {
- PLOG(FATAL, "sem_open(%s, O_CREAT | O_RDWR | O_EXCL) failed", name);
+ AOS_PLOG(FATAL, "sem_open(%s, O_CREAT | O_RDWR | O_EXCL) failed", name);
}
return r;
}
@@ -756,14 +762,14 @@
pong_queue_(RawQueue::Fetch("pong", sizeof(Data), 0, 1)) {}
Data *PingData() override {
- CHECK_EQ(nullptr, ping_to_send_);
+ AOS_CHECK_EQ(nullptr, ping_to_send_);
ping_to_send_ = static_cast<Data *>(ping_queue_->GetMessage());
return ping_to_send_;
}
const Data *Ping() override {
- CHECK_NE(nullptr, ping_to_send_);
- CHECK(ping_queue_->WriteMessage(ping_to_send_, RawQueue::kBlock));
+ AOS_CHECK_NE(nullptr, ping_to_send_);
+ AOS_CHECK(ping_queue_->WriteMessage(ping_to_send_, RawQueue::kBlock));
ping_to_send_ = nullptr;
pong_queue_->FreeMessage(pong_received_);
pong_received_ =
@@ -779,14 +785,14 @@
}
Data *PongData() override {
- CHECK_EQ(nullptr, pong_to_send_);
+ AOS_CHECK_EQ(nullptr, pong_to_send_);
pong_to_send_ = static_cast<Data *>(pong_queue_->GetMessage());
return pong_to_send_;
}
void Pong() override {
- CHECK_NE(nullptr, pong_to_send_);
- CHECK(pong_queue_->WriteMessage(pong_to_send_, RawQueue::kBlock));
+ AOS_CHECK_NE(nullptr, pong_to_send_);
+ AOS_CHECK(pong_queue_->WriteMessage(pong_to_send_, RawQueue::kBlock));
pong_to_send_ = nullptr;
}
@@ -887,7 +893,7 @@
memset(*to_send, i % 123, sizeof(*to_send));
const PingPongerInterface::Data *received = ping_ponger->Ping();
for (size_t ii = 0; ii < sizeof(*received); ++ii) {
- CHECK_EQ(((i % 123) + 1) % 255, (*received)[ii]);
+ AOS_CHECK_EQ(((i % 123) + 1) % 255, (*received)[ii]);
}
}
@@ -903,14 +909,14 @@
ping_ponger->Ping();
server.join();
- LOG(INFO, "Took %f seconds to send %" PRId32 " messages\n",
- ::aos::time::DurationInSeconds(end - start), FLAGS_messages);
+ AOS_LOG(INFO, "Took %f seconds to send %" PRId32 " messages\n",
+ ::aos::time::DurationInSeconds(end - start), FLAGS_messages);
const chrono::nanoseconds per_message = (end - start) / FLAGS_messages;
if (per_message >= chrono::seconds(1)) {
- LOG(INFO, "More than 1 second per message ?!?\n");
+ AOS_LOG(INFO, "More than 1 second per message ?!?\n");
} else {
- LOG(INFO, "That is %" PRId32 " nanoseconds per message\n",
- static_cast<int>(per_message.count()));
+ AOS_LOG(INFO, "That is %" PRId32 " nanoseconds per message\n",
+ static_cast<int>(per_message.count()));
}
return 0;
diff --git a/aos/ipc_lib/lockless_queue.cc b/aos/ipc_lib/lockless_queue.cc
index fb9c0b6..cd0e2ae 100644
--- a/aos/ipc_lib/lockless_queue.cc
+++ b/aos/ipc_lib/lockless_queue.cc
@@ -13,6 +13,7 @@
#include "aos/ipc_lib/lockless_queue_memory.h"
#include "aos/logging/logging.h"
#include "aos/util/compiler_memory_barrier.h"
+#include "glog/logging.h"
namespace aos {
namespace ipc_lib {
@@ -490,7 +491,7 @@
}
if (sender_index_ == -1) {
- LOG(FATAL, "Too many senders\n");
+ LOG(FATAL) << "Too many senders";
}
::aos::ipc_lib::Sender *s = memory_->GetSender(sender_index_);
diff --git a/aos/ipc_lib/lockless_queue_death_test.cc b/aos/ipc_lib/lockless_queue_death_test.cc
index 100821c..7a68273 100644
--- a/aos/ipc_lib/lockless_queue_death_test.cc
+++ b/aos/ipc_lib/lockless_queue_death_test.cc
@@ -15,10 +15,10 @@
#include "aos/ipc_lib/aos_sync.h"
#include "aos/ipc_lib/lockless_queue_memory.h"
#include "aos/libc/aos_strsignal.h"
-#include "aos/logging/logging.h"
#include "aos/testing/prevent_exit.h"
#include "aos/testing/test_logging.h"
#include "gflags/gflags.h"
+#include "glog/logging.h"
#include "gtest/gtest.h"
namespace aos {
@@ -148,12 +148,11 @@
// Calls mprotect(2) for the entire shared memory region with the given prot.
void ShmProtectOrDie(int prot) {
GlobalState *my_global_state = global_state.load(::std::memory_order_relaxed);
- if (mprotect(my_global_state->lockless_queue_memory,
- my_global_state->lockless_queue_memory_size, prot) == -1) {
- PLOG(FATAL, "mprotect(%p, %zu, %x) failed",
- my_global_state->lockless_queue_memory,
- my_global_state->lockless_queue_memory_size, prot);
- }
+ PCHECK(mprotect(my_global_state->lockless_queue_memory,
+ my_global_state->lockless_queue_memory_size, prot) != -1)
+ << ": mprotect(" << my_global_state->lockless_queue_memory << ", "
+ << my_global_state->lockless_queue_memory_size << ", 0x" << std::hex
+ << prot << ") failed";
}
// Checks a write into the queue and conditionally dies. Tracks the write.
@@ -277,13 +276,13 @@
SigactionType real_sigaction =
reinterpret_cast<SigactionType>(dlsym(RTLD_NEXT, "sigaction"));
if (sigaction == real_sigaction) {
- LOG(WARNING, "failed to work around tsan signal handling weirdness\n");
+ LOG(WARNING) << "failed to work around tsan signal handling weirdness";
}
- PCHECK(real_sigaction(signal, &action, old_action));
+ PCHECK(real_sigaction(signal, &action, old_action) == 0);
return;
}
#endif
- PCHECK(sigaction(signal, &action, old_action));
+ PCHECK(sigaction(signal, &action, old_action) == 0);
}
#endif // ifndef __ARM_EABI__
@@ -318,9 +317,7 @@
if (!prepare_in_child) prepare(my_global_state->lockless_queue_memory);
const pid_t pid = fork();
- if (pid == -1) {
- PLOG(FATAL, "fork() failed\n");
- }
+ PCHECK(pid != -1) << ": fork() failed";
if (pid == 0) {
// Run the test.
::aos::testing::PreventExit();
@@ -350,12 +347,13 @@
pid_t waited_on = waitpid(pid, &status, 0);
if (waited_on == -1) {
if (errno == EINTR) continue;
- PLOG(FATAL, "waitpid(%jd, %p, 0) failed\n", static_cast<intmax_t>(pid),
- &status);
+ PCHECK(false) << ": waitpid(" << static_cast<intmax_t>(pid) << ", "
+ << &status << ", 0) failed";
}
if (waited_on != pid) {
- LOG(FATAL, "waitpid got child %jd instead of %jd\n",
- static_cast<intmax_t>(waited_on), static_cast<intmax_t>(pid));
+ PCHECK(false) << ": waitpid got child "
+ << static_cast<intmax_t>(waited_on) << " instead of "
+ << static_cast<intmax_t>(pid);
}
if (WIFEXITED(status)) {
if (WEXITSTATUS(status) == 0) return true;
diff --git a/aos/ipc_lib/queue.cc b/aos/ipc_lib/queue.cc
index 295e854..5b6a0fa 100644
--- a/aos/ipc_lib/queue.cc
+++ b/aos/ipc_lib/queue.cc
@@ -172,7 +172,7 @@
MessageHeader *header = __atomic_load_n(&free_messages_, __ATOMIC_RELAXED);
do {
if (__builtin_expect(header == nullptr, 0)) {
- LOG(FATAL, "overused pool of queue %p (%s)\n", this, name_);
+ AOS_LOG(FATAL, "overused pool of queue %p (%s)\n", this, name_);
}
} while (__builtin_expect(
!__atomic_compare_exchange_n(&free_messages_, &header, header->next, true,
@@ -196,8 +196,8 @@
"need to revalidate size/alignent assumptions");
if (queue_length < 1) {
- LOG(FATAL, "queue length %d of %s needs to be at least 1\n", queue_length,
- name);
+ AOS_LOG(FATAL, "queue length %d of %s needs to be at least 1\n",
+ queue_length, name);
}
const size_t name_size = strlen(name) + 1;
@@ -249,8 +249,8 @@
printf("fetching queue %s\n", name);
}
if (mutex_lock(&global_core->mem_struct->queues.lock) != 0) {
- LOG(FATAL, "mutex_lock(%p) failed\n",
- &global_core->mem_struct->queues.lock);
+ AOS_LOG(FATAL, "mutex_lock(%p) failed\n",
+ &global_core->mem_struct->queues.lock);
}
RawQueue *current =
static_cast<RawQueue *>(global_core->mem_struct->queues.pointer);
@@ -309,7 +309,7 @@
{
IPCMutexLocker locker(&data_lock_);
- CHECK(!locker.owner_died());
+ AOS_CHECK(!locker.owner_died());
int new_end;
while (true) {
@@ -334,7 +334,7 @@
if (kWriteDebug) {
printf("queue: going to wait for writable_ of %p\n", this);
}
- CHECK(!writable_.Wait());
+ AOS_CHECK(!writable_.Wait());
}
}
data_[data_end_] = msg;
@@ -390,7 +390,7 @@
if (wait_result == Condition::WaitResult::kOk) {
break;
}
- CHECK(wait_result != Condition::WaitResult::kOwnerDied);
+ AOS_CHECK(wait_result != Condition::WaitResult::kOwnerDied);
if (wait_result == Condition::WaitResult::kTimeout) {
return false;
}
@@ -427,7 +427,7 @@
void *msg = NULL;
IPCMutexLocker locker(&data_lock_);
- CHECK(!locker.owner_died());
+ AOS_CHECK(!locker.owner_died());
if (!ReadCommonStart(options, nullptr, chrono::nanoseconds(0))) {
if (kReadDebug) {
@@ -490,7 +490,7 @@
void *msg = NULL;
IPCMutexLocker locker(&data_lock_);
- CHECK(!locker.owner_died());
+ AOS_CHECK(!locker.owner_died());
if (!ReadCommonStart(options, index, timeout)) {
if (kReadDebug) {
diff --git a/aos/ipc_lib/queue.h b/aos/ipc_lib/queue.h
index b93cc42..5b68f2e 100644
--- a/aos/ipc_lib/queue.h
+++ b/aos/ipc_lib/queue.h
@@ -90,10 +90,10 @@
static constexpr Options<RawQueue> kWriteFailureOptions =
kNonBlock | kBlock | kOverride;
if (!options.NoOthersSet(kWriteFailureOptions)) {
- LOG(FATAL, "illegal write options in %x\n", options.printable());
+ AOS_LOG(FATAL, "illegal write options in %x\n", options.printable());
}
if (!options.ExactlyOneSet(kWriteFailureOptions)) {
- LOG(FATAL, "invalid write options %x\n", options.printable());
+ AOS_LOG(FATAL, "invalid write options %x\n", options.printable());
}
return DoWriteMessage(msg, options);
}
@@ -123,7 +123,7 @@
CheckReadOptions(options);
static constexpr Options<RawQueue> kFromEndAndPeek = kFromEnd | kPeek;
if (options.AllSet(kFromEndAndPeek)) {
- LOG(FATAL, "ReadMessageIndex(kFromEnd | kPeek) is not allowed\n");
+ AOS_LOG(FATAL, "ReadMessageIndex(kFromEnd | kPeek) is not allowed\n");
}
return DoReadMessageIndex(options, index, timeout);
}
@@ -161,11 +161,11 @@
static constexpr Options<RawQueue> kValidOptions =
kPeek | kFromEnd | kNonBlock | kBlock;
if (!options.NoOthersSet(kValidOptions)) {
- LOG(FATAL, "illegal read options in %x\n", options.printable());
+ AOS_LOG(FATAL, "illegal read options in %x\n", options.printable());
}
static constexpr Options<RawQueue> kBlockChoices = kNonBlock | kBlock;
if (!options.ExactlyOneSet(kBlockChoices)) {
- LOG(FATAL, "invalid read options %x\n", options.printable());
+ AOS_LOG(FATAL, "invalid read options %x\n", options.printable());
}
}
diff --git a/aos/ipc_lib/raw_queue_test.cc b/aos/ipc_lib/raw_queue_test.cc
index ab98b1f..aa3b335 100644
--- a/aos/ipc_lib/raw_queue_test.cc
+++ b/aos/ipc_lib/raw_queue_test.cc
@@ -99,23 +99,25 @@
printf("process %jd was already dead\n",
static_cast<intmax_t>(pid_));
} else {
- PLOG(FATAL, "kill(SIGKILL, %jd) failed",
- static_cast<intmax_t>(pid_));
+ AOS_PLOG(FATAL, "kill(SIGKILL, %jd) failed",
+ static_cast<intmax_t>(pid_));
}
}
}
const pid_t ret = wait(NULL);
if (ret == -1) {
- LOG(WARNING, "wait(NULL) failed."
- " child %jd might still be alive\n",
- static_cast<intmax_t>(pid_));
+ AOS_LOG(WARNING,
+ "wait(NULL) failed."
+ " child %jd might still be alive\n",
+ static_cast<intmax_t>(pid_));
} else if (ret == 0) {
- LOG(WARNING, "child %jd wasn't waitable. it might still be alive\n",
- static_cast<intmax_t>(pid_));
+ AOS_LOG(WARNING, "child %jd wasn't waitable. it might still be alive\n",
+ static_cast<intmax_t>(pid_));
} else if (ret != pid_) {
- LOG(WARNING, "child %d is now confirmed dead"
- ", but child %jd might still be alive\n",
- ret, static_cast<intmax_t>(pid_));
+ AOS_LOG(WARNING,
+ "child %d is now confirmed dead"
+ ", but child %jd might still be alive\n",
+ ret, static_cast<intmax_t>(pid_));
}
}
@@ -188,16 +190,16 @@
switch (pid) {
case 0: // child
if (kForkSleep != chrono::milliseconds(0)) {
- LOG(INFO, "pid %jd sleeping for %" PRId64 "ns\n",
- static_cast<intmax_t>(getpid()), kForkSleep.count());
+ AOS_LOG(INFO, "pid %jd sleeping for %" PRId64 "ns\n",
+ static_cast<intmax_t>(getpid()), kForkSleep.count());
this_thread::sleep_for(kForkSleep);
}
::aos::testing::PreventExit();
function(arg);
- CHECK_NE(-1, futex_set(done));
+ AOS_CHECK_NE(-1, futex_set(done));
exit(EXIT_SUCCESS);
case -1: // parent failure
- PLOG(ERROR, "fork() failed");
+ AOS_PLOG(ERROR, "fork() failed");
return std::unique_ptr<ForkedProcess>();
default: // parent
return std::unique_ptr<ForkedProcess>(new ForkedProcess(pid, done));
@@ -237,7 +239,7 @@
static_cast<char *>(fatal_failure)[0] = '\0';
children_[id] = ForkExecute(Hangs_, to_call).release();
if (!children_[id]) return AssertionFailure() << "ForkExecute failed";
- CHECK_EQ(0, futex_wait(&to_call->started));
+ AOS_CHECK_EQ(0, futex_wait(&to_call->started));
to_calls_[id] = reinterpret_cast<FunctionToCall<void> *>(to_call);
return AssertionSuccess();
}
diff --git a/aos/ipc_lib/shared_mem.c b/aos/ipc_lib/shared_mem.c
index e8edc9e..da55ebc 100644
--- a/aos/ipc_lib/shared_mem.c
+++ b/aos/ipc_lib/shared_mem.c
@@ -61,7 +61,7 @@
if (shm == -1 && errno == EEXIST) {
printf("shared_mem: going to shm_unlink(%s)\n", global_core->shm_name);
if (shm_unlink(global_core->shm_name) == -1) {
- PLOG(WARNING, "shm_unlink(%s) failed", global_core->shm_name);
+ AOS_PLOG(WARNING, "shm_unlink(%s) failed", global_core->shm_name);
break;
}
} else {
@@ -73,12 +73,12 @@
global_core->owner = 0;
}
if (shm == -1) {
- PLOG(FATAL, "shm_open(%s, O_RDWR [| O_CREAT | O_EXCL, 0|0666) failed",
- global_core->shm_name);
+ AOS_PLOG(FATAL, "shm_open(%s, O_RDWR [| O_CREAT | O_EXCL, 0|0666) failed",
+ global_core->shm_name);
}
if (global_core->owner) {
if (ftruncate(shm, SIZEOFSHMSEG) == -1) {
- PLOG(FATAL, "fruncate(%d, 0x%zx) failed", shm, (size_t)SIZEOFSHMSEG);
+ AOS_PLOG(FATAL, "fruncate(%d, 0x%zx) failed", shm, (size_t)SIZEOFSHMSEG);
}
}
int flags = MAP_SHARED | MAP_FIXED;
@@ -86,8 +86,8 @@
void *shm_address = mmap((void *)SHM_START, SIZEOFSHMSEG,
PROT_READ | PROT_WRITE, flags, shm, 0);
if (shm_address == MAP_FAILED) {
- PLOG(FATAL, "shared_mem: mmap(%p, 0x%zx, stuff, %x, %d, 0) failed",
- (void *)SHM_START, (size_t)SIZEOFSHMSEG, flags, shm);
+ AOS_PLOG(FATAL, "shared_mem: mmap(%p, 0x%zx, stuff, %x, %d, 0) failed",
+ (void *)SHM_START, (size_t)SIZEOFSHMSEG, flags, shm);
}
if (create) {
printf("shared_mem: creating %s, shm at: %p\n", global_core->shm_name,
@@ -96,14 +96,14 @@
printf("shared_mem: not creating, shm at: %p\n", shm_address);
}
if (close(shm) == -1) {
- PLOG(WARNING, "close(%d(=shm) failed", shm);
+ AOS_PLOG(WARNING, "close(%d(=shm) failed", shm);
}
if (shm_address != (void *)SHM_START) {
- LOG(FATAL, "shm isn't at hard-coded %p. at %p instead\n",
- (void *)SHM_START, shm_address);
+ AOS_LOG(FATAL, "shm isn't at hard-coded %p. at %p instead\n",
+ (void *)SHM_START, shm_address);
}
aos_core_use_address_as_shared_mem(shm_address, SIZEOFSHMSEG);
- LOG(INFO, "shared_mem: end of create_shared_mem owner=%d\n",
+ AOS_LOG(INFO, "shared_mem: end of create_shared_mem owner=%d\n",
global_core->owner);
}
@@ -118,7 +118,7 @@
futex_set(&global_core->mem_struct->creation_condition);
} else {
if (futex_wait(&global_core->mem_struct->creation_condition) != 0) {
- LOG(FATAL, "waiting on creation_condition failed\n");
+ AOS_LOG(FATAL, "waiting on creation_condition failed\n");
}
}
}
@@ -126,12 +126,13 @@
void aos_core_free_shared_mem() {
void *shm_address = global_core->shared_mem;
if (munmap((void *)SHM_START, SIZEOFSHMSEG) == -1) {
- PLOG(FATAL, "munmap(%p, 0x%zx) failed", shm_address,
- (size_t)SIZEOFSHMSEG);
+ AOS_PLOG(FATAL, "munmap(%p, 0x%zx) failed", shm_address,
+ (size_t)SIZEOFSHMSEG);
}
if (global_core->owner) {
if (shm_unlink(global_core->shm_name)) {
- PLOG(FATAL, "shared_mem: shm_unlink(%s) failed", global_core->shm_name);
+ AOS_PLOG(FATAL, "shared_mem: shm_unlink(%s) failed",
+ global_core->shm_name);
}
}
}
diff --git a/aos/ipc_lib/signalfd.cc b/aos/ipc_lib/signalfd.cc
index 1679b46..045444b 100644
--- a/aos/ipc_lib/signalfd.cc
+++ b/aos/ipc_lib/signalfd.cc
@@ -18,7 +18,7 @@
}
// Then build a signalfd. Make it nonblocking so it works well with an epoll
// loop, and have it close on exec.
- PCHECK(fd_ = signalfd(-1, &mask_, SFD_NONBLOCK | SFD_CLOEXEC));
+ AOS_PCHECK(fd_ = signalfd(-1, &mask_, SFD_NONBLOCK | SFD_CLOEXEC));
// Now that we have a consumer of the signal, block the signals so the
// signalfd gets them.
pthread_sigmask(SIG_BLOCK, &mask_, nullptr);
@@ -27,7 +27,7 @@
SignalFd::~SignalFd() {
// Unwind the constructor. Unblock the signals and close the fd.
pthread_sigmask(SIG_UNBLOCK, &mask_, nullptr);
- PCHECK(close(fd_));
+ AOS_PCHECK(close(fd_));
}
signalfd_siginfo SignalFd::Read() {