Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detach current thread only at its exit #20

Open
MatteoArella opened this issue Jun 9, 2020 · 3 comments
Open

Detach current thread only at its exit #20

MatteoArella opened this issue Jun 9, 2020 · 3 comments
Labels
good first issue Good for newcomers help wanted Contributions are welcome jni JNI-related tasks

Comments

@MatteoArella
Copy link
Member

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 call DetachCurrentThread() from there. (Use that key with pthread_setspecific() to store the JNIEnv in thread-local-storage).

@MatteoArella MatteoArella added the enhancement New feature or request label Jun 9, 2020
@gavv gavv added good first issue Good for newcomers hacktoberfest help wanted Contributions are welcome labels Sep 28, 2020
@panwarab
Copy link

panwarab commented Oct 1, 2020

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

@MatteoArella
Copy link
Member Author

MatteoArella commented Oct 2, 2020

Great!

A dev setup can be obtained running travis-ci jobs locally.

Linux

  1. build libroc:
    scripts/travis/linux/before_install.sh
    scripts/travis/linux/install.sh
    
  2. build roc-java and run tests:
    ./gradlew build
    

Android

  1. 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
    
  2. build libroc for all android ABIs with:

    scripts/travis/android/install.sh
    
  3. 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.

@gavv
Copy link
Member

gavv commented Dec 4, 2020

@masterskipper Hi, do you still have plans on this issue?

@panwarab panwarab removed their assignment Dec 5, 2020
@gavv gavv removed good first issue Good for newcomers help wanted Contributions are welcome labels Apr 6, 2023
@gavv gavv added good first issue Good for newcomers help wanted Contributions are welcome labels Apr 19, 2023
@gavv gavv added jni JNI-related tasks and removed enhancement New feature or request labels May 13, 2023
@gavv gavv pinned this issue Oct 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Contributions are welcome jni JNI-related tasks
Projects
None yet
Development

No branches or pull requests

3 participants