Skip to content

threading

Dmitry Koplyarov edited this page May 17, 2016 · 9 revisions

Back to reference

A policy that defines the signal/listenable lock_primitive, its storage and the way it is being locked.

namespace threading
{
	struct own_recursive_mutex;
	struct own_mutex;
	struct shared_recursive_mutex;
	struct shared_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.

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

shared_recursive_mutex

A signal holds an std::shared_ptr<std::recursive_mutex> object which should be passed to the signal constructor.

signal::lock_primitive() method returns std::shared_ptr<std::recursive_mutex>.

shared_mutex

A signal holds an std::shared_ptr<std::mutex> object which should be passed to the signal constructor. You must lock the mutex in the calling code.

signal::lock_primitive() method returns std::shared_ptr<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
{
	using tag = wigwag::threading::tag<wigwag::api_version<2, 0>>;

	class lock_primitive
	{
	public:
		unspecified_type get_primitive() const { /*...*/ }

		void lock_nonrecursive() const { /*...*/ }
		void unlock_nonrecursive() const { /*...*/ }

		void lock_recursive() const { /*...*/ }
		void unlock_recursive() const { /*...*/ }
	};
};

Required nested types

tag

using tag = wigwag::threading::tag<wigwag::api_version<2, 0>>;

The policy tag. Must be a type alias for wigwag::threading::tag<wigwag::api_version<2, 0>>.

lock_primitive

class lock_primitive;

A lock_primitive object is stored inside a signal.

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_nonrecursive

void lock_nonrecursive() const;

This method should lock the lock primitive.

unlock_nonrecursive

void unlock_nonrecursive() const;

See lock_nonrecursive.

lock_recursive

void lock_recursive() const;

This method should lock the lock primitive if it may be locked recursively. It is invoked from the signal::operator () and may allow a user not to lock the primitive externally if there is no state object associated with the signal.

unlock_recursive

void unlock_recursive() const;

See lock_recursive.

Clone this wiki locally