Subject | Hash | Author | Date (UTC) |
---|---|---|---|
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 |
---|---|---|
package.json | 2 | 1 |
src/factory.h | 11 | 12 |
src/impl/circuit_host.hxx | 4 | 4 |
test/src/main.cpp | 2 | 2 |
File package.json changed (mode: 100644) (index 2dffab3..46fc3d5) | |||
7 | 7 | "test": "test" | "test": "test" |
8 | 8 | }, | }, |
9 | 9 | "scripts": { | "scripts": { |
10 | "test": "crimp -g test/test.json" | ||
10 | "test": "crimp -g test/test.json", | ||
11 | "format": "clang-format -i --style=Webkit src/*.h src/impl/*.h src/impl/*.hxx test/src/*.cpp" | ||
11 | 12 | }, | }, |
12 | 13 | "author": "", | "author": "", |
13 | 14 | "license": "ISC" | "license": "ISC" |
File src/factory.h changed (mode: 100644) (index 027ee94..b5e155e) | |||
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 twice_size { | namespace twice_size { |
9 | 9 | ||
10 | template<typename T> | ||
11 | Circuit<T> * make_stack() | ||
12 | { | ||
13 | return new CircuitHost<T, StackPolicy>(); | ||
14 | } | ||
10 | template <typename T> | ||
11 | std::shared_ptr<Circuit<T>> make_stack() | ||
12 | { | ||
13 | return std::make_shared<CircuitHost<T, StackPolicy>>(); | ||
14 | } | ||
15 | 15 | ||
16 | template<typename T> | ||
17 | Circuit<T> * make_queue() | ||
18 | { | ||
19 | return new CircuitHost<T, QueuePolicy>(); | ||
20 | } | ||
16 | template <typename T> | ||
17 | std::shared_ptr<Circuit<T>> make_queue() | ||
18 | { | ||
19 | return std::make_shared<CircuitHost<T, QueuePolicy>>(); | ||
20 | } | ||
21 | 21 | } // twice_size | } // twice_size |
22 | 22 | } // om636 | } // om636 |
23 |
File src/impl/circuit_host.hxx changed (mode: 100644) (index a7f2410..b07e458) | |||
... | ... | namespace twice_size { | |
45 | 45 | template <typename T, template <typename> class U> | template <typename T, template <typename> class U> |
46 | 46 | bool CircuitHost<T, U>::is_locked() const | bool CircuitHost<T, U>::is_locked() const |
47 | 47 | { | { |
48 | bool result( false ); | ||
49 | std::thread([this, & result]() { | ||
50 | result = m_mutex.try_lock(); | ||
51 | }).join(); | ||
48 | bool result(false); | ||
49 | std::thread([this, &result]() { | ||
50 | result = m_mutex.try_lock(); | ||
51 | }).join(); | ||
52 | 52 | return !result; | return !result; |
53 | 53 | } | } |
54 | 54 |
File test/src/main.cpp changed (mode: 100644) (index b082b21..9752dd4) | |||
... | ... | int main() | |
23 | 23 | { | { |
24 | 24 | using namespace om636::twice_size; | using namespace om636::twice_size; |
25 | 25 | ||
26 | test_wait_pop(std::shared_ptr<Circuit<int>>(make_stack<int>())); | ||
27 | test_wait_pop(std::shared_ptr<Circuit<int>>(make_queue<int>())); | ||
26 | test_wait_pop(make_stack<int>()); | ||
27 | test_wait_pop(make_queue<int>()); | ||
28 | 28 | ||
29 | 29 | return 0; | return 0; |
30 | 30 | } | } |