]> git.lyx.org Git - lyx.git/blob - 3rdparty/nod/nod.hpp
Comments
[lyx.git] / 3rdparty / nod / nod.hpp
1 #ifndef IG_NOD_INCLUDE_NOD_HPP
2 #define IG_NOD_INCLUDE_NOD_HPP
3
4 #include <vector>       // std::vector
5 #include <functional>   // std::function
6 #include <mutex>        // std::mutex, std::lock_guard
7 #include <memory>       // std::shared_ptr, std::weak_ptr
8 #include <algorithm>    // std::find_if()
9 #include <cassert>      // assert()
10 #include <thread>       // std::this_thread::yield()
11 #include <type_traits>  // std::is_same
12 #include <iterator>     // std::back_inserter
13
14 namespace nod {
15         // implementational details
16         namespace detail {
17                 /// Interface for type erasure when disconnecting slots
18                 struct disconnector {
19                         virtual void operator()( std::size_t index ) const = 0;
20                 };
21                 /// Deleter that doesn't delete
22                 inline void no_delete(disconnector*){
23                 };
24         } // namespace detail
25
26         /// Base template for the signal class
27         template <class P, class T>
28         class signal_type;
29
30
31         /// Connection class.
32         ///
33         /// This is used to be able to disconnect slots after they have been connected.
34         /// Used as return type for the connect method of the signals.
35         ///
36         /// Connections are default constructible.
37         /// Connections are not copy constructible or copy assignable.
38         /// Connections are move constructible and move assignable.
39         ///
40         class connection {
41                 public:
42                         /// Default constructor
43                         connection() :
44                                 _index()
45                         {}
46
47                         // Connection are not copy constructible or copy assignable
48                         connection( connection const& ) = delete;
49                         connection& operator=( connection const& ) = delete;
50
51                         /// Move constructor
52                         /// @param other   The instance to move from.
53                         connection( connection&& other ) :
54                                 _weak_disconnector( std::move(other._weak_disconnector) ),
55                                 _index( other._index )
56                         {}
57
58                         /// Move assign operator.
59                         /// @param other   The instance to move from.
60                         connection& operator=( connection&& other ) {
61                                 _weak_disconnector = std::move( other._weak_disconnector );
62                                 _index = other._index;
63                                 return *this;
64                         }
65
66                         /// @returns `true` if the connection is connected to a signal object,
67                         ///          and `false` otherwise.
68                         bool connected() const {
69                                 return !_weak_disconnector.expired();
70                         }
71
72                         /// Disconnect the slot from the connection.
73                         ///
74                         /// If the connection represents a slot that is connected to a signal object, calling
75                         /// this method will disconnect the slot from that object. The result of this operation
76                         /// is that the slot will stop receiving calls when the signal is invoked.
77                         void disconnect();
78
79                 private:
80                         /// The signal template is a friend of the connection, since it is the
81                         /// only one allowed to create instances using the meaningful constructor.
82                         template<class P,class T> friend class signal_type;
83
84                         /// Create a connection.
85                         /// @param shared_disconnector   Disconnector instance that will be used to disconnect
86                         ///                              the connection when the time comes. A weak pointer
87                         ///                              to the disconnector will be held within the connection
88                         ///                              object.
89                         /// @param index                 The slot index of the connection.
90                         connection( std::shared_ptr<detail::disconnector> const& shared_disconnector, std::size_t index ) :
91                                 _weak_disconnector( shared_disconnector ),
92                                 _index( index )
93                         {}
94
95                         /// Weak pointer to the current disconnector functor.
96                         std::weak_ptr<detail::disconnector> _weak_disconnector;
97                         /// Slot index of the connected slot.
98                         std::size_t _index;
99         };
100
101         /// Scoped connection class.
102         ///
103         /// This type of connection is automatically disconnected when
104         /// the connection object is destructed.
105         ///
106         class scoped_connection
107         {
108                 public:
109                         /// Scoped are default constructible
110                         scoped_connection() = default;
111                         /// Scoped connections are not copy constructible
112                         scoped_connection( scoped_connection const& ) = delete;
113                         /// Scoped connections are not copy assingable
114                         scoped_connection& operator=( scoped_connection const& ) = delete;
115
116                         /// Move constructor
117                         scoped_connection( scoped_connection&& other ) :
118                                 _connection( std::move(other._connection) )
119                         {}
120
121                         /// Move assign operator.
122                         /// @param other   The instance to move from.
123                         scoped_connection& operator=( scoped_connection&& other ) {
124                                 reset( std::move( other._connection ) );
125                                 return *this;
126                         }
127
128                         /// Construct a scoped connection from a connection object
129                         /// @param connection   The connection object to manage
130                         scoped_connection( connection&& c ) :
131                                 _connection( std::forward<connection>(c) )
132                         {}
133
134                         /// destructor
135                         ~scoped_connection() {
136                                 disconnect();
137                         }
138
139                         /// Assignment operator moving a new connection into the instance.
140                         /// @note If the scoped_connection instance already contains a
141                         ///       connection, that connection will be disconnected as if
142                         ///       the scoped_connection was destroyed.
143                         /// @param c   New connection to manage
144                         scoped_connection& operator=( connection&& c ) {
145                                 reset( std::forward<connection>(c) );
146                                 return *this;
147                         }
148
149                         /// Reset the underlying connection to another connection.
150                         /// @note The connection currently managed by the scoped_connection
151                         ///       instance will be disconnected when resetting.
152                         /// @param c   New connection to manage
153                         void reset( connection&& c = {} ) {
154                                 disconnect();
155                                 _connection = std::move(c);
156                         }
157
158                         /// Release the underlying connection, without disconnecting it.
159                         /// @returns The newly released connection instance is returned.
160                         connection release() {
161                                 connection c = std::move(_connection);
162                                 _connection = connection{};
163                                 return c;
164                         }
165
166                         ///
167                         /// @returns `true` if the connection is connected to a signal object,
168                         ///          and `false` otherwise.
169                         bool connected() const {
170                                 return _connection.connected();
171                         }
172
173                         /// Disconnect the slot from the connection.
174                         ///
175                         /// If the connection represents a slot that is connected to a signal object, calling
176                         /// this method will disconnect the slot from that object. The result of this operation
177                         /// is that the slot will stop receiving calls when the signal is invoked.
178                         void disconnect() {
179                                 _connection.disconnect();
180                         }
181
182                 private:
183                         /// Underlying connection object
184                         connection _connection;
185         };
186
187         /// Policy for multi threaded use of signals.
188         ///
189         /// This policy provides mutex and lock types for use in
190         /// a multithreaded environment, where signals and slots
191         /// may exists in different threads.
192         ///
193         /// This policy is used in the `nod::signal` type provided
194         /// by the library.
195         struct multithread_policy
196         {
197                 using mutex_type = std::mutex;
198                 using mutex_lock_type = std::unique_lock<mutex_type>;
199                 /// Function that yields the current thread, allowing
200                 /// the OS to reschedule.
201                 static void yield_thread() {
202                         std::this_thread::yield();
203                 }
204                 /// Function that defers a lock to a lock function that prevents deadlock
205                 static mutex_lock_type defer_lock(mutex_type & m){
206                         return mutex_lock_type{m, std::defer_lock};
207                 }
208                 /// Function that locks two mutexes and prevents deadlock
209                 static void lock(mutex_lock_type & a,mutex_lock_type & b) {
210                         std::lock(a,b);
211                 }
212         };
213
214         /// Policy for single threaded use of signals.
215         ///
216         /// This policy provides dummy implementations for mutex
217         /// and lock types, resulting in that no synchronization
218         /// will take place.
219         ///
220         /// This policy is used in the `nod::unsafe_signal` type
221         /// provided by the library.
222         struct singlethread_policy
223         {
224                 /// Dummy mutex type that doesn't do anything
225                 struct mutex_type{};
226                 /// Dummy lock type, that doesn't do any locking.
227                 struct mutex_lock_type
228                 {
229                         /// A lock type must be constructible from a
230                         /// mutex type from the same thread policy.
231                         explicit mutex_lock_type( mutex_type const& ) {
232                         }
233                 };
234                 /// Dummy implementation of thread yielding, that
235                 /// doesn't do any actual yielding.
236                 static void yield_thread() {
237                 }
238                 /// Dummy implemention of defer_lock that doesn't
239                 /// do anything
240                 static mutex_lock_type defer_lock(mutex_type &m){
241                         return mutex_lock_type{m};
242                 }
243                 /// Dummy implemention of lock that doesn't
244                 /// do anything
245                 static void lock(mutex_lock_type &,mutex_lock_type &) {
246                 }
247         };
248
249         /// Signal accumulator class template.
250         ///
251         /// This acts sort of as a proxy for triggering a signal and
252         /// accumulating the slot return values.
253         ///
254         /// This class is not really intended to instantiate by client code.
255         /// Instances are aquired as return values of the method `accumulate()`
256         /// called on signals.
257         ///
258         /// @tparam S      Type of signal. The signal_accumulator acts
259         ///                as a type of proxy for a signal instance of
260         ///                this type.
261         /// @tparam T      Type of initial value of the accumulate algorithm.
262         ///                This type must meet the requirements of `CopyAssignable`
263         ///                and `CopyConstructible`
264         /// @tparam F      Type of accumulation function.
265         /// @tparam A...   Argument types of the underlying signal type.
266         ///
267         template <class S, class T, class F, class...A>
268         class signal_accumulator
269         {
270                 public:
271                         /// Result type when calling the accumulating function operator.
272                         using result_type = typename std::result_of<F(T, typename S::slot_type::result_type)>::type;
273
274                         /// Construct a signal_accumulator as a proxy to a given signal
275                         //
276                         /// @param signal   Signal instance.
277                         /// @param init     Initial value of the accumulate algorithm.
278                         /// @param func     Binary operation function object that will be
279                         ///                 applied to all slot return values.
280                         ///                 The signature of the function should be
281                         ///                 equivalent of the following:
282                         ///                   `R func( T1 const& a, T2 const& b )`
283                         ///                  - The signature does not need to have `const&`.
284                         ///                  - The initial value, type `T`, must be implicitly
285                         ///                    convertible to `R`
286                         ///                  - The return type `R` must be implicitly convertible
287                         ///                    to type `T1`.
288                         ///                  - The type `R` must be `CopyAssignable`.
289                         ///                  - The type `S::slot_type::result_type` (return type of
290                         ///                    the signals slots) must be implicitly convertible to
291                         ///                    type `T2`.
292                         signal_accumulator( S const& signal, T init, F func ) :
293                                 _signal( signal ),
294                                 _init( init ),
295                                 _func( func )
296                         {}
297
298                         /// Function call operator.
299                         ///
300                         /// Calling this will trigger the underlying signal and accumulate
301                         /// all of the connected slots return values with the current
302                         /// initial value and accumulator function.
303                         ///
304                         /// When called, this will invoke the accumulator function will
305                         /// be called for each return value of the slots. The semantics
306                         /// are similar to the `std::accumulate` algorithm.
307                         ///
308                         /// @param args   Arguments to propagate to the slots of the
309                         ///               underlying when triggering the signal.
310                         result_type operator()( A const& ... args ) const {
311                                 return _signal.trigger_with_accumulator( _init, _func, args... );
312                         }
313
314                 private:
315
316                         /// Reference to the underlying signal to proxy.
317                         S const& _signal;
318                         /// Initial value of the accumulate algorithm.
319                         T _init;
320                         /// Accumulator function.
321                         F _func;
322
323         };
324
325         /// Signal template specialization.
326         ///
327         /// This is the main signal implementation, and it is used to
328         /// implement the observer pattern whithout the overhead
329         /// boilerplate code that typically comes with it.
330         ///
331         /// Any function or function object is considered a slot, and
332         /// can be connected to a signal instance, as long as the signature
333         /// of the slot matches the signature of the signal.
334         ///
335         /// @tparam P      Threading policy for the signal.
336         ///                A threading policy must provide two type definitions:
337         ///                 - P::mutex_type, this type will be used as a mutex
338         ///                   in the signal_type class template.
339         ///                 - P::mutex_lock_type, this type must implement a
340         ///                   constructor that takes a P::mutex_type as a parameter,
341         ///                   and it must have the semantics of a scoped mutex lock
342         ///                   like std::lock_guard, i.e. locking in the constructor
343         ///                   and unlocking in the destructor.
344         ///
345         /// @tparam R      Return value type of the slots connected to the signal.
346         /// @tparam A...   Argument types of the slots connected to the signal.
347         template <class P, class R, class... A >
348         class signal_type<P,R(A...)>
349         {
350                 public:
351                         /// signals are not copy constructible
352                         signal_type( signal_type const& ) = delete;
353                         /// signals are not copy assignable
354                         signal_type& operator=( signal_type const& ) = delete;
355                         /// signals are move constructible
356                         signal_type(signal_type&& other)
357                         {
358                                 mutex_lock_type lock{other._mutex};
359                                 _slot_count = std::move(other._slot_count);
360                                 _slots = std::move(other._slots);
361                                 if(other._shared_disconnector != nullptr)
362                                 {
363                                         _disconnector = disconnector{ this };
364                                         _shared_disconnector = std::move(other._shared_disconnector);
365                                         // replace the disconnector with our own disconnector
366                                         *static_cast<disconnector*>(_shared_disconnector.get()) = _disconnector;
367                                 }
368                         }
369                         /// signals are move assignable
370                         signal_type& operator=(signal_type&& other)
371                         {
372                                 auto lock = thread_policy::defer_lock(_mutex);
373                                 auto other_lock = thread_policy::defer_lock(other._mutex);
374                                 thread_policy::lock(lock,other_lock);
375
376                                 _slot_count = std::move(other._slot_count);
377                                 _slots = std::move(other._slots);
378                                 if(other._shared_disconnector != nullptr)
379                                 {
380                                         _disconnector = disconnector{ this };
381                                         _shared_disconnector = std::move(other._shared_disconnector);
382                                         // replace the disconnector with our own disconnector
383                                         *static_cast<disconnector*>(_shared_disconnector.get()) = _disconnector;
384                                 }
385                                 return *this;
386                         }
387
388                         /// signals are default constructible
389                         signal_type() :
390                                 _slot_count(0)
391                         {}
392
393                         // Destruct the signal object.
394                         ~signal_type() {
395                                 invalidate_disconnector();
396                         }
397
398                         /// Type that will be used to store the slots for this signal type.
399                         using slot_type = std::function<R(A...)>;
400                         /// Type that is used for counting the slots connected to this signal.
401                         using size_type = typename std::vector<slot_type>::size_type;
402
403
404                         /// Connect a new slot to the signal.
405                         ///
406                         /// The connected slot will be called every time the signal
407                         /// is triggered.
408                         /// @param slot   The slot to connect. This must be a callable with
409                         ///               the same signature as the signal itself.
410                         /// @return       A connection object is returned, and can be used to
411                         ///               disconnect the slot.
412                         template <class T>
413                         connection connect( T&& slot ) {
414                                 mutex_lock_type lock{ _mutex };
415                                 _slots.push_back( std::forward<T>(slot) );
416                                 std::size_t index = _slots.size()-1;
417                                 if( _shared_disconnector == nullptr ) {
418                                         _disconnector = disconnector{ this };
419                                         _shared_disconnector = std::shared_ptr<detail::disconnector>{&_disconnector, detail::no_delete};
420                                 }
421                                 ++_slot_count;
422                                 return connection{ _shared_disconnector, index };
423                         }
424
425                         /// Function call operator.
426                         ///
427                         /// Calling this is how the signal is triggered and the
428                         /// connected slots are called.
429                         ///
430                         /// @note The slots will be called in the order they were
431                         ///       connected to the signal.
432                         ///
433                         /// @param args   Arguments that will be propagated to the
434                         ///               connected slots when they are called.
435                         void operator()( A const&... args ) const {
436                                 for( auto const& slot : copy_slots() ) {
437                                         if( slot ) {
438                                                 slot( args... );
439                                         }
440                                 }
441                         }
442
443                         /// Construct a accumulator proxy object for the signal.
444                         ///
445                         /// The intended purpose of this function is to create a function
446                         /// object that can be used to trigger the signal and accumulate
447                         /// all the slot return values.
448                         ///
449                         /// The algorithm used to accumulate slot return values is similar
450                         /// to `std::accumulate`. A given binary function is called for
451                         /// each return value with the parameters consisting of the
452                         /// return value of the accumulator function applied to the
453                         /// previous slots return value, and the current slots return value.
454                         /// A initial value must be provided for the first slot return type.
455                         ///
456                         /// @note This can only be used on signals that have slots with
457                         ///       non-void return types, since we can't accumulate void
458                         ///       values.
459                         ///
460                         /// @tparam T      The type of the initial value given to the accumulator.
461                         /// @tparam F      The accumulator function type.
462                         /// @param init    Initial value given to the accumulator.
463                         /// @param op      Binary operator function object to apply by the accumulator.
464                         ///                The signature of the function should be
465                         ///                equivalent of the following:
466                         ///                  `R func( T1 const& a, T2 const& b )`
467                         ///                 - The signature does not need to have `const&`.
468                         ///                 - The initial value, type `T`, must be implicitly
469                         ///                   convertible to `R`
470                         ///                 - The return type `R` must be implicitly convertible
471                         ///                   to type `T1`.
472                         ///                 - The type `R` must be `CopyAssignable`.
473                         ///                 - The type `S::slot_type::result_type` (return type of
474                         ///                   the signals slots) must be implicitly convertible to
475                         ///                   type `T2`.
476                         template <class T, class F>
477                         signal_accumulator<signal_type, T, F, A...> accumulate( T init, F op ) const {
478                                 static_assert( std::is_same<R,void>::value == false, "Unable to accumulate slot return values with 'void' as return type." );
479                                 return { *this, init, op };
480                         }
481
482
483                         /// Trigger the signal, calling the slots and aggregate all
484                         /// the slot return values into a container.
485                         ///
486                         /// @tparam C     The type of container. This type must be
487                         ///               `DefaultConstructible`, and usable with
488                         ///               `std::back_insert_iterator`. Additionally it
489                         ///               must be either copyable or moveable.
490                         /// @param args   The arguments to propagate to the slots.
491                         template <class C>
492                         C aggregate( A const&... args ) const {
493                                 static_assert( std::is_same<R,void>::value == false, "Unable to aggregate slot return values with 'void' as return type." );
494                                 C container;
495                                 auto iterator = std::back_inserter( container );
496                                 for( auto const& slot : copy_slots() ) {
497                                         if( slot ) {
498                                                 (*iterator) = slot( args... );
499                                         }
500                                 }
501                                 return container;
502                         }
503
504                         /// Count the number of slots connected to this signal
505                         /// @returns   The number of connected slots
506                         size_type slot_count() const {
507                                 return _slot_count;
508                         }
509
510                         /// Determine if the signal is empty, i.e. no slots are connected
511                         /// to it.
512                         /// @returns   `true` is returned if the signal has no connected
513                         ///            slots, and `false` otherwise.
514                         bool empty() const {
515                                 return slot_count() == 0;
516                         }
517
518                         /// Disconnects all slots
519                         /// @note This operation invalidates all scoped_connection objects
520                         void disconnect_all_slots() {
521                                 mutex_lock_type lock{ _mutex };
522                                 _slots.clear();
523                                 _slot_count = 0;
524                                 invalidate_disconnector();
525                         }
526
527                 private:
528                         template<class, class, class, class...> friend class signal_accumulator;
529                         /// Thread policy currently in use
530                         using thread_policy = P;
531                         /// Type of mutex, provided by threading policy
532                         using mutex_type = typename thread_policy::mutex_type;
533                         /// Type of mutex lock, provided by threading policy
534                         using mutex_lock_type = typename thread_policy::mutex_lock_type;
535
536                         /// Invalidate the internal disconnector object in a way
537                         /// that is safe according to the current thread policy.
538                         ///
539                         /// This will effectively make all current connection objects to
540                         /// to this signal incapable of disconnecting, since they keep a
541                         /// weak pointer to the shared disconnector object.
542                         void invalidate_disconnector() {
543                                 // If we are unlucky, some of the connected slots
544                                 // might be in the process of disconnecting from other threads.
545                                 // If this happens, we are risking to destruct the disconnector
546                                 // object managed by our shared pointer before they are done
547                                 // disconnecting. This would be bad. To solve this problem, we
548                                 // discard the shared pointer (that is pointing to the disconnector
549                                 // object within our own instance), but keep a weak pointer to that
550                                 // instance. We then stall the destruction until all other weak
551                                 // pointers have released their "lock" (indicated by the fact that
552                                 // we will get a nullptr when locking our weak pointer).
553                                 std::weak_ptr<detail::disconnector> weak{_shared_disconnector};
554                                 _shared_disconnector.reset();
555                                 while( weak.lock() != nullptr ) {
556                                         // we just yield here, allowing the OS to reschedule. We do
557                                         // this until all threads has released the disconnector object.
558                                         thread_policy::yield_thread();
559                                 }
560                         }
561
562                         /// Retrieve a copy of the current slots
563                         ///
564                         /// It's useful and necessary to copy the slots so we don't need
565                         /// to hold the lock while calling the slots. If we hold the lock
566                         /// we prevent the called slots from modifying the slots vector.
567                         /// This simple "double buffering" will allow slots to disconnect
568                         /// themself or other slots and connect new slots.
569                         std::vector<slot_type> copy_slots() const
570                         {
571                                 mutex_lock_type lock{ _mutex };
572                                 return _slots;
573                         }
574
575                         /// Implementation of the signal accumulator function call
576                         template <class T, class F>
577                         typename signal_accumulator<signal_type, T, F, A...>::result_type trigger_with_accumulator( T value, F& func, A const&... args ) const {
578                                 for( auto const& slot : copy_slots() ) {
579                                         if( slot ) {
580                                                 value = func( value, slot( args... ) );
581                                         }
582                                 }
583                                 return value;
584                         }
585
586                         /// Implementation of the disconnection operation.
587                         ///
588                         /// This is private, and only called by the connection
589                         /// objects created when connecting slots to this signal.
590                         /// @param index   The slot index of the slot that should
591                         ///                be disconnected.
592                         void disconnect( std::size_t index ) {
593                                 mutex_lock_type lock( _mutex );
594                                 assert( _slots.size() > index );
595                                 if( _slots[ index ] != nullptr ) {
596                                         --_slot_count;
597                                 }
598                                 _slots[ index ] = slot_type{};
599                                 while( _slots.size()>0 && !_slots.back() ) {
600                                         _slots.pop_back();
601                                 }
602                         }
603
604                         /// Implementation of the shared disconnection state
605                         /// used by all connection created by signal instances.
606                         ///
607                         /// This inherits the @ref detail::disconnector interface
608                         /// for type erasure.
609                         struct disconnector :
610                                 detail::disconnector
611                         {
612                                 /// Default constructor, resulting in a no-op disconnector.
613                                 disconnector() :
614                                         _ptr(nullptr)
615                                 {}
616
617                                 /// Create a disconnector that works with a given signal instance.
618                                 /// @param ptr   Pointer to the signal instance that the disconnector
619                                 ///              should work with.
620                                 disconnector( signal_type<P,R(A...)>* ptr ) :
621                                         _ptr( ptr )
622                                 {}
623
624                                 /// Disconnect a given slot on the current signal instance.
625                                 /// @note If the instance is default constructed, or created
626                                 ///       with `nullptr` as signal pointer this operation will
627                                 ///       effectively be a no-op.
628                                 /// @param index   The index of the slot to disconnect.
629                                 void operator()( std::size_t index ) const override {
630                                         if( _ptr ) {
631                                                 _ptr->disconnect( index );
632                                         }
633                                 }
634
635                                 /// Pointer to the current signal.
636                                 signal_type<P,R(A...)>* _ptr;
637                         };
638
639                         /// Mutex to synchronize access to the slot vector
640                         mutable mutex_type _mutex;
641                         /// Vector of all connected slots
642                         std::vector<slot_type> _slots;
643                         /// Number of connected slots
644                         size_type _slot_count;
645                         /// Disconnector operation, used for executing disconnection in a
646                         /// type erased manner.
647                         disconnector _disconnector;
648                         /// Shared pointer to the disconnector. All connection objects has a
649                         /// weak pointer to this pointer for performing disconnections.
650                         std::shared_ptr<detail::disconnector> _shared_disconnector;
651         };
652
653         // Implementation of the disconnect operation of the connection class
654         inline void connection::disconnect() {
655                 auto ptr = _weak_disconnector.lock();
656                 if( ptr ) {
657                         (*ptr)( _index );
658                 }
659                 _weak_disconnector.reset();
660         }
661
662         /// Signal type that is safe to use in multithreaded environments,
663         /// where the signal and slots exists in different threads.
664         /// The multithreaded policy provides mutexes and locks to synchronize
665         /// access to the signals internals.
666         ///
667         /// This is the recommended signal type, even for single threaded
668         /// environments.
669         template <class T> using signal = signal_type<multithread_policy, T>;
670
671         /// Signal type that is unsafe in multithreaded environments.
672         /// No synchronizations are provided to the signal_type for accessing
673         /// the internals.
674         ///
675         /// Only use this signal type if you are sure that your environment is
676         /// single threaded and performance is of importance.
677         template <class T> using unsafe_signal = signal_type<singlethread_policy, T>;
678 } // namespace nod
679
680 #endif // IG_NOD_INCLUDE_NOD_HPP