Skip to content

Instantly share code, notes, and snippets.

@syg
Created December 8, 2012 00:15
Show Gist options
  • Save syg/4237738 to your computer and use it in GitHub Desktop.
Save syg/4237738 to your computer and use it in GitHub Desktop.
diff --git a/js/src/jsapi.cpp b/js/src/jsapi.cpp
index 47060f4..8b2e769 100644
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -738,7 +738,8 @@ js::PerThreadData::PerThreadData(JSRuntime *runtime)
{}
JSRuntime::JSRuntime(JSUseHelperThreads useHelperThreads)
- : mainThread(this),
+ : RuntimeFriendFields(&mainThread),
+ mainThread(this),
atomsCompartment(NULL),
#ifdef JS_THREADSAFE
ownerThread_(NULL),
diff --git a/js/src/jsfriendapi.cpp b/js/src/jsfriendapi.cpp
index f20a2f2..bc58947 100644
--- a/js/src/jsfriendapi.cpp
+++ b/js/src/jsfriendapi.cpp
@@ -22,9 +22,6 @@
using namespace js;
using namespace JS;
-// Required by PerThreadDataFriendFields::getMainThread()
-JS_STATIC_ASSERT(offsetof(JSRuntime, mainThread) == JS_PERTHREADDATAOFFSET);
-
PerThreadDataFriendFields::PerThreadDataFriendFields()
{
#if defined(JSGC_ROOT_ANALYSIS) || defined(JSGC_USE_EXACT_ROOTING)
diff --git a/js/src/jspubtd.h b/js/src/jspubtd.h
index e699e68..cf4d641 100644
--- a/js/src/jspubtd.h
+++ b/js/src/jspubtd.h
@@ -299,26 +299,24 @@ struct ContextFriendFields {
#endif
};
+class PerThreadData;
+
struct RuntimeFriendFields {
/*
* If non-zero, we were been asked to call the operation callback as soon
* as possible.
*/
volatile int32_t interrupt;
+ PerThreadData *mainThreadPtr;
- RuntimeFriendFields()
- : interrupt(0) { }
+ RuntimeFriendFields(PerThreadData *mainThread)
+ : interrupt(0), mainThreadPtr(mainThread) { }
static const RuntimeFriendFields *get(const JSRuntime *rt) {
return reinterpret_cast<const RuntimeFriendFields *>(rt);
}
};
-class PerThreadData;
-
-#define JS_PERTHREADDATAOFFSET \
- ((sizeof(RuntimeFriendFields) + (sizeof(uintptr_t) - 1)) & sizeof(uintptr_t))
-
struct PerThreadDataFriendFields
{
PerThreadDataFriendFields();
@@ -341,15 +339,13 @@ struct PerThreadDataFriendFields
static PerThreadDataFriendFields *getMainThread(JSRuntime *rt) {
// mainThread must always appear directly after |RuntimeFriendFields|.
// Tested by a JS_STATIC_ASSERT in |jsfriendapi.cpp|
- return reinterpret_cast<PerThreadDataFriendFields *>(
- reinterpret_cast<char*>(rt) + JS_PERTHREADDATAOFFSET);
+ return reinterpret_cast<PerThreadDataFriendFields *>(RuntimeFriendFields::get(rt)->mainThreadPtr);
}
static const PerThreadDataFriendFields *getMainThread(const JSRuntime *rt) {
// mainThread must always appear directly after |RuntimeFriendFields|.
// Tested by a JS_STATIC_ASSERT in |jsfriendapi.cpp|
- return reinterpret_cast<const PerThreadDataFriendFields *>(
- reinterpret_cast<const char*>(rt) + JS_PERTHREADDATAOFFSET);
+ return reinterpret_cast<const PerThreadDataFriendFields *>(RuntimeFriendFields::get(rt)->mainThreadPtr);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment