1 /* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include <stdio.h> 18 #include "ThreadInfo.h" 19 20 //#define TRACE_THREADINFO 21 #ifdef TRACE_THREADINFO 22 #define LOG_THREADINFO(x...) fprintf(stderr, x) 23 #else 24 #define LOG_THREADINFO(x...) 25 #endif 26 27 void ThreadInfo::updateInfo(ContextPtr eglCtx, 28 EglDisplay* dpy, 29 GLEScontext* glesCtx, 30 ShareGroupPtr share, 31 ObjectNameManager* manager) { 32 33 eglContext = eglCtx; 34 eglDisplay = dpy; 35 glesContext = glesCtx; 36 shareGroup = share; 37 objManager = manager; 38 } 39 40 #include <cutils/threads.h> 41 static thread_store_t s_tls = THREAD_STORE_INITIALIZER; 42 static int active_instance = 0; 43 static void tlsDestruct(void *ptr) 44 { 45 active_instance--; 46 LOG_THREADINFO("tlsDestruct EGL %lx %d\n", (long)ptr, active_instance); 47 if (ptr) { 48 ThreadInfo *ti = (ThreadInfo *)ptr; 49 delete ti; 50 } 51 } 52 53 ThreadInfo *getThreadInfo() 54 { 55 ThreadInfo *ti = (ThreadInfo *)thread_store_get(&s_tls); 56 if (!ti) { 57 ti = new ThreadInfo(); 58 thread_store_set(&s_tls, ti, tlsDestruct); 59 active_instance++; 60 LOG_THREADINFO("getThreadInfo EGL %lx %d\n", (long)ti, active_instance); 61 } 62 return ti; 63 } 64