- remove untested functionality
- fix delete self/recursive call and other connect/disconnect management
lsignal (or lightweight signal) is a very little and fast C++ thread-safe implementation of signal and slot system which is based on modern C++11 code.
C++ compiler with support C++17.
Include lsignal.h in your project.
This is a template class which holds callbacks and can emit signals with certain arguments. See examples of declarations:
| Declaration | Description |
|---|---|
lsignal::signal<void()> s; |
Signal without parameters, return type - void |
lsignal::signal<int(int,int)> t; |
Signal with two parameters, return type - int |
lsignal::signal<std::string()> u; |
Signal without parameters, return type - std::string |
You can connect to signal any callback which looks like callable object but be aware than signature of callback must be equal signature of corresponding signal:
| Callback | Description |
|---|---|
s.connect(foo, owner); |
foo is a common function |
s.connect(bar, owner); |
bar is a lambda function |
s.connect(baz, owner); |
baz is a class with operator() |
s.connect(&qx, &qux::func, &qx); |
qx is a instance of class qux : public lsignal::slot |
Result of this function is a instance of class connection.
When signal is emitted return value will be the result of executing last connected callback.
connection contains link between signal and callback. Available next operations:
| Method | Description |
|---|---|
is_locked |
Check if connection is locked |
set_lock |
If connection is locked then callback won't be called |
disconnect |
Remove callback from signal |
Also you can pass connection directly to signal::disconnect for disconnecting this connection.
This class similar to connection but is used for owhership policy. Look example:
class foo : public lsignal::slot
{
...
};
...
foo f;
// disconnect when f was destroyed
s.connect([](){ ... }, &f);Synthetic test (one or more empty callbacks) showed that calling lsignal from two
to five times faster than calling boost::signal2 which was created with dummy (empty) mutex.
balmerdx My test lsignal is 2x faster then boost::signal2