1
0
Fork 0
mirror of https://github.com/tobast/libunwind-eh_elf.git synced 2024-11-22 23:47:39 +01:00

Move pthread-locking stuff to "internal.h".

(_U_dyn_info_list_lock): Rename from "registration_lock" and change from r/w-lock
	to a simple mutex (spin) lock.
(_U_dyn_register): Insert into doubly-linked list.

(Logical change 1.30)
This commit is contained in:
mostang.com!davidm 2002-12-12 09:17:41 +00:00
parent 12f30d6481
commit 78306c6f14

View file

@ -1,52 +1,19 @@
#include <libunwind.h>
#include "internal.h"
#ifndef HAVE_CMP8XCHG16
pthread_mutex_t _U_dyn_info_list_lock = PTHREAD_MUTEX_INITIALIZER;
#include <pthread.h>
/* Make it easy to write thread-safe code which may or may not be
linked against libpthread. The macros below can be used
unconditionally and if -lpthread is around, they'll call the
corresponding routines otherwise, they do nothing. */
#pragma weak pthread_rwlock_rdlock
#pragma weak pthread_rwlock_wrlock
#pragma weak pthread_rwlock_unlock
#define rw_rdlock(l) (pthread_rwlock_rdlock ? pthread_rwlock_rdlock (l) : 0)
#define rw_wrlock(l) (pthread_rwlock_wrlock ? pthread_rwlock_wrlock (l) : 0)
#define rw_unlock(l) (pthread_rwlock_unlock ? pthread_rwlock_unlock (l) : 0)
static pthread_rwlock_t registration_lock = PTHREAD_RWLOCK_INITIALIZER;
#endif
extern unw_dyn_info_list_t _U_dyn_info_list;
int
void
_U_dyn_register (unw_dyn_info_t *di)
{
#ifdef HAVE_CMP8XCHG16
unw_dyn_info_t *old_list_head, *new_list_head;
unsigned long old_gen, new_gen;
do
{
old_gen = _U_dyn_info_list.generation;
old_list_head = _U_dyn_info_list.first;
new_gen = old_gen + 1;
new_list_head = di;
di->next = old_list_head;
}
while (cmp8xchg16 (&_U_dyn_info_list, new_gen, new_list_head) != old_gen);
#else
rw_wrlock (&registration_lock);
mutex_lock (&_U_dyn_info_list_lock);
{
++_U_dyn_info_list.generation;
di->next = _U_dyn_info_list.first;
di->prev = NULL;
if (di->next)
di->next->prev = di;
_U_dyn_info_list.first = di;
}
rw_unlock (&registration_lock);
#endif
mutex_unlock (&_U_dyn_info_list_lock);
}