Skip to content

Commit

Permalink
Atomic inc and dec, the standard way
Browse files Browse the repository at this point in the history
Try to use standard atomic instead of assembly code to do
atomic increment and decrement.

Signed-off-by: DaNiMoTh <jjdanimoth@gmail.com>
  • Loading branch information
DaNiMoTh committed Jul 8, 2010
1 parent 58fe9ad commit aec56b6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 16 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ IF(COMPILE_PLUGIN)
ENDIF(COMPILE_PLUGIN)

# Compiler defaults flags for different profiles
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wnon-virtual-dtor -Woverloaded-virtual -pipe -fvisibility=hidden")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wnon-virtual-dtor -Woverloaded-virtual -pipe -fvisibility=hidden -std=c++0x")
SET(CMAKE_CXX_FLAGS_DEBUG "-g -O0 -DEXPENSIVE_DEBUG")
SET(CMAKE_CXX_FLAGS_PROFILE "-g -pg -O2")
SET(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG")
Expand Down
20 changes: 5 additions & 15 deletions swftypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <assert.h>
#include "exceptions.h"
#include <arpa/inet.h>
#include <stdatomic.h>

namespace lightspark
{
Expand Down Expand Up @@ -460,17 +461,6 @@ friend class ABCContext;
void destroyContents();
};

//Atomic operations: placeholders until C++0x is supported in GCC
inline void atomic_increment(int* operand)
{
__asm__ ("lock incl %0" : "+m" (*operand):);
}

inline void atomic_decrement(int* operand)
{
__asm__ ("lock decl %0" : "+m" (*operand):);
}

class DLL_PUBLIC ASObject
{
friend class Manager;
Expand All @@ -487,7 +477,7 @@ CLASSBUILDABLE(ASObject);
virtual ~ASObject();
SWFOBJECT_TYPE type;
private:
int32_t ref_count;
std::atomic<int32_t> ref_count;
Manager* manager;
int cur_level;
virtual int _maxlevel();
Expand All @@ -513,14 +503,14 @@ CLASSBUILDABLE(ASObject);
void incRef()
{
//std::cout << "incref " << this << std::endl;
atomic_increment(&ref_count);
ref_count.fetch_add(1);
assert(ref_count>0);
}
void decRef()
{
//std::cout << "decref " << this << std::endl;
assert_and_throw(ref_count>0);
atomic_decrement(&ref_count);
ref_count.fetch_sub(1);
if(ref_count==0)
{
if(manager)
Expand All @@ -538,7 +528,7 @@ CLASSBUILDABLE(ASObject);
}
void fake_decRef()
{
atomic_decrement(&ref_count);
ref_count.fetch_sub(1);
}
static void s_incRef(ASObject* o)
{
Expand Down

0 comments on commit aec56b6

Please sign in to comment.