Detach current thread only at its exit
Actually we are calling AttachCurrentThread and DetachCurrentThread inside the logger_handler function (https://github.com/roc-project/roc-java/blob/master/roc_jni/src/main/cpp/logger.cpp);
As it has been discussed at #18 this can slow down performances.
A more efficient solution would involve detaching thread just before its exit, as it's described at https://developer.android.com/training/articles/perf-jni#threads:
you can use
pthread_key_create()to define a destructor function that will be called before the thread exits, and callDetachCurrentThread()from there. (Use that key withpthread_setspecific()to store theJNIEnvin thread-local-storage).
let me take this up @MatteoArella @gavv what I need before working on this-
- get started doc to do a dev setup
- steps to repro the issue
Great!
A dev setup can be obtained running travis-ci jobs locally.
Linux
- build libroc:
scripts/travis/linux/before_install.sh scripts/travis/linux/install.sh - build roc-java and run tests:
./gradlew build
Android
-
export some env variables for android environment configuration, for example:
export JAVA_VERSION=8 export ANDROID_API=28 export ANDROID_BUILD_TOOLS_VERSION=28.0.3 export ANDROID_NDK_VERSION=21.1.6352462 export ROC_BASE_DIR=/tmp/roc-build # libroc prefix destination path -
build libroc for all android ABIs with:
scripts/travis/android/install.sh -
build android subproject and run instrumented tests:
scripts/travis/android/script.sh
The step 3 will run a fresh docker container and a new AVD at each execution; if it's needed to only build and test android subproject (only after steps 1-2 are done) you can just run /bin/bash on rocstreaming/env-android:jdk$JAVA_VERSION docker image with:
docker run -it --rm --privileged --env API=$ANDROID_API \
--env BUILD_TOOLS_VERSION=$ANDROID_BUILD_TOOLS_VERSION \
--env NDK_VERSION=$ANDROID_NDK_VERSION \
--env ROC_BASE_DIR=$ROC_BASE_DIR \
-v $PWD:$PWD -v $ROC_BASE_DIR:$ROC_BASE_DIR \
-v android-sdk:/sdk -w $PWD \
rocstreaming/env-android:jdk$JAVA_VERSION /bin/bash
then create an AVD
device --name "roc_device" --image "default" --api "${API}" create
device --name "roc_device" start
and finally build and test roc-android
cd android
./gradlew build
./gradlew cAT --info --stacktrace
Additional infos about our env-android docker image are available here.
@masterskipper Hi, do you still have plans on this issue?