blob: 9d31441a49d27cfbe230538d4678f5cd094e189f [file] [log] [blame]
henrike@webrtc.orgf0488722014-05-13 18:00:26 +00001// sigslot.h: Signal/Slot classes
2//
3// Written by Sarah Thompson (sarah@telergy.com) 2002.
4//
deadbeefd0ffa862017-05-12 22:52:51 -07005// License: Public domain. You are free to use this code however you like, with
6// the proviso that the author takes on no responsibility or liability for any
7// use.
henrike@webrtc.orgf0488722014-05-13 18:00:26 +00008//
9// QUICK DOCUMENTATION
10//
deadbeefd0ffa862017-05-12 22:52:51 -070011// (see also the full documentation at http://sigslot.sourceforge.net/)
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000012//
deadbeefd0ffa862017-05-12 22:52:51 -070013// #define switches
14// SIGSLOT_PURE_ISO:
15// Define this to force ISO C++ compliance. This also disables all of
16// the thread safety support on platforms where it is available.
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000017//
deadbeefd0ffa862017-05-12 22:52:51 -070018// SIGSLOT_USE_POSIX_THREADS:
19// Force use of Posix threads when using a C++ compiler other than gcc
20// on a platform that supports Posix threads. (When using gcc, this is
21// the default - use SIGSLOT_PURE_ISO to disable this if necessary)
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000022//
deadbeefd0ffa862017-05-12 22:52:51 -070023// SIGSLOT_DEFAULT_MT_POLICY:
24// Where thread support is enabled, this defaults to
25// multi_threaded_global. Otherwise, the default is single_threaded.
26// #define this yourself to override the default. In pure ISO mode,
27// anything other than single_threaded will cause a compiler error.
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000028//
deadbeefd0ffa862017-05-12 22:52:51 -070029// PLATFORM NOTES
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000030//
deadbeefd0ffa862017-05-12 22:52:51 -070031// Win32:
32// On Win32, the WEBRTC_WIN symbol must be #defined. Most mainstream
33// compilers do this by default, but you may need to define it yourself
34// if your build environment is less standard. This causes the Win32
35// thread support to be compiled in and used automatically.
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000036//
deadbeefd0ffa862017-05-12 22:52:51 -070037// Unix/Linux/BSD, etc.:
38// If you're using gcc, it is assumed that you have Posix threads
39// available, so they are used automatically. You can override this (as
40// under Windows) with the SIGSLOT_PURE_ISO switch. If you're using
41// something other than gcc but still want to use Posix threads, you
42// need to #define SIGSLOT_USE_POSIX_THREADS.
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000043//
deadbeefd0ffa862017-05-12 22:52:51 -070044// ISO C++:
45// If none of the supported platforms are detected, or if
46// SIGSLOT_PURE_ISO is defined, all multithreading support is turned
47// off, along with any code that might cause a pure ISO C++ environment
48// to complain. Before you ask, gcc -ansi -pedantic won't compile this
49// library, but gcc -ansi is fine. Pedantic mode seems to throw a lot of
50// errors that aren't really there. If you feel like investigating this,
51// please contact the author.
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000052//
53//
deadbeefd0ffa862017-05-12 22:52:51 -070054// THREADING MODES
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000055//
deadbeefd0ffa862017-05-12 22:52:51 -070056// single_threaded:
57// Your program is assumed to be single threaded from the point of view
58// of signal/slot usage (i.e. all objects using signals and slots are
59// created and destroyed from a single thread). Behaviour if objects are
60// destroyed concurrently is undefined (i.e. you'll get the occasional
61// segmentation fault/memory exception).
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000062//
deadbeefd0ffa862017-05-12 22:52:51 -070063// multi_threaded_global:
64// Your program is assumed to be multi threaded. Objects using signals
65// and slots can be safely created and destroyed from any thread, even
66// when connections exist. In multi_threaded_global mode, this is
67// achieved by a single global mutex (actually a critical section on
68// Windows because they are faster). This option uses less OS resources,
69// but results in more opportunities for contention, possibly resulting
70// in more context switches than are strictly necessary.
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000071//
deadbeefd0ffa862017-05-12 22:52:51 -070072// multi_threaded_local:
73// Behaviour in this mode is essentially the same as
74// multi_threaded_global, except that each signal, and each object that
75// inherits has_slots, all have their own mutex/critical section. In
76// practice, this means that mutex collisions (and hence context
77// switches) only happen if they are absolutely essential. However, on
78// some platforms, creating a lot of mutexes can slow down the whole OS,
79// so use this option with care.
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000080//
deadbeefd0ffa862017-05-12 22:52:51 -070081// USING THE LIBRARY
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000082//
deadbeefd0ffa862017-05-12 22:52:51 -070083// See the full documentation at http://sigslot.sourceforge.net/
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000084//
85// Libjingle specific:
deadbeefd0ffa862017-05-12 22:52:51 -070086//
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000087// This file has been modified such that has_slots and signalx do not have to be
88// using the same threading requirements. E.g. it is possible to connect a
89// has_slots<single_threaded> and signal0<multi_threaded_local> or
90// has_slots<multi_threaded_local> and signal0<single_threaded>.
91// If has_slots is single threaded the user must ensure that it is not trying
92// to connect or disconnect to signalx concurrently or data race may occur.
93// If signalx is single threaded the user must ensure that disconnect, connect
94// or signal is not happening concurrently or data race may occur.
95
Henrik Kjellander67765182017-06-28 20:58:07 +020096#ifndef WEBRTC_BASE_SIGSLOT_H_
97#define WEBRTC_BASE_SIGSLOT_H_
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000098
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000099
Henrik Kjellander67765182017-06-28 20:58:07 +0200100// This header is deprecated and is just left here temporarily during
101// refactoring. See https://bugs.webrtc.org/7634 for more details.
102#include "webrtc/rtc_base/sigslot.h"
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000103
Henrik Kjellander67765182017-06-28 20:58:07 +0200104#endif // WEBRTC_BASE_SIGSLOT_H_