}
-/* Acquire lock for the descriptor and all children. */
+/* Caller must hold a lock for ELF. If there are children then a lock
+ will be acquired for each of them (recursively). */
static void
__attribute__ ((unused))
-libelf_acquire_all (Elf *elf)
+libelf_acquire_all_children (Elf *elf)
{
- rwlock_wrlock (elf->lock);
-
if (elf->kind == ELF_K_AR)
{
Elf *child = elf->state.ar.children;
while (child != NULL)
{
+ rwlock_wrlock (child->lock);
+
if (child->ref_count != 0)
- libelf_acquire_all (child);
+ libelf_acquire_all_children (child);
+
child = child->next;
}
}
}
-/* Release own lock and those of the children. */
+
+/* Caller must hold a lock for ELF. If there are children then a lock
+ will be released for each of them (recursively). */
static void
__attribute__ ((unused))
-libelf_release_all (Elf *elf)
+libelf_release_all_children (Elf *elf)
{
if (elf->kind == ELF_K_AR)
{
while (child != NULL)
{
if (child->ref_count != 0)
- libelf_release_all (child);
+ libelf_release_all_children (child);
+
+ rwlock_unlock (child->lock);
child = child->next;
}
}
-
- rwlock_unlock (elf->lock);
}
/* If this is an archive and we have derived descriptors get the
locks for all of them. */
- libelf_acquire_all (elf);
+ libelf_acquire_all_children (elf);
if (elf->maximum_size == ~((size_t) 0))
{
__libelf_seterrno (ELF_E_NOMEM);
/* Free the locks on the children. */
- libelf_release_all (elf);
+ libelf_release_all_children (elf);
}
rwlock_unlock (elf->lock);