source: trunk/src/lol/sys/atomic.h @ 2361

Last change on this file since 2361 was 2361, checked in by sam, 8 years ago

sys: prototype for the file reading functions.

File size: 1.4 KB
Line 
1//
2// Lol Engine
3//
4// Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net>
5//   This program is free software; you can redistribute it and/or
6//   modify it under the terms of the Do What The Fuck You Want To
7//   Public License, Version 2, as published by Sam Hocevar. See
8//   http://www.wtfpl.net/ for more details.
9//
10
11#if !defined __LOL_SYS_ATOMIC_H__
12#define __LOL_SYS_ATOMIC_H__
13
14namespace lol
15{
16
17/*
18 * TODO: we should use real atomic stuff here.
19 */
20template<typename T> class Atomic
21{
22public:
23    inline Atomic() : m_value(0) {}
24    inline Atomic(T const &value) : m_value(value) {}
25
26    operator T() const
27    {
28        return m_value;
29    }
30
31    inline T operator =(T const &value)
32    {
33        m_mutex.Lock();
34        m_value = value;
35        m_mutex.Unlock();
36    }
37
38    inline T operator++(int)
39    {
40        m_mutex.Lock();
41        T ret = m_value++;
42        m_mutex.Unlock();
43        return ret;
44    }
45
46    inline T operator++()
47    {
48        m_mutex.Lock();
49        T ret = ++m_value;
50        m_mutex.Unlock();
51        return ret;
52    }
53
54    inline T operator--(int)
55    {
56        m_mutex.Lock();
57        T ret = m_value--;
58        m_mutex.Unlock();
59        return ret;
60    }
61
62    inline T operator--()
63    {
64        m_mutex.Lock();
65        T ret = --m_value;
66        m_mutex.Unlock();
67        return ret;
68    }
69
70private:
71    Mutex m_mutex; /* FIXME: this shouldn't be needed */
72    T m_value;
73};
74
75} /* namespace lol */
76
77#endif // __LOL_SYS_ATOMIC_H__
78
Note: See TracBrowser for help on using the repository browser.