/*****************************************************************************
* thread.c : OS/2 back-end for LibVLC
*****************************************************************************
- * Copyright (C) 1999-2011 the VideoLAN team
+ * Copyright (C) 1999-2011 VLC authors and VideoLAN
*
* Authors: KO Myung-Hun <komh@chollian.net>
* Jean-Marc Dressler <polux@via.ecp.fr>
* RĂ©mi Denis-Courmont
* Pierre Ynard
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
*
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifdef HAVE_CONFIG_H
vlc_mutex_init (&lock->mutex);
vlc_cond_init (&lock->wait);
lock->readers = 0; /* active readers */
- lock->writers = 0; /* waiting or active writers */
lock->writer = 0; /* ID of active writer */
}
void vlc_rwlock_rdlock (vlc_rwlock_t *lock)
{
vlc_mutex_lock (&lock->mutex);
- /* Recursive read-locking is allowed. With the infos available:
- * - the loosest possible condition (no active writer) is:
- * (lock->writer != 0)
- * - the strictest possible condition is:
- * (lock->writer != 0 || (lock->readers == 0 && lock->writers > 0))
- * or (lock->readers == 0 && (lock->writer != 0 || lock->writers > 0))
- */
+ /* Recursive read-locking is allowed. */
while (lock->writer != 0)
{
assert (lock->readers == 0);
assert (lock->readers > 0);
/* If there are no readers left, wake up a writer. */
- if (--lock->readers == 0 && lock->writers > 0)
+ if (--lock->readers == 0)
vlc_cond_signal (&lock->wait);
vlc_mutex_unlock (&lock->mutex);
}
void vlc_rwlock_wrlock (vlc_rwlock_t *lock)
{
vlc_mutex_lock (&lock->mutex);
- if (unlikely(lock->writers == ULONG_MAX))
- abort ();
- lock->writers++;
/* Wait until nobody owns the lock in either way. */
while ((lock->readers > 0) || (lock->writer != 0))
vlc_cond_wait (&lock->wait, &lock->mutex);
- lock->writers--;
assert (lock->writer == 0);
lock->writer = _gettid ();
vlc_mutex_unlock (&lock->mutex);