This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[android] Android specific thread pool that keeps threads attached to…
… JVM
- Loading branch information
1 parent
cd5f87e
commit 5d833b1
Showing
6 changed files
with
70 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include "android_thread_pool.hpp" | ||
#include <mbgl/util/platform.hpp> | ||
|
||
namespace mbgl { | ||
namespace android { | ||
|
||
void AndroidThreadLifecycle::onThreadCreated() const { | ||
attach_jni_thread(theJVM, &env, platform::getCurrentThreadName()); | ||
} | ||
|
||
void AndroidThreadLifecycle::onThreadDestroyed() const { | ||
detach_jni_thread(theJVM, &env, true); | ||
} | ||
|
||
AndroidThreadPool::AndroidThreadPool(size_t count) : mbgl::ThreadPool(count, std::make_unique<AndroidThreadLifecycle>()) {} | ||
|
||
} // namespace android | ||
} // namespace mbgl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#pragma once | ||
#include <mbgl/util/default_thread_pool.hpp> | ||
#include "jni.hpp" | ||
|
||
namespace mbgl { | ||
namespace android { | ||
|
||
class AndroidThreadLifecycle : public mbgl::ThreadLifecycle { | ||
public: | ||
void onThreadCreated() const override; | ||
void onThreadDestroyed() const override; | ||
|
||
private: | ||
mutable JNIEnv *env = nullptr; | ||
}; | ||
|
||
class AndroidThreadPool : public mbgl::ThreadPool { | ||
public: | ||
explicit AndroidThreadPool(size_t count); | ||
}; | ||
|
||
} // namespace android | ||
} // namespace mbgl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include <mbgl/util/shared_thread_pool.hpp> | ||
#include "android_thread_pool.hpp" | ||
|
||
namespace mbgl { | ||
|
||
std::shared_ptr<ThreadPool> sharedThreadPool() { | ||
static std::weak_ptr<ThreadPool> weak; | ||
auto pool = weak.lock(); | ||
if (!pool) { | ||
weak = pool = std::make_shared<android::AndroidThreadPool>(4); | ||
} | ||
return pool; | ||
} | ||
|
||
} // namespace mbgl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters