Skip to content

Commit

Permalink
Disabling direct TLS_SLOT_OPENGL_API access on i386
Browse files Browse the repository at this point in the history
Direct access to TLS_SLOT_OPENGL_API breaks the TLS handling done
by glibc, so just use pthread_setspecific/getspecific instead
(generic implementation).

Not setting as default as we might have some performance issues on arm.

Change-Id: I7cf9f45a3ba0b579741cb7de4dd9acf01d93aec6
Signed-off-by: Ricardo Salveti de Araujo <[email protected]>
Signed-off-by: Ondrej Kubik <[email protected]>
  • Loading branch information
Ricardo Salveti de Araujo authored and mariogrip committed Nov 2, 2015
1 parent 7c703b0 commit 50f14f2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
13 changes: 13 additions & 0 deletions opengl/libs/EGL/egl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ gl_hooks_t gHooks[2];
gl_hooks_t gHooksNoContext;
pthread_key_t gGLWrapperKey = -1;

#if defined(__i386__)
EGLAPI pthread_key_t gGLKey = -1;
#endif

// ----------------------------------------------------------------------------

#if EGL_TRACE
Expand Down Expand Up @@ -231,6 +235,9 @@ static int gl_no_context() {

static void early_egl_init(void)
{
#if defined(__i386__)
pthread_key_create(&gGLKey, NULL);
#endif
#if EGL_TRACE
pthread_key_create(&gGLTraceKey, NULL);
initEglTraceLevel();
Expand Down Expand Up @@ -358,10 +365,16 @@ void gl_noop() {

// ----------------------------------------------------------------------------

#if defined(__i386__)
inline void setGlThreadSpecific(gl_hooks_t const *value) {
pthread_setspecific(gGLKey, value);
}
#else
void setGlThreadSpecific(gl_hooks_t const *value) {
gl_hooks_t const * volatile * tls_hooks = get_tls_hooks();
tls_hooks[TLS_SLOT_OPENGL_API] = value;
}
#endif

// ----------------------------------------------------------------------------
// GL / EGL hooks
Expand Down
8 changes: 8 additions & 0 deletions opengl/libs/hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ struct gl_hooks_t {

EGLAPI void setGlThreadSpecific(gl_hooks_t const *value);

#if defined(__i386__)
extern EGLAPI pthread_key_t gGLKey;

inline EGLAPI gl_hooks_t const* getGlThreadSpecific() {
return static_cast<gl_hooks_t*>(pthread_getspecific(gGLKey));
}
#else
// We have a dedicated TLS slot in bionic
inline gl_hooks_t const * volatile * get_tls_hooks() {
volatile void *tls_base = __get_tls();
Expand All @@ -88,6 +95,7 @@ inline EGLAPI gl_hooks_t const* getGlThreadSpecific() {
gl_hooks_t const* hooks = tls_hooks[TLS_SLOT_OPENGL_API];
return hooks;
}
#endif

// ----------------------------------------------------------------------------
}; // namespace android
Expand Down

0 comments on commit 50f14f2

Please sign in to comment.