henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1 | // sigslot.h: Signal/Slot classes |
| 2 | // |
| 3 | // Written by Sarah Thompson (sarah@telergy.com) 2002. |
| 4 | // |
deadbeef | d0ffa86 | 2017-05-12 22:52:51 -0700 | [diff] [blame] | 5 | // 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.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 8 | // |
| 9 | // QUICK DOCUMENTATION |
| 10 | // |
deadbeef | d0ffa86 | 2017-05-12 22:52:51 -0700 | [diff] [blame] | 11 | // (see also the full documentation at http://sigslot.sourceforge.net/) |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 12 | // |
deadbeef | d0ffa86 | 2017-05-12 22:52:51 -0700 | [diff] [blame] | 13 | // #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.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 17 | // |
deadbeef | d0ffa86 | 2017-05-12 22:52:51 -0700 | [diff] [blame] | 18 | // 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.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 22 | // |
deadbeef | d0ffa86 | 2017-05-12 22:52:51 -0700 | [diff] [blame] | 23 | // 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.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 28 | // |
deadbeef | d0ffa86 | 2017-05-12 22:52:51 -0700 | [diff] [blame] | 29 | // PLATFORM NOTES |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 30 | // |
deadbeef | d0ffa86 | 2017-05-12 22:52:51 -0700 | [diff] [blame] | 31 | // 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.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 36 | // |
deadbeef | d0ffa86 | 2017-05-12 22:52:51 -0700 | [diff] [blame] | 37 | // 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.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 43 | // |
deadbeef | d0ffa86 | 2017-05-12 22:52:51 -0700 | [diff] [blame] | 44 | // 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.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 52 | // |
| 53 | // |
deadbeef | d0ffa86 | 2017-05-12 22:52:51 -0700 | [diff] [blame] | 54 | // THREADING MODES |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 55 | // |
deadbeef | d0ffa86 | 2017-05-12 22:52:51 -0700 | [diff] [blame] | 56 | // 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.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 62 | // |
deadbeef | d0ffa86 | 2017-05-12 22:52:51 -0700 | [diff] [blame] | 63 | // 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.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 71 | // |
deadbeef | d0ffa86 | 2017-05-12 22:52:51 -0700 | [diff] [blame] | 72 | // 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.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 80 | // |
deadbeef | d0ffa86 | 2017-05-12 22:52:51 -0700 | [diff] [blame] | 81 | // USING THE LIBRARY |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 82 | // |
deadbeef | d0ffa86 | 2017-05-12 22:52:51 -0700 | [diff] [blame] | 83 | // See the full documentation at http://sigslot.sourceforge.net/ |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 84 | // |
| 85 | // Libjingle specific: |
deadbeef | d0ffa86 | 2017-05-12 22:52:51 -0700 | [diff] [blame] | 86 | // |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 87 | // 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 Kjellander | 6776518 | 2017-06-28 20:58:07 +0200 | [diff] [blame] | 96 | #ifndef WEBRTC_BASE_SIGSLOT_H_ |
| 97 | #define WEBRTC_BASE_SIGSLOT_H_ |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 98 | |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 99 | |
Henrik Kjellander | 6776518 | 2017-06-28 20:58:07 +0200 | [diff] [blame] | 100 | // 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.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 103 | |
Henrik Kjellander | 6776518 | 2017-06-28 20:58:07 +0200 | [diff] [blame] | 104 | #endif // WEBRTC_BASE_SIGSLOT_H_ |