1//
2// immer: immutable data structures for C++
3// Copyright (C) 2016, 2017, 2018 Juan Pedro Bolivar Puente
4//
5// This software is distributed under the Boost Software License, Version 1.0.
6// See accompanying file LICENSE or copy at http://boost.org/LICENSE_1_0.txt
7//
8
9#pragma once
10
11#include <immer/refcount/no_refcount_policy.hpp>
12
13#include <atomic>
14#include <utility>
15
16namespace immer {
17
18/*!
19 * A reference counting policy implemented using a raw `int` count.
20 * It is **not thread-safe**.
21 */
22struct unsafe_refcount_policy
23{
24 using spinlock_type = no_spinlock;
25
26 mutable int refcount;
27
28 unsafe_refcount_policy() : refcount{1} {};
29 unsafe_refcount_policy(disowned) : refcount{0} {}
30
31 void inc() { ++refcount; }
32 bool dec() { return --refcount == 0; }
33 void dec_unsafe() { --refcount; }
34 bool unique() { return refcount == 1; }
35};
36
37} // namespace immer
38