3 ** Copyright 2007, The Android Open Source Project
5 ** Licensed under the Apache License, Version 2.0 (the "License");
6 ** you may not use this file except in compliance with the License.
7 ** You may obtain a copy of the License at
9 ** http://www.apache.org/licenses/LICENSE-2.0
11 ** Unless required by applicable law or agreed to in writing, software
12 ** distributed under the License is distributed on an "AS IS" BASIS,
13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 ** See the License for the specific language governing permissions and
15 ** limitations under the License.
18 #include "playerdriver.h"
19 #include <media/thread_init.h>
20 //#include <android_runtime/AndroidRuntime.h>
21 #include <utils/threads.h>
22 #include "android_log_appender.h"
23 #include "pvlogger_time_and_id_layout.h"
26 #include "oscl_error.h"
30 #include "android_logger_config.h"
32 using namespace android;
33 static pthread_key_t ptkey=NULL;
35 static void keydestructor(void*)
37 // This thread is about to exit, so we can un-initialize
38 // PV for this thread.
39 UninitializeForThread();
42 static pthread_once_t create_tls_entry_once = PTHREAD_ONCE_INIT;
44 static void CreateTLSEntry() {
46 0 != pthread_key_create(&ptkey, keydestructor),
47 "Ran out of TLS entries");
50 template<class DestructClass>
51 class LogAppenderDestructDealloc : public OsclDestructDealloc
54 virtual void destruct_and_dealloc(OsclAny *ptr)
56 delete((DestructClass*)ptr);
60 bool InitializeForThread()
62 pthread_once(&create_tls_entry_once, &CreateTLSEntry);
64 if (NULL == pthread_getspecific(ptkey)) {
65 // PV hasn't yet been initialized for this thread;
66 int error = OsclBase::Init();
69 LOGE("OsclBase::Init error %d", error);
72 error = OsclErrorTrap::Init();
75 LOGE("OsclErrorTrap::Init error %d", error);
82 error = pthread_setspecific(ptkey,data);
85 LOGE("pthread_setspecific error %d", error);
88 PVLoggerConfigFile obj;
89 obj.ReadAndParseLoggerConfigFile();
95 void UninitializeForThread() {
98 OsclErrorTrap::Cleanup();
100 // In case this didn't get called from keydestructor(), set the key
101 // to NULL for this thread, which prevents the keydestructor() from
102 // running once the thread actually exits.
104 pthread_setspecific(ptkey,data);