Skip to content

threading

Dmitry Koplyarov edited this page Feb 12, 2016 · 9 revisions

Back to reference

namespace threading
{
	struct own_recursive_mutex;
	struct own_mutex;
	struct none;
}

Table of contents

Supplied policies

own_recursive_mutex

A signal holds an std::recursive_mutex object. This is the default policy because you are not forced to lock the mutex in the calling code if you don't need to protect an external state.

signal::lock_primitive() method returns std::recursive_mutex&.

own_mutex

A signal holds an std::mutex object. You must lock the mutex in the calling code, otherwise an exception is thrown.

signal::lock_primitive() method returns std::mutex&.

none

An empty policy. Best for single-threaded signals because it has no overhead.

signal::lock_primitive() method returns void.

How to implement your own policy

struct my_threading
{
	class lock_primitive
	{
	public:
		void get_primitive() const { /*...*/ }

		void lock_connect() const { /*...*/ }
		void unlock_connect() const { /*...*/ }

		void lock_invoke() const { /*...*/ }
		void unlock_invoke() const { /*...*/ }
	};
};

Required methods in lock_primitive nested class

get_primitive

unspecified_type& get_primitive() const;

A getter for the lock primitive. This is the method that is used in signal::lock_primitive().

lock_connect

void lock_connect() const;

This method is used when connecting to and disconnecting from a signal. The handlers collection is modified while holding the lock.

unlock_connect

void unlock_connect() const;

See lock_connect.

lock_invoke

void lock_invoke() const;

This method is used when invoking a signal. The handlers collection is copied to a temporary container while holding the lock.

unlock_invoke

void unlock_invoke() const;

See lock_invoke.

Clone this wiki locally