File test/lib/circuit/README.md changed (mode: 100644) (index e8eeb01..7b85e05) |
1 |
|
## Objective |
|
|
1 |
|
# circuit |
2 |
2 |
|
|
3 |
|
Syncronize container operations (for single objects) |
|
|
3 |
|
Syncronize container operations for single objects |
4 |
4 |
|
|
5 |
5 |
## Interface |
## Interface |
|
6 |
|
``` |
|
7 |
|
#pragma once |
|
8 |
|
|
|
9 |
|
namespace om636 { |
|
10 |
|
namespace circuit { |
|
11 |
|
|
|
12 |
|
template <class T> |
|
13 |
|
struct Circuit { |
|
14 |
|
typedef T value_type; |
|
15 |
|
|
|
16 |
|
virtual ~Circuit() = default; |
|
17 |
|
virtual void push(value_type&&) = 0; |
|
18 |
|
virtual bool check_pop(value_type&) = 0; |
|
19 |
|
virtual void wait_pop(value_type&) = 0; |
|
20 |
|
virtual Circuit* clone() const = 0; |
|
21 |
|
}; |
|
22 |
|
|
|
23 |
|
} // circuit |
|
24 |
|
} // om636 |
6 |
25 |
|
|
7 |
26 |
``` |
``` |
8 |
|
circuit.check_pop(variable) |
|
9 |
|
circuit.wait_pop(variable) |
|
10 |
|
circuit.push(1); |
|
|
27 |
|
|
|
28 |
|
|
|
29 |
|
## Example |
11 |
30 |
``` |
``` |
|
31 |
|
#include <tmp/src/test.h> |
|
32 |
|
|
|
33 |
|
#include <lib/circuit/src/index.h> |
|
34 |
|
|
|
35 |
|
using namespace std; |
|
36 |
|
using namespace om636::circuit; |
|
37 |
|
|
|
38 |
|
int main() |
|
39 |
|
{ |
|
40 |
|
CircuitStack<int> s; |
|
41 |
|
|
|
42 |
|
s.push(88); |
|
43 |
|
s.push(77); |
|
44 |
|
|
|
45 |
|
int i; |
|
46 |
|
s.wait_pop(i); |
|
47 |
|
if (s.check_pop(i)) { |
|
48 |
|
|
|
49 |
|
} |
|
50 |
|
} |
|
51 |
|
``` |
|
52 |
|
|
File test/lib/circuit/package.json changed (mode: 100644) (index 46fc3d5..5a7c3ec) |
1 |
1 |
{ |
{ |
2 |
2 |
"name": "circuit", |
"name": "circuit", |
3 |
3 |
"version": "1.0.0", |
"version": "1.0.0", |
4 |
|
"description": "", |
|
|
4 |
|
"description": "Syncronize container operations for single objects", |
5 |
5 |
"main": "index.js", |
"main": "index.js", |
6 |
6 |
"directories": { |
"directories": { |
7 |
7 |
"test": "test" |
"test": "test" |
8 |
8 |
}, |
}, |
9 |
9 |
"scripts": { |
"scripts": { |
10 |
10 |
"test": "crimp -g test/test.json", |
"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 |
|
"format": "clang-format -i --style=Webkit src/*.h src/impl/*.h src/impl/*.hxx test/src/*.cpp", |
|
12 |
|
"generateDoc": "doc-tool package_header src_interface ./EXAMPLE.md > README.md" |
12 |
13 |
}, |
}, |
13 |
14 |
"author": "", |
"author": "", |
14 |
15 |
"license": "ISC" |
"license": "ISC" |
File test/lib/circuit/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 test/lib/circuit/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 test/lib/circuit/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 test/lib/dynamo/README.md changed (mode: 100644) (index 9b9214b..64a5f8e) |
... |
... |
Dispatch work to agents. |
6 |
6 |
|
|
7 |
7 |
### Interface:
|
### Interface:
|
8 |
8 |
```
|
```
|
9 |
|
batch.hook( function ) -> agent
|
|
10 |
|
batch.invoke( ... )
|
|
11 |
|
batch.kill( ... )
|
|
12 |
|
batch.kill_invoke( ... )
|
|
13 |
|
batch.is_dead()
|
|
|
9 |
|
namespace om636 {
|
|
10 |
|
namespace control {
|
|
11 |
|
|
|
12 |
|
template <typename... T>
|
|
13 |
|
class Batch {
|
|
14 |
|
public:
|
|
15 |
|
typedef std::function<void(T...)> function_type;
|
|
16 |
|
typedef std::shared_ptr<function_type> agent_type;
|
|
17 |
|
typedef agent_type listener_type;
|
|
18 |
|
|
|
19 |
|
virtual ~Batch() = default;
|
|
20 |
|
virtual agent_type hook(function_type) = 0;
|
|
21 |
|
virtual agent_type hook_once(function_type) = 0;
|
|
22 |
|
virtual void invoke(T...) = 0;
|
|
23 |
|
};
|
|
24 |
|
|
|
25 |
|
} // control
|
|
26 |
|
} // om636
|
14 |
27 |
```
|
```
|
|
28 |
|
|
15 |
29 |
### Dependencies
|
### Dependencies
|
16 |
30 |
|
|
17 |
31 |
Dynamo uses Circuit for thread syncronization
|
Dynamo uses Circuit for thread syncronization
|