Remove //aos/transaction
I'm not sure if its test plays happy with the new simplified AOS_LOG,
but it doesn't matter if it's gone.
Change-Id: I08428b9f60dc73c4981721bf026833d7b0aa4cec
diff --git a/aos/transaction/BUILD b/aos/transaction/BUILD
deleted file mode 100644
index 81dc8a0..0000000
--- a/aos/transaction/BUILD
+++ /dev/null
@@ -1,25 +0,0 @@
-package(default_visibility = ["//visibility:public"])
-
-cc_library(
- name = "transaction",
- hdrs = [
- "transaction.h",
- ],
- deps = [
- "//aos/logging",
- "//aos/util:compiler_memory_barrier",
- ],
-)
-
-cc_test(
- name = "transaction_test",
- srcs = [
- "transaction_test.cc",
- ],
- deps = [
- ":transaction",
- "//aos/logging",
- "//aos/testing:googletest",
- "//aos/util:death_test_log_implementation",
- ],
-)
diff --git a/aos/transaction/transaction.h b/aos/transaction/transaction.h
deleted file mode 100644
index e0266f9..0000000
--- a/aos/transaction/transaction.h
+++ /dev/null
@@ -1,103 +0,0 @@
-#ifndef AOS_TRANSACTION_H_
-#define AOS_TRANSACTION_H_
-
-#include <stdint.h>
-
-#include <array>
-
-#include "aos/util/compiler_memory_barrier.h"
-#include "aos/logging/logging.h"
-
-namespace aos {
-namespace transaction {
-
-// Manages a LIFO stack of Work objects. Designed to help implement transactions
-// by providing a safe way to undo things etc.
-//
-// number_works Work objects are created statically and then Create is called on
-// each as it is added to the stack. When the work should do whatever it does,
-// DoWork() will be called. The work objects get no notification when they are
-// dropped off of the stack.
-//
-// Work::DoWork() must be idempotent because it may get called multiple times if
-// CompleteWork() is interrupted part of the way through.
-//
-// This class handles compiler memory barriers etc to make sure only fully
-// created works are ever invoked, and each work will be fully created by the
-// time AddWork returns. This does not mean it's safe for multiple threads to
-// interact with an instance of this class at the same time.
-template <class Work, int number_works>
-class WorkStack {
- public:
- // Calls DoWork() on all the works that have been added and then removes them
- // all from the stack.
- void CompleteWork() {
- int current = stack_index_;
- while (current > 0) {
- stack_.at(--current).DoWork();
- }
- aos_compiler_memory_barrier();
- stack_index_ = 0;
- aos_compiler_memory_barrier();
- }
-
- // Drops all works that have been added.
- void DropWork() {
- stack_index_ = 0;
- aos_compiler_memory_barrier();
- }
-
- // Returns true if we have any works to complete right now.
- bool HasWork() const { return stack_index_ != 0; }
-
- // Forwards all of its arguments to Work::Create, which it calls on the next
- // work to be added.
- template <class... A>
- void AddWork(A &&... a) {
- if (stack_index_ >= number_works) {
- AOS_LOG(FATAL, "too many works\n");
- }
- stack_.at(stack_index_).Create(::std::forward<A>(a)...);
- aos_compiler_memory_barrier();
- ++stack_index_;
- aos_compiler_memory_barrier();
- }
-
- private:
- // The next index into stack_ for a new work to be added.
- int stack_index_ = 0;
- ::std::array<Work, number_works> stack_;
-};
-
-// When invoked, sets *pointer to the value it had when this work was Created.
-template <class T>
-class RestoreValueWork {
- public:
- void Create(T *pointer) {
- pointer_ = pointer;
- value_ = *pointer;
- }
- void DoWork() {
- *pointer_ = value_;
- }
-
- private:
- T *pointer_;
- T value_;
-};
-
-// Handles the casting necessary to restore any kind of pointer.
-class RestorePointerWork : public RestoreValueWork<void *> {
- public:
- template <class T>
- void Create(T **pointer) {
- static_assert(sizeof(T *) == sizeof(void *),
- "that's a weird pointer");
- RestoreValueWork<void *>::Create(reinterpret_cast<void **>(pointer));
- }
-};
-
-} // namespace transaction
-} // namespace aos
-
-#endif // AOS_TRANSACTION_H_
diff --git a/aos/transaction/transaction_test.cc b/aos/transaction/transaction_test.cc
deleted file mode 100644
index fd76d3f..0000000
--- a/aos/transaction/transaction_test.cc
+++ /dev/null
@@ -1,102 +0,0 @@
-#include "aos/transaction/transaction.h"
-
-#include <vector>
-
-#include "gtest/gtest.h"
-
-#include "aos/util/death_test_log_implementation.h"
-
-namespace aos {
-namespace transaction {
-namespace testing {
-
-class WorkStackTest : public ::testing::Test {
- public:
- // Contains an index which it adds to the created_works and invoked_works
- // vectors of its containing WorkStackTest.
- class TestWork {
- public:
- void Create(WorkStackTest *test, int i) {
- test->created_works()->push_back(i);
- i_ = i;
- test_ = test;
- }
- void DoWork() { test_->invoked_works()->push_back(i_); }
-
- int i() const { return i_; }
-
- private:
- int i_;
- WorkStackTest *test_;
- };
-
- ::std::vector<int> *created_works() { return &created_works_; }
- ::std::vector<int> *invoked_works() { return &invoked_works_; }
- WorkStack<TestWork, 20> *work_stack() { return &work_stack_; }
-
- // Creates a TestWork with index i and adds it to work_stack().
- void CreateWork(int i) { work_stack_.AddWork(this, i); }
-
- private:
- ::std::vector<int> created_works_, invoked_works_;
- WorkStack<TestWork, 20> work_stack_;
-};
-
-typedef WorkStackTest WorkStackDeathTest;
-
-TEST_F(WorkStackTest, Basic) {
- EXPECT_FALSE(work_stack()->HasWork());
- EXPECT_EQ(0u, created_works()->size());
- EXPECT_EQ(0u, invoked_works()->size());
-
- CreateWork(971);
- EXPECT_TRUE(work_stack()->HasWork());
- EXPECT_EQ(1u, created_works()->size());
- EXPECT_EQ(0u, invoked_works()->size());
- EXPECT_EQ(971, created_works()->at(0));
-
- work_stack()->CompleteWork();
- EXPECT_FALSE(work_stack()->HasWork());
- EXPECT_EQ(1u, created_works()->size());
- EXPECT_EQ(1u, invoked_works()->size());
- EXPECT_EQ(971, invoked_works()->at(0));
-}
-
-TEST_F(WorkStackTest, DropWork) {
- CreateWork(971);
- CreateWork(254);
- EXPECT_EQ(2u, created_works()->size());
-
- work_stack()->DropWork();
- EXPECT_FALSE(work_stack()->HasWork());
- work_stack()->CompleteWork();
- EXPECT_EQ(0u, invoked_works()->size());
-}
-
-// Tests that the works get run in the correct order.
-TEST_F(WorkStackTest, InvocationOrder) {
- CreateWork(971);
- CreateWork(254);
- CreateWork(1678);
-
- work_stack()->CompleteWork();
- EXPECT_EQ((::std::vector<int>{971, 254, 1678}), *created_works());
- EXPECT_EQ((::std::vector<int>{1678, 254, 971}), *invoked_works());
-}
-
-// Tests that it handles adding too many works intelligently.
-TEST_F(WorkStackDeathTest, TooManyWorks) {
- EXPECT_DEATH(
- {
- logging::SetImplementation(
- std::make_shared<util::DeathTestLogImplementation>());
- for (int i = 0; i < 1000; ++i) {
- CreateWork(i);
- }
- },
- ".*too many works.*");
-}
-
-} // namespace testing
-} // namespace transaction
-} // namespace aos
diff --git a/aos/util/BUILD b/aos/util/BUILD
index b23b720..01be701 100644
--- a/aos/util/BUILD
+++ b/aos/util/BUILD
@@ -237,28 +237,6 @@
],
)
-cc_library(
- name = "linked_list",
- hdrs = [
- "linked_list.h",
- ],
- deps = [
- "//aos/transaction",
- ],
-)
-
-cc_test(
- name = "linked_list_test",
- srcs = [
- "linked_list_test.cc",
- ],
- deps = [
- ":linked_list",
- "//aos/logging",
- "//aos/testing:googletest",
- ],
-)
-
cc_test(
name = "phased_loop_test",
srcs = [
diff --git a/aos/util/linked_list.h b/aos/util/linked_list.h
deleted file mode 100644
index 14f1788..0000000
--- a/aos/util/linked_list.h
+++ /dev/null
@@ -1,113 +0,0 @@
-#ifndef AOS_UTIL_LINKED_LIST_H_
-#define AOS_UTIL_LINKED_LIST_H_
-
-#include <functional>
-
-#include "aos/transaction/transaction.h"
-
-namespace aos {
-namespace util {
-
-// Handles manipulating an intrusive linked list. T must look like the
-// following:
-// struct T {
-// ...
-// T *next;
-// ...
-// };
-// This class doesn't deal with creating or destroying them, so
-// constructors/destructors/other members variables/member functions are all
-// fine, but the next pointer must be there for this class to work.
-// This class will handle all manipulations of next. It does not need to be
-// initialized before calling Add and should not be changed afterwards.
-// next can (and probably should) be private if the appropriate instantiation of
-// this class is friended.
-template <class T>
-class LinkedList {
- public:
- T *head() const { return head_; }
-
- bool Empty() const { return head() == nullptr; }
-
- void Add(T *t) {
- Add<0>(t, nullptr);
- }
-
- // restore_points (if non-null) will be used so the operation can be safely
- // reverted at any point.
- template <int number_works>
- void Add(T *t, transaction::WorkStack<transaction::RestorePointerWork,
- number_works> *restore_pointers) {
- if (restore_pointers != nullptr) restore_pointers->AddWork(&t->next);
- t->next = head();
- if (restore_pointers != nullptr) restore_pointers->AddWork(&head_);
- head_ = t;
- }
-
- void Remove(T *t) {
- Remove<0>(t, nullptr);
- }
-
- // restore_points (if non-null) will be used so the operation can be safely
- // reverted at any point.
- template <int number_works>
- void Remove(T *t, transaction::WorkStack<transaction::RestorePointerWork,
- number_works> *restore_pointers) {
- T **pointer = &head_;
- while (*pointer != nullptr) {
- if (*pointer == t) {
- if (restore_pointers != nullptr) {
- restore_pointers->AddWork(pointer);
- }
- *pointer = t->next;
- return;
- }
- pointer = &(*pointer)->next;
- }
- AOS_LOG(FATAL, "%p is not in the list\n", t);
- }
-
- // Calls function for each element of the list.
- // function can modify these elements in any way except touching the next
- // pointer (including by calling other methods of this object).
- void Each(::std::function<void(T *)> function) const {
- T *c = head();
- while (c != nullptr) {
- T *const next = c->next;
- function(c);
- c = next;
- }
- }
-
- // Returns the first element of the list where function returns true or
- // nullptr if it returns false for all.
- T *Find(::std::function<bool(const T *)> function) const {
- T *c = head();
- while (c != nullptr) {
- if (function(c)) return c;
- c = c->next;
- }
- return nullptr;
- }
-
- private:
- T *head_ = nullptr;
-};
-
-// Keeps track of something along with a next pointer. Useful for things that
-// either have types without next pointers or for storing pointers to things
-// that belong in multiple lists.
-template <class V>
-struct LinkedListReference {
- V item;
-
- private:
- friend class LinkedList<LinkedListReference>;
-
- LinkedListReference *next;
-};
-
-} // namespace util
-} // namespace aos
-
-#endif // AOS_UTIL_LINKED_LIST_H_
diff --git a/aos/util/linked_list_test.cc b/aos/util/linked_list_test.cc
deleted file mode 100644
index 6959628..0000000
--- a/aos/util/linked_list_test.cc
+++ /dev/null
@@ -1,119 +0,0 @@
-#include "aos/util/linked_list.h"
-
-#include <vector>
-
-#include "gtest/gtest.h"
-
-namespace aos {
-namespace util {
-namespace testing {
-
-class LinkedListTest : public ::testing::Test {
- public:
- virtual ~LinkedListTest() {
- while (list.head() != nullptr) {
- RemoveElement(list.head());
- }
- }
-
- struct Member {
- Member(int i) : i(i) {}
-
- int i;
- Member *next = nullptr;
- };
- LinkedList<Member> list;
-
- Member *AddElement(int i) {
- Member *member = new Member(i);
- list.Add(member);
- return member;
- }
-
- void RemoveElement(Member *member) {
- list.Remove(member);
- delete member;
- }
-
- Member *GetMember(int i) const {
- return list.Find([i](const Member *member) { return member->i == i; });
- }
-
- bool HasMember(int i) const { return GetMember(i) != nullptr; }
-
- ::std::vector<int> GetMembers() {
- ::std::vector<int> r;
- list.Each([&r](Member *member) { r.push_back(member->i); });
- return r;
- }
-};
-
-// Tests that adding and removing elements works correctly.
-TEST_F(LinkedListTest, Basic) {
- EXPECT_TRUE(list.Empty());
- AddElement(971);
- EXPECT_FALSE(list.Empty());
- AddElement(254);
- EXPECT_FALSE(list.Empty());
- AddElement(1678);
- EXPECT_FALSE(list.Empty());
-
- EXPECT_EQ((::std::vector<int>{1678, 254, 971}), GetMembers());
-
- EXPECT_EQ(1678, list.head()->i);
- RemoveElement(list.head());
- EXPECT_EQ(254, list.head()->i);
- EXPECT_FALSE(list.Empty());
- RemoveElement(list.head());
- EXPECT_EQ(971, list.head()->i);
- EXPECT_FALSE(list.Empty());
- RemoveElement(list.head());
- EXPECT_TRUE(list.Empty());
-}
-
-TEST_F(LinkedListTest, Each) {
- ::std::vector<int> found;
- auto add_to_found = [&found](Member *member) {
- found.push_back(member->i);
- };
-
- AddElement(971);
- found.clear();
- list.Each(add_to_found);
- EXPECT_EQ((::std::vector<int>{971}), found);
-
- AddElement(254);
- found.clear();
- list.Each(add_to_found);
- EXPECT_EQ((::std::vector<int>{254, 971}), found);
-
- AddElement(1678);
- found.clear();
- list.Each(add_to_found);
- EXPECT_EQ((::std::vector<int>{1678, 254, 971}), found);
-}
-
-TEST_F(LinkedListTest, Find) {
- auto find_254 = [](const Member *member) { return member->i == 254; };
-
- AddElement(971);
- EXPECT_EQ(nullptr, list.Find(find_254));
- Member *member = AddElement(254);
- EXPECT_EQ(member, list.Find(find_254));
- AddElement(1678);
- EXPECT_EQ(member, list.Find(find_254));
-}
-
-// Removing an element from the middle of the list used to break it.
-TEST_F(LinkedListTest, RemoveFromMiddle) {
- AddElement(971);
- auto in_middle = AddElement(254);
- AddElement(1678);
- RemoveElement(in_middle);
-
- EXPECT_EQ((::std::vector<int>{1678, 971}), GetMembers());
-}
-
-} // namespace testing
-} // namespace util
-} // namespace aos