Bläddra i källkod

sys: use the fully working std::atomic instead of our placeholder class.

undefined
Sam Hocevar 10 år sedan
förälder
incheckning
378eaec1cb
8 ändrade filer med 8 tillägg och 141 borttagningar
  1. +1
    -2
      src/Makefile.am
  2. +0
    -1
      src/lol/sys/all.h
  3. +0
    -78
      src/lol/sys/atomic.h
  4. +0
    -1
      src/lolcore.vcxproj
  5. +0
    -3
      src/lolcore.vcxproj.filters
  6. +5
    -4
      src/sys/file.cpp
  7. +2
    -2
      test/Makefile.am
  8. +0
    -50
      test/unit/atomic.cpp

+ 1
- 2
src/Makefile.am Visa fil

@@ -46,8 +46,7 @@ liblolcore_headers = \
lol/algorithm/sort.h lol/algorithm/portal.h lol/algorithm/aabb_tree.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/pixel.h lol/image/color.h lol/image/image.h \


+ 0
- 1
src/lol/sys/all.h Visa fil

@@ -12,7 +12,6 @@
#define __LOL_SYS_ALL_H__

#include <lol/sys/thread.h>
#include <lol/sys/atomic.h>
#include <lol/sys/init.h>
#include <lol/sys/file.h>
#include <lol/sys/timer.h>


+ 0
- 78
src/lol/sys/atomic.h Visa fil

@@ -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__


+ 0
- 1
src/lolcore.vcxproj Visa fil

@@ -328,7 +328,6 @@
<ClInclude Include="lol\math\remez.h" />
<ClInclude Include="lol\math\vector.h" />
<ClInclude Include="lol\sys\all.h" />
<ClInclude Include="lol\sys\atomic.h" />
<ClInclude Include="lol\sys\file.h" />
<ClInclude Include="lol\sys\init.h" />
<ClInclude Include="lol\sys\thread.h" />


+ 0
- 3
src/lolcore.vcxproj.filters Visa fil

@@ -633,9 +633,6 @@
<ClInclude Include="lol\base\all.h">
<Filter>lol\base</Filter>
</ClInclude>
<ClInclude Include="lol\sys\atomic.h">
<Filter>lol\sys</Filter>
</ClInclude>
<ClInclude Include="lol\math\constants.h">
<Filter>lol\math</Filter>
</ClInclude>


+ 5
- 4
src/sys/file.cpp Visa fil

@@ -27,6 +27,7 @@
# include <dirent.h>
#endif

#include <atomic>
#include <sys/stat.h>

#include "core.h"
@@ -242,9 +243,9 @@ class FileData
#elif HAVE_STDIO_H
FILE *m_fd;
#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 --
@@ -475,7 +476,7 @@ class DirectoryData
#elif HAVE_STDIO_H
DIR *m_dd;
#endif
Atomic<int> m_refcount;
std::atomic<int> m_refcount;
StreamType m_type;
};



+ 2
- 2
test/Makefile.am Visa fil

@@ -19,9 +19,9 @@ testsuite_SOURCES = testsuite.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/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/camera.cpp unit/enum.cpp
unit/camera.cpp
testsuite_CPPFLAGS = $(AM_CPPFLAGS)
testsuite_DEPENDENCIES = @LOL_DEPS@
noinst_DATA = data/gradient.png


+ 0
- 50
test/unit/atomic.cpp Visa fil

@@ -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 */


Laddar…
Avbryt
Spara