Move some .cc files next to their corresponding headers
Change-Id: I8a6bbdc7edeb8b6d746f08f593b1655e7260cd03
diff --git a/aos/linux_code/ipc_lib/BUILD b/aos/linux_code/ipc_lib/BUILD
index 576774e..2b90c34 100644
--- a/aos/linux_code/ipc_lib/BUILD
+++ b/aos/linux_code/ipc_lib/BUILD
@@ -67,8 +67,8 @@
'queue.h',
],
deps = [
- '//aos/linux_code/ipc_lib:condition',
- '//aos/linux_code/ipc_lib:mutex',
+ '//aos/common:condition',
+ '//aos/common:mutex',
':core_lib',
':shared_mem',
'//aos/common/logging:logging_interface',
@@ -107,7 +107,7 @@
'//aos/testing:googletest',
'//aos/common:time',
'//aos/common:queue_testutils',
- '//aos/linux_code/ipc_lib:mutex',
+ '//aos/common:mutex',
':core_lib',
'//aos/common:die',
'//aos/common/libc:dirname',
@@ -122,43 +122,3 @@
':queue',
],
)
-
-cc_library(
- name = 'condition',
- visibility = ['//aos/common:__pkg__'],
- srcs = [
- 'condition.cc',
- ],
- deps = [
- ':mutex',
- '//aos/common:real_condition',
- ':aos_sync',
- '//aos/common/logging:logging_interface',
- ],
-)
-
-cc_library(
- name = 'mutex',
- srcs = [
- 'mutex.cc',
- ],
- deps = [
- ':aos_sync',
- '//aos/common/logging:logging_interface',
- '//aos/common:type_traits',
- '//aos/common:mutex',
- ],
-)
-
-cc_library(
- name = 'event',
- visibility = ['//aos/common:__pkg__'],
- srcs = [
- 'event.cc',
- ],
- deps = [
- ':aos_sync',
- '//aos/common/logging:logging_interface',
- '//aos/common:real_event',
- ],
-)
diff --git a/aos/linux_code/ipc_lib/condition.cc b/aos/linux_code/ipc_lib/condition.cc
deleted file mode 100644
index 62ede1c..0000000
--- a/aos/linux_code/ipc_lib/condition.cc
+++ /dev/null
@@ -1,30 +0,0 @@
-#include "aos/common/condition.h"
-
-#include <inttypes.h>
-#include <assert.h>
-
-#include "aos/common/type_traits.h"
-#include "aos/common/mutex.h"
-
-namespace aos {
-
-static_assert(shm_ok<Condition>::value,
- "Condition should work in shared memory");
-
-Condition::Condition(Mutex *m) : impl_(), m_(m) {}
-
-bool Condition::Wait() {
- const int ret = condition_wait(&impl_, &m_->impl_);
- assert(__builtin_expect(ret == 0 || ret == 1, 1));
- return ret == 1;
-}
-
-void Condition::Signal() {
- condition_signal(&impl_, &m_->impl_);
-}
-
-void Condition::Broadcast() {
- condition_broadcast(&impl_, &m_->impl_);
-}
-
-} // namespace aos
diff --git a/aos/linux_code/ipc_lib/event.cc b/aos/linux_code/ipc_lib/event.cc
deleted file mode 100644
index ae32d39..0000000
--- a/aos/linux_code/ipc_lib/event.cc
+++ /dev/null
@@ -1,47 +0,0 @@
-#include "aos/common/event.h"
-
-#include "aos/common/type_traits.h"
-#include "aos/common/logging/logging.h"
-
-namespace aos {
-
-Event::Event() : impl_(0) {
- static_assert(shm_ok<Event>::value,
- "Event is not safe for use in shared memory.");
-}
-
-void Event::Wait() {
- int ret;
- do {
- ret = futex_wait(&impl_);
- } while (ret == 1);
- if (ret == 0) return;
- CHECK_EQ(-1, ret);
- PLOG(FATAL, "futex_wait(%p) failed", &impl_);
-}
-
-bool Event::WaitTimeout(const ::aos::time::Time &timeout) {
- const auto timeout_timespec = timeout.ToTimespec();
- int ret;
- do {
- ret = futex_wait_timeout(&impl_, &timeout_timespec);
- } while (ret == 1);
- if (ret == 0) return true;
- if (ret == 2) return false;
- CHECK_EQ(-1, ret);
- PLOG(FATAL, "futex_wait(%p) failed", &impl_);
-}
-
-// We're not going to expose the number woken because that's not easily portable
-// to condition variable-based implementations.
-void Event::Set() {
- if (futex_set(&impl_) == -1) {
- PLOG(FATAL, "futex_set(%p) failed", &impl_);
- }
-}
-
-bool Event::Clear() {
- return !futex_unset(&impl_);
-}
-
-} // namespace aos
diff --git a/aos/linux_code/ipc_lib/mutex.cc b/aos/linux_code/ipc_lib/mutex.cc
deleted file mode 100644
index c5b8652..0000000
--- a/aos/linux_code/ipc_lib/mutex.cc
+++ /dev/null
@@ -1,58 +0,0 @@
-#include "aos/common/mutex.h"
-
-#include <inttypes.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "aos/common/type_traits.h"
-#include "aos/common/logging/logging.h"
-
-namespace aos {
-
-Mutex::Mutex() : impl_() {
- static_assert(shm_ok<Mutex>::value,
- "Mutex is not safe for use in shared memory.");
-}
-
-Mutex::~Mutex() {
- if (__builtin_expect(mutex_islocked(&impl_), false)) {
- LOG(FATAL, "destroying locked mutex %p (aka %p)\n",
- this, &impl_);
- }
-}
-
-// Lock and Unlock use the return values of mutex_lock/mutex_unlock
-// to determine whether the lock/unlock succeeded.
-
-bool Mutex::Lock() {
- const int ret = mutex_grab(&impl_);
- if (ret == 0) {
- return false;
- } else {
- LOG(FATAL, "mutex_grab(%p(=%" PRIu32 ")) failed with %d\n",
- &impl_, impl_.futex, ret);
- }
-}
-
-void Mutex::Unlock() {
- mutex_unlock(&impl_);
-}
-
-Mutex::State Mutex::TryLock() {
- const int ret = mutex_trylock(&impl_);
- switch (ret) {
- case 0:
- return State::kLocked;
- case 4:
- return State::kLockFailed;
- default:
- LOG(FATAL, "mutex_trylock(%p(=%" PRIu32 ")) failed with %d\n",
- &impl_, impl_.futex, ret);
- }
-}
-
-bool Mutex::OwnedBySelf() const {
- return mutex_islocked(&impl_);
-}
-
-} // namespace aos