Skip to content

Commit

Permalink
AAudioLoader: cleanup destructor
Browse files Browse the repository at this point in the history
remove close()
remove some logging
reduced ERROR to WARNING for dlsym() when function not found
  • Loading branch information
Phil Burk committed Nov 26, 2018
1 parent e62cce0 commit 65983d6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 24 deletions.
17 changes: 5 additions & 12 deletions src/aaudio/AAudioLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
namespace oboe {

AAudioLoader::~AAudioLoader() {
close(); // TODO dangerous from a destructor, require caller to close()
if (mLibHandle != nullptr) {
dlclose(mLibHandle);

This comment has been minimized.

Copy link
@rpattabi

rpattabi Dec 22, 2020

Contributor

As per NDK Known Issues, calling dlclose could cause segfaults on M or newer:

Issue 360: thread_local variables with non-trivial destructors will cause segfaults if the containing library is dlcloseed on devices running M or newer, or devices before M when using a static STL. The simple workaround is to not call dlclose.

I don't know if unloading aaudio lib in this code could cause the mentioned segfaults.

mLibHandle = nullptr;
}
}

AAudioLoader* AAudioLoader::getInstance() {
Expand Down Expand Up @@ -151,19 +154,9 @@ int AAudioLoader::open() {
return 0;
}

int AAudioLoader::close() {
if (mLibHandle != nullptr) {
dlclose(mLibHandle);
mLibHandle = nullptr;
}
return 0;
}

static void AAudioLoader_check(void *proc, const char *functionName) {
if (proc == nullptr) {
LOGE("AAudioLoader could not find %s", functionName);
} else {
LOGV("AAudioLoader(): dlsym(%s) succeeded.", functionName);
LOGW("AAudioLoader could not find %s", functionName);
}
}

Expand Down
14 changes: 2 additions & 12 deletions src/aaudio/AAudioLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,11 @@ class AAudioLoader {
* This can be called multiple times.
* It should only be called from one thread.
*
* @return 0 if successful or negative error.
*/
int open();

/**
* Close the AAudio shared library.
* This can be called multiple times.
* It should only be called from one thread.
*
* The open() and close() do not nest. Calling close() once will always close the library.
* The destructor will call close() so you don't need to.
* The destructor will clean up after the open.
*
* @return 0 if successful or negative error.
*/
int close();
int open();

// Function pointers into the AAudio shared library.
aaudio_result_t (*createStreamBuilder)(AAudioStreamBuilder **builder);
Expand Down

0 comments on commit 65983d6

Please sign in to comment.