• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "ThreadInfo.h"
18 
19 
updateInfo(ContextPtr eglCtx,EglDisplay * dpy,GLEScontext * glesCtx,ShareGroupPtr share,ObjectNameManager * manager)20 void ThreadInfo::updateInfo(ContextPtr eglCtx,
21                             EglDisplay* dpy,
22                             GLEScontext* glesCtx,
23                             ShareGroupPtr share,
24                             ObjectNameManager* manager) {
25 
26     eglContext  = eglCtx;
27     eglDisplay  = dpy;
28     glesContext = glesCtx;
29     shareGroup  = share;
30     objManager  = manager;
31 }
32 
33 #ifdef __linux__
34 
35 __thread ThreadInfo* thread  = NULL;
36 
getThreadInfo()37 ThreadInfo* getThreadInfo(){
38     if(!thread) {
39         thread = new ThreadInfo();
40     }
41     return thread;
42 }
43 
44 #else
45 
46 #include <cutils/threads.h>
47 static thread_store_t s_tls = THREAD_STORE_INITIALIZER;
48 
tlsDestruct(void * ptr)49 static void tlsDestruct(void *ptr)
50 {
51     if (ptr) {
52         ThreadInfo *ti = (ThreadInfo *)ptr;
53         delete ti;
54     }
55 }
56 
getThreadInfo()57 ThreadInfo *getThreadInfo()
58 {
59     ThreadInfo *ti = (ThreadInfo *)thread_store_get(&s_tls);
60     if (!ti) {
61         ti = new ThreadInfo();
62         thread_store_set(&s_tls, ti, tlsDestruct);
63     }
64     return ti;
65 }
66 
67 #endif
68