locks in pos_map aren't needed anymore (we do it in RageSound)

This commit is contained in:
Glenn Maynard
2004-04-16 22:28:57 +00:00
parent b925b61654
commit c8f1fc31d3
2 changed files with 2 additions and 33 deletions
+2 -30
View File
@@ -8,40 +8,18 @@
* is mostly harmless; the data is small. */ * is mostly harmless; the data is small. */
const int pos_map_backlog_frames = 100000; const int pos_map_backlog_frames = 100000;
pos_map_queue::pos_map_queue(): m_Mutex("pos_map_queue") pos_map_queue::pos_map_queue()
{ {
} }
pos_map_queue::pos_map_queue( const pos_map_queue &cpy ): m_Mutex("pos_map_queue") pos_map_queue::pos_map_queue( const pos_map_queue &cpy )
{ {
*this = cpy; *this = cpy;
} }
pos_map_queue &pos_map_queue::operator=( const pos_map_queue &cpy )
{
/* Hack: to prevent deadlock, always lock the lesser pointer first. */
if( this < &cpy )
{
m_Mutex.Lock();
cpy.m_Mutex.Lock();
} else {
cpy.m_Mutex.Lock();
m_Mutex.Lock();
}
m_Queue = cpy.m_Queue;
/* Unlock order doesn't matter. */
m_Mutex.Unlock();
cpy.m_Mutex.Unlock();
return *this;
}
void pos_map_queue::Insert( int64_t frameno, int pos, int got_frames ) void pos_map_queue::Insert( int64_t frameno, int pos, int got_frames )
{ {
LockMut(m_Mutex);
if( m_Queue.size() ) if( m_Queue.size() )
{ {
/* Optimization: If the last entry lines up with this new entry, just merge them. */ /* Optimization: If the last entry lines up with this new entry, just merge them. */
@@ -61,8 +39,6 @@ void pos_map_queue::Insert( int64_t frameno, int pos, int got_frames )
void pos_map_queue::Cleanup() void pos_map_queue::Cleanup()
{ {
LockMut(m_Mutex);
/* Determine the number of frames of data we have. */ /* Determine the number of frames of data we have. */
int64_t total_frames = 0; int64_t total_frames = 0;
for( unsigned i = 0; i < m_Queue.size(); ++i ) for( unsigned i = 0; i < m_Queue.size(); ++i )
@@ -79,8 +55,6 @@ void pos_map_queue::Cleanup()
int64_t pos_map_queue::Search( int64_t frame, bool *approximate ) const int64_t pos_map_queue::Search( int64_t frame, bool *approximate ) const
{ {
LockMut(m_Mutex);
if( IsEmpty() ) if( IsEmpty() )
{ {
if( approximate ) if( approximate )
@@ -142,13 +116,11 @@ int64_t pos_map_queue::Search( int64_t frame, bool *approximate ) const
void pos_map_queue::Clear() void pos_map_queue::Clear()
{ {
LockMut(m_Mutex);
m_Queue.clear(); m_Queue.clear();
} }
bool pos_map_queue::IsEmpty() const bool pos_map_queue::IsEmpty() const
{ {
LockMut(m_Mutex);
return m_Queue.empty(); return m_Queue.empty();
} }
-3
View File
@@ -1,7 +1,6 @@
#ifndef RAGE_SOUND_POS_MAP_H #ifndef RAGE_SOUND_POS_MAP_H
#define RAGE_SOUND_POS_MAP_H #define RAGE_SOUND_POS_MAP_H
#include "RageThreads.h"
#include <deque> #include <deque>
struct pos_map_t struct pos_map_t
@@ -23,14 +22,12 @@ struct pos_map_t
class pos_map_queue class pos_map_queue
{ {
deque<pos_map_t> m_Queue; deque<pos_map_t> m_Queue;
mutable RageMutex m_Mutex;
void Cleanup(); void Cleanup();
public: public:
pos_map_queue(); pos_map_queue();
pos_map_queue( const pos_map_queue &cpy ); pos_map_queue( const pos_map_queue &cpy );
pos_map_queue &operator=( const pos_map_queue &cpy );
/* Insert a mapping from frameno to position, containing pos got_frames. */ /* Insert a mapping from frameno to position, containing pos got_frames. */
void Insert( int64_t frameno, int position, int got_frames ); void Insert( int64_t frameno, int position, int got_frames );