Bug 794981 - Part 7: Storing a void* for mThread instead of a pthread_t is both nonportable and dangerous. r=kats

This commit is contained in:
Chris Kitching 2013-09-09 08:57:37 -04:00
parent 654d1dd63c
commit 75cc5662cd
3 changed files with 10 additions and 10 deletions

View File

@ -31,10 +31,10 @@
struct AutoAttachJavaThread {
AutoAttachJavaThread() {
attached = mozilla_AndroidBridge_SetMainThread((void*)pthread_self());
attached = mozilla_AndroidBridge_SetMainThread(pthread_self());
}
~AutoAttachJavaThread() {
mozilla_AndroidBridge_SetMainThread(nullptr);
mozilla_AndroidBridge_SetMainThread(-1);
attached = false;
}

View File

@ -165,7 +165,7 @@ AndroidBridge::Init(JNIEnv *jEnv)
AutoLocalJNIFrame jniFrame(jEnv);
mJNIEnv = nullptr;
mThread = nullptr;
mThread = -1;
mGLControllerObj = nullptr;
mOpenedGraphicsLibraries = false;
mHasNativeBitmapAccess = false;
@ -216,7 +216,7 @@ AndroidBridge::Init(JNIEnv *jEnv)
}
bool
AndroidBridge::SetMainThread(void *thr)
AndroidBridge::SetMainThread(pthread_t thr)
{
ALOG_BRIDGE("AndroidBridge::SetMainThread");
if (thr) {
@ -226,7 +226,7 @@ AndroidBridge::SetMainThread(void *thr)
}
mJNIEnv = nullptr;
mThread = nullptr;
mThread = -1;
return true;
}
@ -801,7 +801,7 @@ AndroidBridge::GetStaticStringField(const char *className, const char *fieldName
// Available for places elsewhere in the code to link to.
bool
mozilla_AndroidBridge_SetMainThread(void *thr)
mozilla_AndroidBridge_SetMainThread(pthread_t thr)
{
return AndroidBridge::Bridge()->SetMainThread(thr);
}

View File

@ -42,7 +42,7 @@ class nsIDOMMozSmsMessage;
/* See the comment in AndroidBridge about this function before using it */
extern "C" JNIEnv * GetJNIForThread();
extern bool mozilla_AndroidBridge_SetMainThread(void *);
extern bool mozilla_AndroidBridge_SetMainThread(pthread_t);
extern jclass GetGeckoAppShellClass();
namespace base {
@ -149,7 +149,7 @@ public:
static JNIEnv *GetJNIEnv() {
if (MOZ_LIKELY(sBridge)) {
if ((void*)pthread_self() != sBridge->mThread) {
if (!pthread_equal(pthread_self(), sBridge->mThread)) {
__android_log_print(ANDROID_LOG_INFO, "AndroidBridge",
"###!!!!!!! Something's grabbing the JNIEnv from the wrong thread! (thr %p should be %p)",
(void*)pthread_self(), (void*)sBridge->mThread);
@ -171,7 +171,7 @@ public:
// SetMainThread should be called which will create the JNIEnv for
// us to use. toolkit/xre/nsAndroidStartup.cpp calls
// SetMainThread.
bool SetMainThread(void *thr);
bool SetMainThread(pthread_t thr);
/* These are all implemented in Java */
bool GetThreadNameJavaProfiling(uint32_t aThreadId, nsCString & aResult);
@ -341,7 +341,7 @@ protected:
// the JNIEnv for the main thread
JNIEnv *mJNIEnv;
void *mThread;
pthread_t mThread;
AndroidGeckoLayerClient *mLayerClient;