@@ -46,8 +46,7 @@ liblolcore_headers = \ | |||||
lol/algorithm/sort.h lol/algorithm/portal.h lol/algorithm/aabb_tree.h \ | lol/algorithm/sort.h lol/algorithm/portal.h lol/algorithm/aabb_tree.h \ | ||||
\ | \ | ||||
lol/sys/all.h \ | lol/sys/all.h \ | ||||
lol/sys/init.h lol/sys/file.h lol/sys/thread.h lol/sys/atomic.h \ | |||||
lol/sys/timer.h \ | |||||
lol/sys/init.h lol/sys/file.h lol/sys/thread.h lol/sys/timer.h \ | |||||
\ | \ | ||||
lol/image/all.h \ | lol/image/all.h \ | ||||
lol/image/pixel.h lol/image/color.h lol/image/image.h \ | lol/image/pixel.h lol/image/color.h lol/image/image.h \ | ||||
@@ -12,7 +12,6 @@ | |||||
#define __LOL_SYS_ALL_H__ | #define __LOL_SYS_ALL_H__ | ||||
#include <lol/sys/thread.h> | #include <lol/sys/thread.h> | ||||
#include <lol/sys/atomic.h> | |||||
#include <lol/sys/init.h> | #include <lol/sys/init.h> | ||||
#include <lol/sys/file.h> | #include <lol/sys/file.h> | ||||
#include <lol/sys/timer.h> | #include <lol/sys/timer.h> | ||||
@@ -1,78 +0,0 @@ | |||||
// | |||||
// Lol Engine | |||||
// | |||||
// Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net> | |||||
// This program is free software; you can redistribute it and/or | |||||
// modify it under the terms of the Do What The Fuck You Want To | |||||
// Public License, Version 2, as published by Sam Hocevar. See | |||||
// http://www.wtfpl.net/ for more details. | |||||
// | |||||
#if !defined __LOL_SYS_ATOMIC_H__ | |||||
#define __LOL_SYS_ATOMIC_H__ | |||||
namespace lol | |||||
{ | |||||
/* | |||||
* TODO: we should use real atomic stuff here. | |||||
*/ | |||||
template<typename T> class Atomic | |||||
{ | |||||
public: | |||||
inline Atomic() : m_value(0) {} | |||||
inline Atomic(T const &value) : m_value(value) {} | |||||
operator T() const | |||||
{ | |||||
return m_value; | |||||
} | |||||
inline T operator =(T const &value) | |||||
{ | |||||
m_mutex.Lock(); | |||||
m_value = value; | |||||
m_mutex.Unlock(); | |||||
} | |||||
inline T operator++(int) | |||||
{ | |||||
m_mutex.Lock(); | |||||
T ret = m_value++; | |||||
m_mutex.Unlock(); | |||||
return ret; | |||||
} | |||||
inline T operator++() | |||||
{ | |||||
m_mutex.Lock(); | |||||
T ret = ++m_value; | |||||
m_mutex.Unlock(); | |||||
return ret; | |||||
} | |||||
inline T operator--(int) | |||||
{ | |||||
m_mutex.Lock(); | |||||
T ret = m_value--; | |||||
m_mutex.Unlock(); | |||||
return ret; | |||||
} | |||||
inline T operator--() | |||||
{ | |||||
m_mutex.Lock(); | |||||
T ret = --m_value; | |||||
m_mutex.Unlock(); | |||||
return ret; | |||||
} | |||||
private: | |||||
Mutex m_mutex; /* FIXME: this shouldn't be needed */ | |||||
T m_value; | |||||
}; | |||||
} /* namespace lol */ | |||||
#endif // __LOL_SYS_ATOMIC_H__ | |||||
@@ -328,7 +328,6 @@ | |||||
<ClInclude Include="lol\math\remez.h" /> | <ClInclude Include="lol\math\remez.h" /> | ||||
<ClInclude Include="lol\math\vector.h" /> | <ClInclude Include="lol\math\vector.h" /> | ||||
<ClInclude Include="lol\sys\all.h" /> | <ClInclude Include="lol\sys\all.h" /> | ||||
<ClInclude Include="lol\sys\atomic.h" /> | |||||
<ClInclude Include="lol\sys\file.h" /> | <ClInclude Include="lol\sys\file.h" /> | ||||
<ClInclude Include="lol\sys\init.h" /> | <ClInclude Include="lol\sys\init.h" /> | ||||
<ClInclude Include="lol\sys\thread.h" /> | <ClInclude Include="lol\sys\thread.h" /> | ||||
@@ -633,9 +633,6 @@ | |||||
<ClInclude Include="lol\base\all.h"> | <ClInclude Include="lol\base\all.h"> | ||||
<Filter>lol\base</Filter> | <Filter>lol\base</Filter> | ||||
</ClInclude> | </ClInclude> | ||||
<ClInclude Include="lol\sys\atomic.h"> | |||||
<Filter>lol\sys</Filter> | |||||
</ClInclude> | |||||
<ClInclude Include="lol\math\constants.h"> | <ClInclude Include="lol\math\constants.h"> | ||||
<Filter>lol\math</Filter> | <Filter>lol\math</Filter> | ||||
</ClInclude> | </ClInclude> | ||||
@@ -27,6 +27,7 @@ | |||||
# include <dirent.h> | # include <dirent.h> | ||||
#endif | #endif | ||||
#include <atomic> | |||||
#include <sys/stat.h> | #include <sys/stat.h> | ||||
#include "core.h" | #include "core.h" | ||||
@@ -242,9 +243,9 @@ class FileData | |||||
#elif HAVE_STDIO_H | #elif HAVE_STDIO_H | ||||
FILE *m_fd; | FILE *m_fd; | ||||
#endif | #endif | ||||
Atomic<int> m_refcount; | |||||
StreamType m_type; | |||||
struct stat m_stat; | |||||
std::atomic<int> m_refcount; | |||||
StreamType m_type; | |||||
struct stat m_stat; | |||||
}; | }; | ||||
//-- FILE -- | //-- FILE -- | ||||
@@ -475,7 +476,7 @@ class DirectoryData | |||||
#elif HAVE_STDIO_H | #elif HAVE_STDIO_H | ||||
DIR *m_dd; | DIR *m_dd; | ||||
#endif | #endif | ||||
Atomic<int> m_refcount; | |||||
std::atomic<int> m_refcount; | |||||
StreamType m_type; | StreamType m_type; | ||||
}; | }; | ||||
@@ -19,9 +19,9 @@ testsuite_SOURCES = testsuite.cpp \ | |||||
unit/vector.cpp unit/matrix.cpp unit/half.cpp unit/trig.cpp \ | unit/vector.cpp unit/matrix.cpp unit/half.cpp unit/trig.cpp \ | ||||
unit/build.cpp unit/real.cpp unit/image.cpp unit/quat.cpp unit/cmplx.cpp \ | unit/build.cpp unit/real.cpp unit/image.cpp unit/quat.cpp unit/cmplx.cpp \ | ||||
unit/array.cpp unit/array2d.cpp unit/array3d.cpp unit/rotation.cpp \ | unit/array.cpp unit/array2d.cpp unit/array3d.cpp unit/rotation.cpp \ | ||||
unit/string.cpp unit/map.cpp unit/color.cpp unit/atomic.cpp \ | |||||
unit/string.cpp unit/map.cpp unit/color.cpp unit/enum.cpp \ | |||||
unit/interp.cpp unit/box.cpp unit/rand.cpp unit/thread.cpp \ | unit/interp.cpp unit/box.cpp unit/rand.cpp unit/thread.cpp \ | ||||
unit/camera.cpp unit/enum.cpp | |||||
unit/camera.cpp | |||||
testsuite_CPPFLAGS = $(AM_CPPFLAGS) | testsuite_CPPFLAGS = $(AM_CPPFLAGS) | ||||
testsuite_DEPENDENCIES = @LOL_DEPS@ | testsuite_DEPENDENCIES = @LOL_DEPS@ | ||||
noinst_DATA = data/gradient.png | noinst_DATA = data/gradient.png | ||||
@@ -1,50 +0,0 @@ | |||||
// | |||||
// Lol Engine | |||||
// | |||||
// Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net> | |||||
// This program is free software; you can redistribute it and/or | |||||
// modify it under the terms of the Do What The Fuck You Want To | |||||
// Public License, Version 2, as published by Sam Hocevar. See | |||||
// http://www.wtfpl.net/ for more details. | |||||
// | |||||
#if defined HAVE_CONFIG_H | |||||
# include "config.h" | |||||
#endif | |||||
#include <cmath> | |||||
#include "core.h" | |||||
#include "lol/unit.h" | |||||
namespace lol | |||||
{ | |||||
LOLUNIT_FIXTURE(AtomicTest) | |||||
{ | |||||
LOLUNIT_TEST(SingleThread) | |||||
{ | |||||
Atomic<int> i = 0; | |||||
LOLUNIT_ASSERT_EQUAL(0, (int)i); | |||||
int a1 = i++; | |||||
LOLUNIT_ASSERT_EQUAL(0, a1); | |||||
LOLUNIT_ASSERT_EQUAL(1, (int)i); | |||||
int a2 = i--; | |||||
LOLUNIT_ASSERT_EQUAL(1, a2); | |||||
LOLUNIT_ASSERT_EQUAL(0, (int)i); | |||||
int a3 = ++i; | |||||
LOLUNIT_ASSERT_EQUAL(1, a3); | |||||
LOLUNIT_ASSERT_EQUAL(1, (int)i); | |||||
int a4 = --i; | |||||
LOLUNIT_ASSERT_EQUAL(0, a4); | |||||
LOLUNIT_ASSERT_EQUAL(0, (int)i); | |||||
} | |||||
}; | |||||
} /* namespace lol */ | |||||