Skip to content

MindPerfect/lsignal

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

balmerdx - multiple bugfix and remove untested

- remove untested functionality
- fix delete self/recursive call and other connect/disconnect management 

lsignal: C++ signal/slot system.

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.

Requirements

C++ compiler with support C++17.

How to use

Include lsignal.h in your project.

Essential classes

signal

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

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.

slot

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);

Performance

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

About

C++ signal and slot system

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 97.8%
  • Makefile 1.3%
  • CMake 0.9%