Subject | Hash | Author | Date (UTC) |
---|---|---|---|
clone method | 8ed894a629b78d61421f1b707564756fb0bb4f90 | mucbuc | 2020-01-25 20:01:53 |
siplify example | d3f446eed13921445fd6f16f345e50e873a245e8 | mucbuc | 2020-01-24 14:44:36 |
Edited README.md | c4daca7870daa3a2bcc3cb3a56353b075feeea83 | mark | 2020-01-21 05:25:32 |
Edited README.md | dd5ec0c9fb495adc91a3446c6029e10cbca50741 | mark | 2020-01-21 05:23:48 |
Edited README.md | 7b965f28e6800858cb7250e4a838a11d99aa9146 | mark | 2020-01-21 05:22:23 |
README.md | b04ce36a75a1cc03f592f498320bcbd2487391e3 | Ubuntu | 2020-01-21 05:17:29 |
stack example | 10c89c204a6c7173da4cab531b023e49b43b282f | Ubuntu | 2020-01-21 05:10:05 |
rename namespace | 58de02fbcccc180ddbd895c03fe7615d85079fc2 | mucbuc | 2020-01-19 12:06:11 |
cleanup | 5ffc59ee2057db41384465ada3ce02da94928d83 | mucbuc | 2020-01-19 11:48:09 |
fixed swap | e79678e9a0f6c401bf6c75c073b4afb1d9c99239 | mucbuc | 2020-01-16 12:33:51 |
add unlock | ed0dd962bd7e1468faa3f74a6d61c6ba94b8db13 | mucbuc | 2020-01-12 16:43:19 |
documentaoion | 731b8bf31861113f070ee9e3613fdfbaef1e70a6 | mucbuc | 2020-01-12 15:46:29 |
index.h | 74aafab338206a3d3c02b7448852dbde831692dc | mucbuc | 2020-01-12 04:42:02 |
factory returns shared_ptr | 0d8ff1b381e3c7e275ebd99705853f54b100cdf9 | mucbuc | 2020-01-12 04:05:15 |
init | 01daaea5899ac77acb8ec0c15583573d78eb9f31 | mucbuc | 2020-01-12 03:10:36 |
File | Lines added | Lines deleted |
---|---|---|
src/impl/circuit_host.h | 2 | 0 |
src/impl/circuit_host.hxx | 23 | 2 |
src/impl/queue.h | 8 | 0 |
src/impl/stack.h | 8 | 0 |
src/index.h | 5 | 6 |
src/interface.h | 1 | 1 |
test/src/example.cpp | 1 | 2 |
test/src/main.cpp | 0 | 1 |
File src/impl/circuit_host.h changed (mode: 100644) (index be202e3..375f033) | |||
... | ... | namespace circuit { | |
17 | 17 | using typename base_type::value_type; | using typename base_type::value_type; |
18 | 18 | ||
19 | 19 | CircuitHost() = default; | CircuitHost() = default; |
20 | CircuitHost(const CircuitHost&); | ||
20 | 21 | CircuitHost(CircuitHost&&); | CircuitHost(CircuitHost&&); |
21 | 22 | CircuitHost& operator=(CircuitHost); | CircuitHost& operator=(CircuitHost); |
22 | 23 | ||
... | ... | namespace circuit { | |
28 | 29 | void push(value_type&&) override; | void push(value_type&&) override; |
29 | 30 | bool check_pop(value_type&) override; | bool check_pop(value_type&) override; |
30 | 31 | void wait_pop(value_type&) override; | void wait_pop(value_type&) override; |
32 | CircuitHost* clone() const override; | ||
31 | 33 | ||
32 | 34 | private: | private: |
33 | 35 | typedef U<T> policy_type; | typedef U<T> policy_type; |
File src/impl/circuit_host.hxx changed (mode: 100644) (index 178dfb8..fdf9742) | |||
1 | 1 | namespace om636 { | namespace om636 { |
2 | 2 | namespace circuit { | namespace circuit { |
3 | 3 | ||
4 | ///////////////////////////////////////////////////////////////////////////////////////////// | ||
5 | template <typename T, template <typename> class U> | ||
6 | CircuitHost<T, U>::CircuitHost(const CircuitHost& rhs) | ||
7 | { | ||
8 | typedef std::unique_lock<mutex_type> lock_type; | ||
9 | |||
10 | lock_type left_lock(m_mutex, std::defer_lock); | ||
11 | lock_type right_lock(rhs.m_mutex, std::defer_lock); | ||
12 | std::lock(left_lock, right_lock); | ||
13 | |||
14 | policy_type::on_copy(*this, rhs); | ||
15 | } | ||
16 | |||
4 | 17 | ///////////////////////////////////////////////////////////////////////////////////////////// | ///////////////////////////////////////////////////////////////////////////////////////////// |
5 | 18 | template <typename T, template <typename> class U> | template <typename T, template <typename> class U> |
6 | 19 | CircuitHost<T, U>::CircuitHost(CircuitHost&& rhs) | CircuitHost<T, U>::CircuitHost(CircuitHost&& rhs) |
... | ... | namespace circuit { | |
48 | 61 | bool result(false); | bool result(false); |
49 | 62 | std::thread([this, &result]() { | std::thread([this, &result]() { |
50 | 63 | result = m_mutex.try_lock(); | result = m_mutex.try_lock(); |
51 | if (result) { | ||
52 | m_mutex.unlock(); | ||
64 | if (result) { | ||
65 | m_mutex.unlock(); | ||
53 | 66 | } | } |
54 | 67 | }).join(); | }).join(); |
55 | 68 | return !result; | return !result; |
... | ... | namespace circuit { | |
86 | 99 | m_condition.wait(lock, [this] { return !policy_type::on_empty(*this); }); | m_condition.wait(lock, [this] { return !policy_type::on_empty(*this); }); |
87 | 100 | policy_type::on_pop(*this, value); | policy_type::on_pop(*this, value); |
88 | 101 | } | } |
102 | |||
103 | ///////////////////////////////////////////////////////////////////////////////////////////// | ||
104 | template <typename T, template <typename> class U> | ||
105 | auto CircuitHost<T, U>::clone() const -> CircuitHost* | ||
106 | { | ||
107 | return new CircuitHost(*this); | ||
108 | } | ||
109 | |||
89 | 110 | } // circuit | } // circuit |
90 | 111 | } // om636 | } // om636 |
File src/impl/queue.h changed (mode: 100644) (index bc763a3..b4aaa20) | |||
... | ... | namespace circuit { | |
17 | 17 | lhs.m_queue = std::move(rhs.m_queue); | lhs.m_queue = std::move(rhs.m_queue); |
18 | 18 | } | } |
19 | 19 | ||
20 | template <class U> | ||
21 | static void on_copy(U& lhs, const U& rhs) | ||
22 | { | ||
23 | ASSERT(lhs.is_locked()); | ||
24 | ASSERT(rhs.is_locked()); | ||
25 | lhs.m_queue = rhs.m_queue; | ||
26 | } | ||
27 | |||
20 | 28 | template <class U> | template <class U> |
21 | 29 | static void on_swap(U& lhs, U& rhs) | static void on_swap(U& lhs, U& rhs) |
22 | 30 | { | { |
File src/impl/stack.h changed (mode: 100644) (index bdbf6ac..4f0cdea) | |||
... | ... | namespace circuit { | |
9 | 9 | struct StackPolicy { | struct StackPolicy { |
10 | 10 | typedef T value_type; | typedef T value_type; |
11 | 11 | ||
12 | template <class U> | ||
13 | static void on_copy(U& lhs, const U& rhs) | ||
14 | { | ||
15 | ASSERT(lhs.is_locked()); | ||
16 | ASSERT(rhs.is_locked()); | ||
17 | lhs.m_stack = rhs.m_stack; | ||
18 | } | ||
19 | |||
12 | 20 | template <class U> | template <class U> |
13 | 21 | static void on_init(U& lhs, U&& rhs) | static void on_init(U& lhs, U&& rhs) |
14 | 22 | { | { |
File src/index.h changed (mode: 100644) (index 1742512..aac2bba) | |||
1 | 1 | #pragma once | #pragma once |
2 | 2 | ||
3 | 3 | #include "impl/circuit_host.h" | #include "impl/circuit_host.h" |
4 | #include "impl/stack.h" | ||
5 | 4 | #include "impl/queue.h" | #include "impl/queue.h" |
5 | #include "impl/stack.h" | ||
6 | 6 | ||
7 | 7 | namespace om636 { | namespace om636 { |
8 | 8 | namespace circuit { | namespace circuit { |
9 | 9 | ||
10 | template<typename T> | ||
11 | using CircuitStack = CircuitHost<T, StackPolicy>; | ||
10 | template <typename T> | ||
11 | using CircuitStack = CircuitHost<T, StackPolicy>; | ||
12 | 12 | ||
13 | template<typename T> | ||
14 | using CircuitQueue = CircuitHost<T, QueuePolicy>; | ||
13 | template <typename T> | ||
14 | using CircuitQueue = CircuitHost<T, QueuePolicy>; | ||
15 | 15 | ||
16 | 16 | } // circuit | } // circuit |
17 | 17 | } // om636 | } // om636 |
18 |
File src/interface.h changed (mode: 100644) (index 32d8ab4..8b562d1) | |||
... | ... | namespace circuit { | |
11 | 11 | virtual void push(value_type&&) = 0; | virtual void push(value_type&&) = 0; |
12 | 12 | virtual bool check_pop(value_type&) = 0; | virtual bool check_pop(value_type&) = 0; |
13 | 13 | virtual void wait_pop(value_type&) = 0; | virtual void wait_pop(value_type&) = 0; |
14 | virtual Circuit* clone() const = 0; | ||
14 | 15 | }; | }; |
15 | 16 | ||
16 | 17 | } // circuit | } // circuit |
17 | 18 | } // om636 | } // om636 |
18 |
File test/src/example.cpp changed (mode: 100644) (index 5afe92a..52afea0) | |||
... | ... | using namespace om636::circuit; | |
8 | 8 | int main() | int main() |
9 | 9 | { | { |
10 | 10 | CircuitStack<int> s; | CircuitStack<int> s; |
11 | |||
11 | |||
12 | 12 | s.push(88); | s.push(88); |
13 | 13 | s.push(77); | s.push(77); |
14 | 14 | ||
15 | 15 | s.wait_pop(i); | s.wait_pop(i); |
16 | 16 | if (s.check_pop(i)) { | if (s.check_pop(i)) { |
17 | |||
18 | 17 | } | } |
19 | 18 | } | } |
File test/src/main.cpp changed (mode: 100644) (index dd6faf3..df6a636) | |||
... | ... | int main() | |
25 | 25 | test_wait_pop(std::make_shared<CircuitStack<int>>()); | test_wait_pop(std::make_shared<CircuitStack<int>>()); |
26 | 26 | test_wait_pop(std::make_shared<CircuitQueue<int>>()); | test_wait_pop(std::make_shared<CircuitQueue<int>>()); |
27 | 27 | ||
28 | |||
29 | 28 | CircuitQueue<int> a, b; | CircuitQueue<int> a, b; |
30 | 29 | a.swap(b); | a.swap(b); |
31 | 30 |