Skip to content

use java to handle threads for l2cap#5

Merged
sethvincent merged 2 commits into
mainfrom
java-threads
Jun 9, 2026
Merged

use java to handle threads for l2cap#5
sethvincent merged 2 commits into
mainfrom
java-threads

Conversation

@sethvincent

Copy link
Copy Markdown
Contributor

This could be an alternative to #2.

The goal: use java to handle threads, only plain data moving across threads, keep java_global_ref_t usage on js threads.

This introduces a few new Java classes, which feels like the right tradeoff given the implementation is clearer than how I left #2.

@sethvincent sethvincent requested a review from a team June 3, 2026 01:57
Comment thread lib/L2capReader.java Outdated
Comment thread lib/L2capConnector.java Outdated
Comment thread binding.cc

auto jenv = bare_bluetooth_android_jvm().attach_current_thread();
auto *server = reinterpret_cast<bare_bluetooth_android_server_t *>(native_ptr);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we could have a guard here, like:

Suggested change
auto *server = reinterpret_cast<bare_bluetooth_android_server_t *>(native_ptr);
auto *server = reinterpret_cast<bare_bluetooth_android_server_t *>(native_ptr);
if (server->destroyed) return

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am pretty I saw it elsewhere on this codebase.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bare_bluetooth_android_server_t teardown is synchronous and doesn't have async actions that might still be in progress during teardown like bare_bluetooth_android_peripheral_t and bare_bluetooth_android_channel_t do (they use that destroyed property pattern). So I think we don't need it here? I could be wrong though.

Comment thread lib/L2capAcceptor.java
This was referenced Jun 8, 2026

@kasperisager kasperisager left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's also some exception APIs to figure out for libjnitl, but we can do that separately. It's becoming increasingly relevant 👀

Comment thread binding.cc
Comment thread lib/L2capConnector.java
@sethvincent sethvincent requested a review from kasperisager June 9, 2026 08:34
@sethvincent sethvincent merged commit 30d768f into main Jun 9, 2026
2 checks passed
@sethvincent sethvincent deleted the java-threads branch June 9, 2026 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants