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
d22b88e
commit 3938e16
Showing
6 changed files
with
84 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,23 @@ | ||
#include "android_thread_pool.hpp" | ||
#include <mbgl/util/platform.hpp> | ||
#include <cassert> | ||
|
||
namespace mbgl { | ||
namespace android { | ||
|
||
AndroidThreadPool::AndroidThreadPool(size_t count) | ||
: mbgl::ThreadPool(count, { | ||
[] { | ||
JNIEnv* env = nullptr; | ||
attach_jni_thread(theJVM, &env, platform::getCurrentThreadName()); | ||
return env; | ||
}, | ||
[](ThreadLifecycle::ThreadData threadData_) { | ||
assert(threadData_); | ||
auto env = static_cast<JNIEnv*>(threadData_); | ||
detach_jni_thread(theJVM, &env, true); | ||
} | ||
}) {} | ||
|
||
} // 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 @@ | ||
#pragma once | ||
#include <mbgl/util/default_thread_pool.hpp> | ||
#include <map> | ||
#include "jni.hpp" | ||
|
||
namespace mbgl { | ||
namespace android { | ||
|
||
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