remove ProtAllocator hack
This commit is contained in:
@@ -12,26 +12,6 @@
|
||||
#include "arch/arch.h"
|
||||
#include "arch/Sound/RageSoundDriver.h"
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER >= 1300
|
||||
set<void *> g_ProtectedPages;
|
||||
void EnableWrites()
|
||||
{
|
||||
DWORD ignore;
|
||||
for( set<void *>::iterator it = g_ProtectedPages.begin(); it != g_ProtectedPages.end(); ++it )
|
||||
VirtualProtect( *it, 4096, PAGE_READWRITE, &ignore );
|
||||
}
|
||||
|
||||
void DisableWrites()
|
||||
{
|
||||
DWORD ignore;
|
||||
for( set<void *>::iterator it = g_ProtectedPages.begin(); it != g_ProtectedPages.end(); ++it )
|
||||
VirtualProtect( *it, 4096, PAGE_READONLY, &ignore );
|
||||
}
|
||||
#else
|
||||
void EnableWrites() { }
|
||||
void DisableWrites() { }
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This mutex is locked before Update() deletes old sounds from owned_sounds. Lock
|
||||
* this mutex if you want to ensure that sounds remain valid. (Other threads may
|
||||
@@ -56,7 +36,6 @@ RageSoundManager::RageSoundManager()
|
||||
{
|
||||
pos_map_queue.reserve( 1024 );
|
||||
MixVolume = 1.0f;
|
||||
DisableWrites();
|
||||
}
|
||||
|
||||
void RageSoundManager::Init( CString drivers )
|
||||
@@ -79,8 +58,6 @@ RageSoundManager::~RageSoundManager()
|
||||
|
||||
/* Don't lock while deleting the driver (the decoder thread might deadlock). */
|
||||
delete driver;
|
||||
|
||||
EnableWrites(); /* for dtor */
|
||||
}
|
||||
|
||||
void RageSoundManager::StartMixing( RageSoundBase *snd )
|
||||
@@ -144,18 +121,14 @@ void RageSoundManager::Update(float delta)
|
||||
void RageSoundManager::RegisterSound( RageSound *p )
|
||||
{
|
||||
g_SoundManMutex.Lock(); /* lock for access to all_sounds */
|
||||
EnableWrites();
|
||||
all_sounds.insert( p );
|
||||
DisableWrites();
|
||||
g_SoundManMutex.Unlock(); /* finished with all_sounds */
|
||||
}
|
||||
|
||||
void RageSoundManager::UnregisterSound( RageSound *p )
|
||||
{
|
||||
g_SoundManMutex.Lock(); /* lock for access to all_sounds */
|
||||
EnableWrites();
|
||||
all_sounds.erase( p );
|
||||
DisableWrites();
|
||||
g_SoundManMutex.Unlock(); /* finished with all_sounds */
|
||||
}
|
||||
|
||||
|
||||
@@ -10,67 +10,6 @@ class RageSoundBase;
|
||||
class RageSoundDriver;
|
||||
struct RageSoundParams;
|
||||
|
||||
/* This is a temporary hack, to try to track down an obscure crash. */
|
||||
#if defined(_WINDOWS) && _MSC_VER >= 1300
|
||||
#include <windows.h>
|
||||
|
||||
extern set<void *> g_ProtectedPages;
|
||||
template<typename T>
|
||||
class ProtAllocator
|
||||
{
|
||||
public:
|
||||
typedef T value_type;
|
||||
typedef value_type* pointer;
|
||||
typedef const value_type* const_pointer;
|
||||
typedef value_type& reference;
|
||||
typedef const value_type& const_reference;
|
||||
typedef std::size_t size_type;
|
||||
typedef std::ptrdiff_t difference_type;
|
||||
|
||||
template<typename U> struct rebind
|
||||
{
|
||||
typedef ProtAllocator<U> other;
|
||||
};
|
||||
|
||||
explicit ProtAllocator() {}
|
||||
~ProtAllocator() {}
|
||||
ProtAllocator( ProtAllocator const & ) {}
|
||||
template<typename U> ProtAllocator( ProtAllocator<U> const& ) {}
|
||||
|
||||
pointer address( reference r ) { return &r; }
|
||||
const_pointer address( const_reference r ) { return &r; }
|
||||
|
||||
pointer allocate( size_type cnt, typename std::allocator<void>::const_pointer = 0 )
|
||||
{
|
||||
cnt *= sizeof (T);
|
||||
void *p = VirtualAlloc( NULL, cnt, MEM_COMMIT, PAGE_READWRITE );
|
||||
g_ProtectedPages.insert( p );
|
||||
|
||||
return reinterpret_cast<pointer>( p );
|
||||
}
|
||||
void deallocate( pointer p, size_type s )
|
||||
{
|
||||
VirtualFree( p, 0, MEM_RELEASE );
|
||||
g_ProtectedPages.erase( p );
|
||||
}
|
||||
|
||||
size_type max_size() const
|
||||
{
|
||||
return 2147483648 / sizeof(T);
|
||||
}
|
||||
|
||||
void construct( pointer p, const T& t ) { new(p) T(t); }
|
||||
void destroy( pointer p ) { p->~T(); }
|
||||
|
||||
bool operator==( ProtAllocator const& ) { return true; }
|
||||
bool operator!=( ProtAllocator const& a ) { return !operator==(a); }
|
||||
};
|
||||
|
||||
#else
|
||||
#define ProtAllocator allocator
|
||||
#endif
|
||||
|
||||
|
||||
class RageSoundManager
|
||||
{
|
||||
/* Set of sounds that we've taken over (and are responsible for deleting
|
||||
@@ -79,7 +18,7 @@ class RageSoundManager
|
||||
set<RageSound *> playing_sounds;
|
||||
|
||||
/* A list of all sounds that currently exist. */
|
||||
typedef set<RageSound *, less<RageSound*>, ProtAllocator<RageSound*> > all_sounds_type;
|
||||
typedef set<RageSound *, less<RageSound*> > all_sounds_type;
|
||||
all_sounds_type all_sounds;
|
||||
|
||||
RageSoundDriver *driver;
|
||||
|
||||
Reference in New Issue
Block a user