void *data;
};
-static CRITICAL_SECTION super_mutex;
-static HANDLE super_cond;
+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);
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
- super_cond = CreateEvent (NULL, TRUE, FALSE, NULL);
- if (unlikely(!super_cond))
- return FALSE;
- InitializeCriticalSection (&super_mutex);
+ 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);
- DeleteCriticalSection (&super_mutex);
- CloseHandle (super_cond);
+ vlc_cond_destroy (&super_variable);
+ vlc_mutex_destroy (&super_mutex);
break;
}
return TRUE;
void vlc_mutex_lock (vlc_mutex_t *p_mutex)
{
if (!p_mutex->dynamic)
- { /* static mutexes (inefficient on Windows) */
- EnterCriticalSection (&super_mutex);
+ { /* static mutexes */
+ int canc = vlc_savecancel ();
+ assert (p_mutex != &super_mutex); /* this one cannot be static */
+
+ vlc_mutex_lock (&super_mutex);
while (p_mutex->locked)
{
p_mutex->contention++;
- LeaveCriticalSection (&super_mutex);
- WaitForSingleObject (super_cond, INFINITE);
- EnterCriticalSection (&super_mutex);
- assert (p_mutex->contention > 0);
+ vlc_cond_wait (&super_variable, &super_mutex);
p_mutex->contention--;
}
p_mutex->locked = true;
- LeaveCriticalSection (&super_mutex);
+ vlc_mutex_unlock (&super_mutex);
+ vlc_restorecancel (canc);
return;
}
{ /* static mutexes */
int ret = EBUSY;
- EnterCriticalSection (&super_mutex);
+ assert (p_mutex != &super_mutex); /* this one cannot be static */
+ vlc_mutex_lock (&super_mutex);
if (!p_mutex->locked)
{
p_mutex->locked = true;
ret = 0;
}
- LeaveCriticalSection (&super_mutex);
+ vlc_mutex_unlock (&super_mutex);
return ret;
}
{
if (!p_mutex->dynamic)
{ /* static mutexes */
- EnterCriticalSection (&super_mutex);
+ assert (p_mutex != &super_mutex); /* this one cannot be static */
+
+ vlc_mutex_lock (&super_mutex);
assert (p_mutex->locked);
p_mutex->locked = false;
- if (p_mutex->contention > 0)
- SetEvent (super_cond);
- LeaveCriticalSection (&super_mutex);
+ if (p_mutex->contention)
+ vlc_cond_broadcast (&super_variable);
+ vlc_mutex_unlock (&super_mutex);
return;
}
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);
}
var->next = NULL;
*p_tls = var;
- EnterCriticalSection (&super_mutex);
+ vlc_mutex_lock (&super_mutex);
var->prev = vlc_threadvar_last;
vlc_threadvar_last = var;
- LeaveCriticalSection (&super_mutex);
+ vlc_mutex_unlock (&super_mutex);
return 0;
}
{
struct vlc_threadvar *var = *p_tls;
- EnterCriticalSection (&super_mutex);
+ vlc_mutex_lock (&super_mutex);
if (var->prev != NULL)
var->prev->next = var->next;
else
vlc_threadvar_last = var->next;
if (var->next != NULL)
var->next->prev = var->prev;
- LeaveCriticalSection (&super_mutex);
+ vlc_mutex_unlock (&super_mutex);
TlsFree (var->id);
free (var);
retry:
/* TODO: use RW lock or something similar */
- EnterCriticalSection (&super_mutex);
+ vlc_mutex_lock (&super_mutex);
for (key = vlc_threadvar_last; key != NULL; key = key->prev)
{
void *value = vlc_threadvar_get (key);
if (value != NULL && key->destroy != NULL)
{
- EnterCriticalSection (&super_mutex);
+ vlc_mutex_unlock (&super_mutex);
vlc_threadvar_set (key, NULL);
key->destroy (value);
goto retry;
}
}
- EnterCriticalSection (&super_mutex);
+ vlc_mutex_unlock (&super_mutex);
if (th->detached)
{