summaryrefslogtreecommitdiff
path: root/libcult/cult/mm/arch/generic/counter.ixx
blob: 648d28a84f3dd4efa6e2f3ca3099aaeb376e9e63 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// file      : cult/mm/arch/generic/counter.ixx
// author    : Boris Kolpackov <boris@kolpackov.net>
// copyright : Copyright (c) 2005-2010 Boris Kolpackov
// license   : GNU GPL v2 + exceptions; see accompanying LICENSE file

#include <cult/sched/lock.hxx>

namespace Cult
{
  namespace MM
  {
    inline
    Counter::
    Counter ()
        : value_ (1)
    {
    }

    inline
    Void Counter::
    inc_ref ()
    {
      Sched::Lock l (spin_);

      ++value_;
    }

    inline
    Boolean Counter::
    dec_ref ()
    {
      Sched::Lock l (spin_);

      return --value_ == 0;

    }

    inline
    Size Counter::
    count () const
    {
      Sched::Lock l (spin_);

      return value_;
    }
  }
}