Skip to content

ref_counter

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

Back to reference

A policy that defines the reference counting mechanism.

namespace ref_counter
{
	struct atomic;
	struct single_threaded;
}

Table of contents

Supplied policies

atomic

A ref_counter that uses std::atomic as a counter value. A good default.

single_threaded

A ref_counter that uses int as a counter value. This is faster than atomic, but is not thread-safe. You may want to use it in single-threaded signals.

How to implement your own policy

struct my_ref_counter
{
	using tag = wigwag::ref_counter::tag<wigwag::api_version<2, 0>>;

	my_ref_counter(int initVal);

	int add_ref() const;
	int release() const;
};

Required nested types

tag

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

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

Required constructors

int-parameterized constructor

my_ref_counter(int initVal);

Arguments:

  • initVal - initial reference counter value

Required methods

add_ref

int add_ref() const;

This method should increase reference counter.

Return value: the new reference counter value

release

int release() const;

This method should decrease reference counter.

Return value: the new reference counter value

Clone this wiki locally