1:1 source port of the engine and game code; Windows build and system layer; docs. No game files or SDK headers.
This commit is contained in:
parent
c3b032a45a
commit
0ecb47e9cb
3871 changed files with 91080 additions and 1640063 deletions
81
port/external/openal/oalAtomicStack.h
vendored
Normal file
81
port/external/openal/oalAtomicStack.h
vendored
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
// Port of pflib/external/openal/oalAtomicStack.h (Apple OpenAL, Playground SDK 4.0): TAtomicStack, a lock-free
|
||||
// LIFO of objects with get_next / set_next (OALSource's PlaybackMessage queue). Header code: the SDK build emits
|
||||
// the TAtomicStack<PlaybackMessage> members out of line in oalSource.o (__textcoal_nt: TAtomicStack()
|
||||
// sdk @0x34fd2, push_NA sdk @0x351da, compare_and_swap sdk @0x35700, pop_all sdk @0x3572c, pop_all_reversed
|
||||
// sdk @0x35772, push_atomic sdk @0x357c4); the game inlines all of them (the CompareAndSwap loops in
|
||||
// OALSource::Pause, Stop, Play, ... and the reversal loop in DoPostRender).
|
||||
// Layout (DWARF): +0x00 mHead.
|
||||
//
|
||||
// Host difference: compare_and_swap calls CompareAndSwap(UInt32, UInt32, UInt32*) on the pointers in both builds;
|
||||
// on the LP64 host the pointers do not fit, so a pointer-sized atomic compare-and-swap with the same result
|
||||
// (true when *pvalue was oldvalue and newvalue was stored) is used there.
|
||||
|
||||
#ifndef OALATOMICSTACK_H_INCLUDED
|
||||
#define OALATOMICSTACK_H_INCLUDED
|
||||
|
||||
#include "oal_sysdecls.h"
|
||||
|
||||
template <class T>
|
||||
class TAtomicStack
|
||||
{
|
||||
public:
|
||||
TAtomicStack() : mHead(NULL) {}
|
||||
|
||||
// non-atomic push: only for a stack no other thread sees
|
||||
void push_NA(T* item)
|
||||
{
|
||||
item->set_next(mHead);
|
||||
mHead = item;
|
||||
}
|
||||
|
||||
void push_atomic(T* item)
|
||||
{
|
||||
T* head;
|
||||
do
|
||||
{
|
||||
head = mHead;
|
||||
item->set_next(head);
|
||||
} while (!compare_and_swap(head, item, &mHead));
|
||||
}
|
||||
|
||||
T* pop_all()
|
||||
{
|
||||
T* result;
|
||||
do
|
||||
{
|
||||
if ((result = mHead) == NULL)
|
||||
{
|
||||
break;
|
||||
}
|
||||
} while (!compare_and_swap(result, NULL, &mHead));
|
||||
return result;
|
||||
}
|
||||
|
||||
T* pop_all_reversed()
|
||||
{
|
||||
TAtomicStack<T> reversed;
|
||||
T* p = pop_all();
|
||||
T* next;
|
||||
while (p != NULL)
|
||||
{
|
||||
next = p->get_next();
|
||||
reversed.push_NA(p);
|
||||
p = next;
|
||||
}
|
||||
return reversed.mHead;
|
||||
}
|
||||
|
||||
static bool compare_and_swap(T* oldvalue, T* newvalue, T** pvalue)
|
||||
{
|
||||
#if __LP64__
|
||||
return __sync_bool_compare_and_swap(pvalue, oldvalue, newvalue);
|
||||
#else
|
||||
return CompareAndSwap(UInt32(oldvalue), UInt32(newvalue), (UInt32*)pvalue);
|
||||
#endif
|
||||
}
|
||||
|
||||
protected:
|
||||
T* mHead;
|
||||
};
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue