static vlc_mutex_t super_mutex;
static vlc_cond_t super_variable;
+extern vlc_rwlock_t config_lock, msg_lock;
BOOL WINAPI DllMain (HINSTANCE, DWORD, LPVOID);
vlc_mutex_init (&super_mutex);
vlc_cond_init (&super_variable);
vlc_threadvar_create (&thread_key, NULL);
+ vlc_rwlock_init (&config_lock);
+ vlc_rwlock_init (&msg_lock);
+ vlc_CPU_init ();
break;
case DLL_PROCESS_DETACH:
+ vlc_rwlock_destroy (&msg_lock);
+ vlc_rwlock_destroy (&config_lock);
vlc_threadvar_delete (&thread_key);
vlc_cond_destroy (&super_variable);
vlc_mutex_destroy (&super_mutex);
/*** Condition variables ***/
enum
{
+ CLOCK_REALTIME=0, /* must be zero for VLC_STATIC_COND */
CLOCK_MONOTONIC,
- CLOCK_REALTIME,
};
static void vlc_cond_init_common (vlc_cond_t *p_condvar, unsigned clock)
void vlc_cond_signal (vlc_cond_t *p_condvar)
{
- /* NOTE: This will cause a broadcast, that is wrong.
- * This will also wake up the next waiting thread if no threads are yet
- * waiting, which is also wrong. However both of these issues are allowed
- * by the provision for spurious wakeups. Better have too many wakeups
- * than too few (= deadlocks). */
- SetEvent (p_condvar->handle);
+ if (!p_condvar->handle)
+ return;
+
+ /* This is suboptimal but works. */
+ vlc_cond_broadcast (p_condvar);
}
void vlc_cond_broadcast (vlc_cond_t *p_condvar)
{
+ if (!p_condvar->handle)
+ return;
+
+ /* Wake all threads up (as the event HANDLE has manual reset) */
SetEvent (p_condvar->handle);
}
{
DWORD result;
- assert (p_mutex->dynamic); /* TODO */
+ if (!p_condvar->handle)
+ { /* FIXME FIXME FIXME */
+ msleep (50000);
+ return;
+ }
+
do
{
vlc_testcancel ();
- LeaveCriticalSection (&p_mutex->mutex);
+ vlc_mutex_unlock (p_mutex);
result = vlc_WaitForSingleObject (p_condvar->handle, INFINITE);
- EnterCriticalSection (&p_mutex->mutex);
+ vlc_mutex_lock (p_mutex);
}
while (result == WAIT_IO_COMPLETION);
{
DWORD result;
- assert (p_mutex->dynamic); /* TODO */
+ if (!p_condvar->handle)
+ { /* FIXME FIXME FIXME */
+ msleep (50000);
+ return 0;
+ }
+
do
{
vlc_testcancel ();
total = 0;
DWORD delay = (total > 0x7fffffff) ? 0x7fffffff : total;
- LeaveCriticalSection (&p_mutex->mutex);
+ vlc_mutex_unlock (p_mutex);
result = vlc_WaitForSingleObject (p_condvar->handle, delay);
- EnterCriticalSection (&p_mutex->mutex);
+ vlc_mutex_lock (p_mutex);
}
while (result == WAIT_IO_COMPLETION);
void vlc_rwlock_init (vlc_rwlock_t *lock)
{
vlc_mutex_init (&lock->mutex);
- vlc_cond_init (&lock->read_wait);
- vlc_cond_init (&lock->write_wait);
+ vlc_cond_init (&lock->wait);
lock->readers = 0; /* active readers */
lock->writers = 0; /* waiting writers */
lock->writer = 0; /* ID of active writer */
void vlc_rwlock_destroy (vlc_rwlock_t *lock)
{
- vlc_cond_destroy (&lock->read_wait);
- vlc_cond_destroy (&lock->write_wait);
+ vlc_cond_destroy (&lock->wait);
vlc_mutex_destroy (&lock->mutex);
}
while (lock->writer != 0)
{
assert (lock->readers == 0);
- vlc_cond_wait (&lock->read_wait, &lock->mutex);
+ vlc_cond_wait (&lock->wait, &lock->mutex);
}
if (unlikely(lock->readers == ULONG_MAX))
abort ();
/* If there are no readers left, wake up a writer. */
if (--lock->readers == 0 && lock->writers > 0)
- vlc_cond_signal (&lock->write_wait);
+ vlc_cond_signal (&lock->wait);
vlc_mutex_unlock (&lock->mutex);
}
lock->writers++;
/* Wait until nobody owns the lock in either way. */
while ((lock->readers > 0) || (lock->writer != 0))
- vlc_cond_wait (&lock->write_wait, &lock->mutex);
+ vlc_cond_wait (&lock->wait, &lock->mutex);
lock->writers--;
assert (lock->writer == 0);
lock->writer = GetCurrentThreadId ();
lock->writer = 0; /* Write unlock */
/* Let reader and writer compete. Scheduler decides who wins. */
- if (lock->writers > 0)
- vlc_cond_signal (&lock->write_wait);
- vlc_cond_broadcast (&lock->read_wait);
+ vlc_cond_broadcast (&lock->wait);
vlc_mutex_unlock (&lock->mutex);
}