Skip to content

Commit

Permalink
SERVER-1625 Apple atomics to be able to build on powerpc.
Browse files Browse the repository at this point in the history
  • Loading branch information
Per Ola Ingvarsson committed Apr 28, 2012
1 parent 199ffe9 commit 2e25910
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/mongo/bson/util/atomic_int.h
Expand Up @@ -22,6 +22,10 @@
# include <windows.h>
#endif

#if defined(__APPLE__)
# include <libkern/OSAtomic.h>
#endif

#include "mongo/platform/compiler.h"

namespace mongo {
Expand Down Expand Up @@ -124,6 +128,35 @@ namespace mongo {
void AtomicUInt::signedAdd(int by) {
atomic_int_helper(&x, by);
}
#elif defined(__APPLE__)
#define PTR_CAST reinterpret_cast<volatile int32_t*>( &x )

AtomicUInt AtomicUInt::operator++() {
// OSAtomicIncrement32Barrier returns the new value
// TODO: Is the barrier version needed?
return OSAtomicIncrement32Barrier( PTR_CAST );
}
AtomicUInt AtomicUInt::operator++(int) {
return OSAtomicIncrement32Barrier( PTR_CAST ) - 1;
}
AtomicUInt AtomicUInt::operator--() {
return OSAtomicDecrement32Barrier( PTR_CAST );
}
AtomicUInt AtomicUInt::operator--(int) {
return OSAtomicDecrement32Barrier( PTR_CAST ) + 1;
}

void AtomicUInt::signedAdd( int by ) {
OSAtomicAdd32Barrier( by, PTR_CAST );
}

void AtomicUInt::set( unsigned newX ) {
x = newX;
OSMemoryBarrier();
}

#undef PTR_CAST

#else
# error "unsupported compiler or platform"
#endif
Expand Down

0 comments on commit 2e25910

Please sign in to comment.