Files
android_development/tools/emulator/opengl/shared/OpenglOsUtils/osThreadUnix.cpp
Andrew Hsieh 8aafafe4bd Fixed crash and 64-bit porting issues
1. "emugen" generates four *dec.cpp files containing code like this
   to decode offset to pointer in stream

   tmp = *(T *)(ptr + 8 + 4 + 4 + 4 + *(size_t *)(ptr +8 + 4 + 4));

   If *dec.cpp are compiled in 64-bit, size_t is 8-byte and dereferencing of
   it is likley to get wild offset for dereferencing of *(T *) to crash the
   code.  Solution is to define tsize_t for "target size_t" instead
   of using host size_t.

2. Cast pointer to "uintptr_t" instead of "unsigned int" for 2nd param of
   ShareGroup::getGlobalName(NamedObjectType, ObjectLocalName/*64bit*/).
3. Instance of EGLSurface, EGLContext and EGLImageKHR are used as 32-bit
   key for std::map< unsigned int, * > SurfacesHndlMap, ContextsHndlMap,
   and ImagesHndlMap, respectively.  Cast pointer to uintptr_t and assert
   upper 32-bit is zero before passing to map::find().
4. Instance of GLeglImageOES is used to eglAttachEGLImage() which expect
   "unsigned int".  Cast it to uintptr_t and assert upper 32-bit is zero.
5. The 5th param to GLEScontext::setPointer is GLvoid* but contains 32-bit
   offset to vbo if bufferName exists.  Cast it to uintptr_t and assert
   upper 32-bit is zero.
6. Use %zu instead of %d to print size_t
7. Cast pointer to (uintptr_t) in many other places

Change-Id: Iba6e5bda08c43376db5b011e9d781481ee1f5a12
2012-03-22 11:10:31 -07:00

95 lines
1.9 KiB
C++

/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "osThread.h"
namespace osUtils {
Thread::Thread() :
m_thread((pthread_t)NULL),
m_exitStatus(0),
m_isRunning(false)
{
pthread_mutex_init(&m_lock, NULL);
}
Thread::~Thread()
{
pthread_mutex_destroy(&m_lock);
}
bool
Thread::start()
{
pthread_mutex_lock(&m_lock);
m_isRunning = true;
int ret = pthread_create(&m_thread, NULL, Thread::thread_main, this);
if(ret) {
m_isRunning = false;
}
pthread_mutex_unlock(&m_lock);
return m_isRunning;
}
bool
Thread::wait(int *exitStatus)
{
if (!m_isRunning) {
return false;
}
void *retval;
if (pthread_join(m_thread,&retval)) {
return false;
}
long long int ret=(long long int)retval;
if (exitStatus) {
*exitStatus = (int)ret;
}
return true;
}
bool
Thread::trywait(int *exitStatus)
{
bool ret = false;
pthread_mutex_lock(&m_lock);
if (!m_isRunning) {
*exitStatus = m_exitStatus;
ret = true;
}
pthread_mutex_unlock(&m_lock);
return ret;
}
void *
Thread::thread_main(void *p_arg)
{
Thread *self = (Thread *)p_arg;
void *ret = (void *)self->Main();
pthread_mutex_lock(&self->m_lock);
self->m_isRunning = false;
self->m_exitStatus = (int)(intptr_t)ret;
pthread_mutex_unlock(&self->m_lock);
return ret;
}
} // of namespace osUtils