mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-22 23:30:07 +02:00
ODLock has a non-blocking TryLock (not yet used); remove unnecessary mallocs.
This commit is contained in:
parent
3ed5defb69
commit
09b7fed2f9
@ -59,28 +59,26 @@ void *ODTaskThread::Entry()
|
||||
#ifdef __WXMAC__
|
||||
ODCondition::ODCondition(ODLock *lock)
|
||||
{
|
||||
condition = (pthread_cond_t *) malloc (sizeof (pthread_cond_t));
|
||||
pthread_cond_init(condition, NULL);
|
||||
pthread_cond_init(&condition, NULL);
|
||||
m_lock=lock;
|
||||
}
|
||||
ODCondition::~ODCondition()
|
||||
{
|
||||
pthread_cond_destroy (condition);
|
||||
free(condition);
|
||||
pthread_cond_destroy (&condition);
|
||||
}
|
||||
|
||||
void ODCondition::Signal()
|
||||
{
|
||||
pthread_cond_signal(condition);
|
||||
pthread_cond_signal(&condition);
|
||||
}
|
||||
|
||||
void ODCondition::Broadcast()
|
||||
{
|
||||
pthread_cond_broadcast(condition);
|
||||
pthread_cond_broadcast(&condition);
|
||||
}
|
||||
void ODCondition::Wait()
|
||||
{
|
||||
pthread_cond_wait(condition,m_lock->mutex);
|
||||
pthread_cond_wait(&condition, &m_lock->mutex);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -83,29 +83,33 @@ class ODTaskThread {
|
||||
class ODLock {
|
||||
public:
|
||||
ODLock(){
|
||||
mutex = (pthread_mutex_t *) malloc (sizeof (pthread_mutex_t));
|
||||
pthread_mutex_init (mutex, NULL);
|
||||
pthread_mutex_init (&mutex, NULL);
|
||||
}
|
||||
|
||||
void Lock()
|
||||
{
|
||||
pthread_mutex_lock (mutex);
|
||||
pthread_mutex_lock (&mutex);
|
||||
}
|
||||
|
||||
// Returns 0 iff the lock was acquired.
|
||||
bool TryLock()
|
||||
{
|
||||
return pthread_mutex_trylock (&mutex);
|
||||
}
|
||||
|
||||
void Unlock()
|
||||
{
|
||||
pthread_mutex_unlock (mutex);
|
||||
pthread_mutex_unlock (&mutex);
|
||||
}
|
||||
|
||||
virtual ~ODLock()
|
||||
{
|
||||
pthread_mutex_destroy (mutex);
|
||||
free(mutex);
|
||||
pthread_mutex_destroy (&mutex);
|
||||
}
|
||||
|
||||
private:
|
||||
friend class ODCondition; //needs friendship for wait()
|
||||
pthread_mutex_t *mutex ;
|
||||
pthread_mutex_t mutex ;
|
||||
};
|
||||
|
||||
class ODCondition
|
||||
@ -118,7 +122,7 @@ public:
|
||||
void Wait();
|
||||
|
||||
protected:
|
||||
pthread_cond_t *condition;
|
||||
pthread_cond_t condition;
|
||||
ODLock* m_lock;
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user