diff options
30 files changed, 458 insertions, 220 deletions
| diff --git a/emulator/opengl/host/libs/Translator/EGL/EglDisplay.cpp b/emulator/opengl/host/libs/Translator/EGL/EglDisplay.cpp index 3516986..24b9a0d 100644 --- a/emulator/opengl/host/libs/Translator/EGL/EglDisplay.cpp +++ b/emulator/opengl/host/libs/Translator/EGL/EglDisplay.cpp @@ -16,7 +16,6 @@  #include "EglDisplay.h"  #include "EglOsApi.h"  #include <GLcommon/GLutils.h> -#include <utils/threads.h>  EglDisplay::EglDisplay(EGLNativeInternalDisplayType dpy,bool isDefault) :      m_dpy(dpy), @@ -31,7 +30,7 @@ EglDisplay::EglDisplay(EGLNativeInternalDisplayType dpy,bool isDefault) :  };  EglDisplay::~EglDisplay() { -    android::Mutex::Autolock mutex(m_lock); +    emugl::Mutex::AutoLock mutex(m_lock);      //      // Destroy the global context if one was created. @@ -59,7 +58,7 @@ EglDisplay::~EglDisplay() {  EGLNativeInternalDisplayType EglDisplay::nativeType(){return m_dpy;}  void EglDisplay::initialize(int renderableType) { -    android::Mutex::Autolock mutex(m_lock); +    emugl::Mutex::AutoLock mutex(m_lock);      m_initialized = true;      initConfigurations(renderableType);      m_configInitialized = true; @@ -68,7 +67,7 @@ void EglDisplay::initialize(int renderableType) {  bool EglDisplay::isInitialize() { return m_initialized;}  void EglDisplay::terminate(){ -    android::Mutex::Autolock mutex(m_lock); +    emugl::Mutex::AutoLock mutex(m_lock);       m_contexts.clear();       m_surfaces.clear();       m_initialized = false; @@ -128,7 +127,7 @@ void EglDisplay::initConfigurations(int renderableType) {  }  EglConfig* EglDisplay::getConfig(EGLConfig conf) { -    android::Mutex::Autolock mutex(m_lock); +    emugl::Mutex::AutoLock mutex(m_lock);      for(ConfigsList::iterator it = m_configs.begin(); it != m_configs.end() ;it++) {          if(static_cast<EGLConfig>(*it) == conf) { @@ -140,7 +139,7 @@ EglConfig* EglDisplay::getConfig(EGLConfig conf) {  }  SurfacePtr EglDisplay::getSurface(EGLSurface surface) { -    android::Mutex::Autolock mutex(m_lock); +    emugl::Mutex::AutoLock mutex(m_lock);      /* surface is "key" in map<unsigned int, SurfacePtr>. */      unsigned int hndl = SafeUIntFromPointer(surface);      SurfacesHndlMap::iterator it = m_surfaces.find(hndl); @@ -150,7 +149,7 @@ SurfacePtr EglDisplay::getSurface(EGLSurface surface) {  }  ContextPtr EglDisplay::getContext(EGLContext ctx) { -    android::Mutex::Autolock mutex(m_lock); +    emugl::Mutex::AutoLock mutex(m_lock);      /* ctx is "key" in map<unsigned int, ContextPtr>. */      unsigned int hndl = SafeUIntFromPointer(ctx);      ContextsHndlMap::iterator it = m_contexts.find(hndl); @@ -160,7 +159,7 @@ ContextPtr EglDisplay::getContext(EGLContext ctx) {  }  bool EglDisplay::removeSurface(EGLSurface s) { -    android::Mutex::Autolock mutex(m_lock); +    emugl::Mutex::AutoLock mutex(m_lock);      /* s is "key" in map<unsigned int, SurfacePtr>. */      unsigned int hndl = SafeUIntFromPointer(s);      SurfacesHndlMap::iterator it = m_surfaces.find(hndl); @@ -172,7 +171,7 @@ bool EglDisplay::removeSurface(EGLSurface s) {  }  bool EglDisplay::removeSurface(SurfacePtr s) { -    android::Mutex::Autolock mutex(m_lock); +    emugl::Mutex::AutoLock mutex(m_lock);      SurfacesHndlMap::iterator it;      for(it = m_surfaces.begin(); it!= m_surfaces.end();it++) @@ -189,7 +188,7 @@ bool EglDisplay::removeSurface(SurfacePtr s) {  }  bool EglDisplay::removeContext(EGLContext ctx) { -    android::Mutex::Autolock mutex(m_lock); +    emugl::Mutex::AutoLock mutex(m_lock);      /* ctx is "key" in map<unsigned int, ContextPtr>. */      unsigned int hndl = SafeUIntFromPointer(ctx);      ContextsHndlMap::iterator it = m_contexts.find(hndl); @@ -201,7 +200,7 @@ bool EglDisplay::removeContext(EGLContext ctx) {  }  bool EglDisplay::removeContext(ContextPtr ctx) { -    android::Mutex::Autolock mutex(m_lock); +    emugl::Mutex::AutoLock mutex(m_lock);      ContextsHndlMap::iterator it;      for(it = m_contexts.begin(); it != m_contexts.end();it++) { @@ -217,7 +216,7 @@ bool EglDisplay::removeContext(ContextPtr ctx) {  }  EglConfig* EglDisplay::getConfig(EGLint id) { -    android::Mutex::Autolock mutex(m_lock); +    emugl::Mutex::AutoLock mutex(m_lock);      for(ConfigsList::iterator it = m_configs.begin(); it != m_configs.end() ;it++) {          if((*it)->id() == id) { @@ -229,7 +228,7 @@ EglConfig* EglDisplay::getConfig(EGLint id) {  }  int EglDisplay::getConfigs(EGLConfig* configs,int config_size) { -    android::Mutex::Autolock mutex(m_lock); +    emugl::Mutex::AutoLock mutex(m_lock);      int i = 0;      for(ConfigsList::iterator it = m_configs.begin(); it != m_configs.end() && i < config_size ;i++,it++) {          configs[i] = static_cast<EGLConfig>(*it); @@ -238,7 +237,7 @@ int EglDisplay::getConfigs(EGLConfig* configs,int config_size) {  }  int EglDisplay::chooseConfigs(const EglConfig& dummy,EGLConfig* configs,int config_size) { -    android::Mutex::Autolock mutex(m_lock); +    emugl::Mutex::AutoLock mutex(m_lock);      return doChooseConfigs(dummy, configs, config_size);  } @@ -258,7 +257,7 @@ int EglDisplay::doChooseConfigs(const EglConfig& dummy,EGLConfig* configs,int co  }  EGLSurface EglDisplay::addSurface(SurfacePtr s ) { -   android::Mutex::Autolock mutex(m_lock); +   emugl::Mutex::AutoLock mutex(m_lock);     unsigned int hndl = s.Ptr()->getHndl();     EGLSurface ret =reinterpret_cast<EGLSurface> (hndl); @@ -271,7 +270,7 @@ EGLSurface EglDisplay::addSurface(SurfacePtr s ) {  }  EGLContext EglDisplay::addContext(ContextPtr ctx ) { -    android::Mutex::Autolock mutex(m_lock); +    emugl::Mutex::AutoLock mutex(m_lock);     unsigned int hndl = ctx.Ptr()->getHndl();     EGLContext ret    = reinterpret_cast<EGLContext> (hndl); @@ -285,7 +284,7 @@ EGLContext EglDisplay::addContext(ContextPtr ctx ) {  EGLImageKHR EglDisplay::addImageKHR(ImagePtr img) { -    android::Mutex::Autolock mutex(m_lock); +    emugl::Mutex::AutoLock mutex(m_lock);      do { ++m_nextEglImageId; } while(m_nextEglImageId == 0);      img->imageId = m_nextEglImageId;      m_eglImages[m_nextEglImageId] = img; @@ -293,7 +292,7 @@ EGLImageKHR EglDisplay::addImageKHR(ImagePtr img) {  }  ImagePtr EglDisplay::getImage(EGLImageKHR img) { -    android::Mutex::Autolock mutex(m_lock); +    emugl::Mutex::AutoLock mutex(m_lock);      /* img is "key" in map<unsigned int, ImagePtr>. */      unsigned int hndl = SafeUIntFromPointer(img);      ImagesHndlMap::iterator i( m_eglImages.find(hndl) ); @@ -301,7 +300,7 @@ ImagePtr EglDisplay::getImage(EGLImageKHR img) {  }  bool EglDisplay:: destroyImageKHR(EGLImageKHR img) { -    android::Mutex::Autolock mutex(m_lock); +    emugl::Mutex::AutoLock mutex(m_lock);      /* img is "key" in map<unsigned int, ImagePtr>. */      unsigned int hndl = SafeUIntFromPointer(img);      ImagesHndlMap::iterator i( m_eglImages.find(hndl) ); @@ -314,7 +313,7 @@ bool EglDisplay:: destroyImageKHR(EGLImageKHR img) {  }  EGLNativeContextType EglDisplay::getGlobalSharedContext(){ -    android::Mutex::Autolock mutex(m_lock); +    emugl::Mutex::AutoLock mutex(m_lock);  #ifndef _WIN32      // find an existing OpenGL context to share with, if exist      EGLNativeContextType ret =  diff --git a/emulator/opengl/host/libs/Translator/EGL/EglDisplay.h b/emulator/opengl/host/libs/Translator/EGL/EglDisplay.h index 889a84f..47a2598 100644 --- a/emulator/opengl/host/libs/Translator/EGL/EglDisplay.h +++ b/emulator/opengl/host/libs/Translator/EGL/EglDisplay.h @@ -20,7 +20,7 @@  #include <map>  #include <EGL/egl.h>  #include <EGL/eglext.h> -#include <utils/threads.h> +#include "emugl/common/mutex.h"  #include "emugl/common/smart_ptr.h"  #include "EglConfig.h" @@ -82,7 +82,7 @@ private:     SurfacesHndlMap                m_surfaces;     GlobalNameSpace                m_globalNameSpace;     ObjectNameManager              *m_manager[MAX_GLES_VERSION]; -   android::Mutex                 m_lock; +   emugl::Mutex                   m_lock;     ImagesHndlMap                  m_eglImages;     unsigned int                   m_nextEglImageId;     EGLNativeContextType           m_globalSharedContext; diff --git a/emulator/opengl/host/libs/Translator/EGL/EglGlobalInfo.cpp b/emulator/opengl/host/libs/Translator/EGL/EglGlobalInfo.cpp index 8e5b462..95b696e 100644 --- a/emulator/opengl/host/libs/Translator/EGL/EglGlobalInfo.cpp +++ b/emulator/opengl/host/libs/Translator/EGL/EglGlobalInfo.cpp @@ -51,7 +51,7 @@ void EglGlobalInfo::delInstance() {  EglDisplay* EglGlobalInfo::addDisplay(EGLNativeDisplayType dpy,EGLNativeInternalDisplayType idpy) {      //search if it is not already exists -    android::Mutex::Autolock mutex(m_lock); +    emugl::Mutex::AutoLock mutex(m_lock);      for(DisplaysMap::iterator it = m_displays.begin(); it != m_displays.end() ;it++) {          if((*it).second == dpy) return (*it).first;      } @@ -68,7 +68,7 @@ EglDisplay* EglGlobalInfo::addDisplay(EGLNativeDisplayType dpy,EGLNativeInternal  }  bool  EglGlobalInfo::removeDisplay(EGLDisplay dpy) { -    android::Mutex::Autolock mutex(m_lock); +    emugl::Mutex::AutoLock mutex(m_lock);      for(DisplaysMap::iterator it = m_displays.begin(); it != m_displays.end() ;it++) {          if(static_cast<EGLDisplay>((*it).first) == dpy) {              delete (*it).first; @@ -80,7 +80,7 @@ bool  EglGlobalInfo::removeDisplay(EGLDisplay dpy) {  }  EglDisplay* EglGlobalInfo::getDisplay(EGLNativeDisplayType dpy) { -    android::Mutex::Autolock mutex(m_lock); +    emugl::Mutex::AutoLock mutex(m_lock);      for(DisplaysMap::iterator it = m_displays.begin(); it != m_displays.end() ;it++) {          if((*it).second == dpy) return (*it).first;      } @@ -88,7 +88,7 @@ EglDisplay* EglGlobalInfo::getDisplay(EGLNativeDisplayType dpy) {  }  EglDisplay* EglGlobalInfo::getDisplay(EGLDisplay dpy) { -    android::Mutex::Autolock mutex(m_lock); +    emugl::Mutex::AutoLock mutex(m_lock);      DisplaysMap::iterator it = m_displays.find(static_cast<EglDisplay*>(dpy));      return (it != m_displays.end() ? (*it).first : NULL);  } @@ -99,7 +99,7 @@ EGLNativeInternalDisplayType EglGlobalInfo::generateInternalDisplay(EGLNativeDis  void EglGlobalInfo::initClientExtFuncTable(GLESVersion ver)  { -    android::Mutex::Autolock mutex(m_lock); +    emugl::Mutex::AutoLock mutex(m_lock);      if (!m_gles_extFuncs_inited[ver]) {          ClientAPIExts::initClientFuncs(m_gles_ifaces[ver], (int)ver - 1);          m_gles_extFuncs_inited[ver] = true; diff --git a/emulator/opengl/host/libs/Translator/EGL/EglGlobalInfo.h b/emulator/opengl/host/libs/Translator/EGL/EglGlobalInfo.h index ec07ffe..f56b79e 100644 --- a/emulator/opengl/host/libs/Translator/EGL/EglGlobalInfo.h +++ b/emulator/opengl/host/libs/Translator/EGL/EglGlobalInfo.h @@ -16,14 +16,15 @@  #ifndef EGL_GLOBAL_INFO  #define EGL_GLOBAL_INFO -#include <list> -#include <EGL/egl.h> -#include <utils/threads.h> -#include <GLcommon/TranslatorIfaces.h>  #include "EglDisplay.h"  #include "EglConfig.h"  #include "EglContext.h" +#include <GLcommon/TranslatorIfaces.h> +#include "emugl/common/mutex.h" +#include <list> +#include <EGL/egl.h> +  typedef std::map<EglDisplay*,EGLNativeDisplayType>DisplaysMap; @@ -58,7 +59,7 @@ private:      EGLNativeInternalDisplayType   m_default;      GLESiface*                     m_gles_ifaces[MAX_GLES_VERSION];      bool                           m_gles_extFuncs_inited[MAX_GLES_VERSION]; -    android::Mutex                 m_lock; +    emugl::Mutex                   m_lock;  };  #endif diff --git a/emulator/opengl/host/libs/Translator/EGL/EglImp.cpp b/emulator/opengl/host/libs/Translator/EGL/EglImp.cpp index 1d5c494..e31dea5 100644 --- a/emulator/opengl/host/libs/Translator/EGL/EglImp.cpp +++ b/emulator/opengl/host/libs/Translator/EGL/EglImp.cpp @@ -50,11 +50,11 @@ GLEScontext* getGLESContext();  #define tls_thread  EglThreadInfo::get()  EglGlobalInfo* g_eglInfo = NULL; -android::Mutex  s_eglLock; +emugl::Mutex  s_eglLock;  void initGlobalInfo()  { -    android::Mutex::Autolock mutex(s_eglLock); +    emugl::Mutex::AutoLock mutex(s_eglLock);      if (!g_eglInfo) {          g_eglInfo = EglGlobalInfo::getInstance();      }  diff --git a/emulator/opengl/host/libs/Translator/EGL/EglX11Api.cpp b/emulator/opengl/host/libs/Translator/EGL/EglX11Api.cpp index a8c624e..41cf8c4 100644 --- a/emulator/opengl/host/libs/Translator/EGL/EglX11Api.cpp +++ b/emulator/opengl/host/libs/Translator/EGL/EglX11Api.cpp @@ -14,10 +14,11 @@  * limitations under the License.  */  #include "EglOsApi.h" +#include "emugl/common/mutex.h" +  #include <string.h>  #include <X11/Xlib.h>  #include <GL/glx.h> -#include <utils/threads.h>  class ErrorHandler{ @@ -29,7 +30,7 @@ int getLastError(){ return s_lastErrorCode;};  private:  static int s_lastErrorCode;  int (*m_oldErrorHandler) (Display *, XErrorEvent *); -static android::Mutex s_lock; +static emugl::Mutex s_lock;  static int errorHandlerProc(EGLNativeDisplayType dpy,XErrorEvent* event);  }; @@ -50,17 +51,17 @@ private:  };  int ErrorHandler::s_lastErrorCode = 0; -android::Mutex ErrorHandler::s_lock; +emugl::Mutex ErrorHandler::s_lock;  ErrorHandler::ErrorHandler(EGLNativeDisplayType dpy){ -   android::Mutex::Autolock mutex(s_lock); +   emugl::Mutex::AutoLock mutex(s_lock);     XSync(dpy,False);     s_lastErrorCode = 0;     m_oldErrorHandler = XSetErrorHandler(errorHandlerProc);  }  ErrorHandler::~ErrorHandler(){ -   android::Mutex::Autolock mutex(s_lock); +   emugl::Mutex::AutoLock mutex(s_lock);     XSetErrorHandler(m_oldErrorHandler);     s_lastErrorCode = 0;  } diff --git a/emulator/opengl/host/libs/Translator/GLES_CM/GLDispatch.cpp b/emulator/opengl/host/libs/Translator/GLES_CM/GLDispatch.cpp index af5c0d8..66adefb 100644 --- a/emulator/opengl/host/libs/Translator/GLES_CM/GLDispatch.cpp +++ b/emulator/opengl/host/libs/Translator/GLES_CM/GLDispatch.cpp @@ -51,7 +51,7 @@ GLDispatch::GLDispatch():m_isLoaded(false){};  void GLDispatch::dispatchFuncs() { -    android::Mutex::Autolock mutex(m_lock); +    emugl::Mutex::AutoLock mutex(m_lock);      if(m_isLoaded)          return;      LOAD_GL_FUNC(glActiveTexture); diff --git a/emulator/opengl/host/libs/Translator/GLES_CM/GLDispatch.h b/emulator/opengl/host/libs/Translator/GLES_CM/GLDispatch.h index 9dc320f..ae8c9f8 100644 --- a/emulator/opengl/host/libs/Translator/GLES_CM/GLDispatch.h +++ b/emulator/opengl/host/libs/Translator/GLES_CM/GLDispatch.h @@ -17,7 +17,7 @@  #define GLDISPATCHH  #include <GLES/gl.h> -#include <utils/threads.h> +#include "emugl/common/mutex.h"  #define GLAPIENTRY GL_APIENTRY @@ -151,8 +151,8 @@ public:      void (GLAPIENTRY *glVertexPointer) (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer);      void (GLAPIENTRY *glViewport) (GLint x, GLint y, GLsizei width, GLsizei height);  private: -    bool             m_isLoaded; -    android::Mutex   m_lock; +    bool           m_isLoaded; +    emugl::Mutex   m_lock;  };  #endif diff --git a/emulator/opengl/host/libs/Translator/GLES_CM/GLEScmContext.cpp b/emulator/opengl/host/libs/Translator/GLES_CM/GLEScmContext.cpp index ecf51bb..6476c02 100644 --- a/emulator/opengl/host/libs/Translator/GLES_CM/GLEScmContext.cpp +++ b/emulator/opengl/host/libs/Translator/GLES_CM/GLEScmContext.cpp @@ -23,7 +23,7 @@  #include <GLES/glext.h>  void GLEScmContext::init() { -    android::Mutex::Autolock mutex(s_lock); +    emugl::Mutex::AutoLock mutex(s_lock);      if(!m_initialized) {          s_glDispatch.dispatchFuncs(GLES_1_1);          GLEScontext::init(); diff --git a/emulator/opengl/host/libs/Translator/GLES_CM/GLEScmContext.h b/emulator/opengl/host/libs/Translator/GLES_CM/GLEScmContext.h index 1785877..fbb7023 100644 --- a/emulator/opengl/host/libs/Translator/GLES_CM/GLEScmContext.h +++ b/emulator/opengl/host/libs/Translator/GLES_CM/GLEScmContext.h @@ -23,7 +23,6 @@  #include <map>  #include <vector>  #include <string> -#include <utils/threads.h>  typedef std::map<GLfloat,std::vector<int> > PointSizeIndices; diff --git a/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Context.cpp b/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Context.cpp index 1457cec..f8f674b 100644 --- a/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Context.cpp +++ b/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Context.cpp @@ -15,11 +15,10 @@  */  #include "GLESv2Context.h" - - +#include <string.h>  void GLESv2Context::init() { -    android::Mutex::Autolock mutex(s_lock); +    emugl::Mutex::AutoLock mutex(s_lock);      if(!m_initialized) {          s_glDispatch.dispatchFuncs(GLES_2_0);          GLEScontext::init(); diff --git a/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Context.h b/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Context.h index 75af864..7e71177 100644 --- a/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Context.h +++ b/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Context.h @@ -20,7 +20,6 @@  #include <GLcommon/GLDispatch.h>  #include <GLcommon/GLEScontext.h>  #include <GLcommon/objectNameManager.h> -#include <utils/threads.h> diff --git a/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Validate.cpp b/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Validate.cpp index 53d1314..3f00428 100644 --- a/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Validate.cpp +++ b/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Validate.cpp @@ -14,6 +14,7 @@  * limitations under the License.  */  #include "GLESv2Validate.h" +#include <string.h>  bool GLESv2Validate::blendEquationMode(GLenum mode){      return mode == GL_FUNC_ADD             || diff --git a/emulator/opengl/host/libs/Translator/GLES_V2/ShaderParser.cpp b/emulator/opengl/host/libs/Translator/GLES_V2/ShaderParser.cpp index a80326d..311a9ed 100644 --- a/emulator/opengl/host/libs/Translator/GLES_V2/ShaderParser.cpp +++ b/emulator/opengl/host/libs/Translator/GLES_V2/ShaderParser.cpp @@ -15,6 +15,7 @@  */  #include "ShaderParser.h" +#include <stdlib.h>  #include <string.h>  ShaderParser::ShaderParser():ObjectData(SHADER_DATA), diff --git a/emulator/opengl/host/libs/Translator/GLcommon/GLDispatch.cpp b/emulator/opengl/host/libs/Translator/GLcommon/GLDispatch.cpp index abed760..54aa200 100644 --- a/emulator/opengl/host/libs/Translator/GLcommon/GLDispatch.cpp +++ b/emulator/opengl/host/libs/Translator/GLcommon/GLDispatch.cpp @@ -67,7 +67,7 @@ static GL_FUNC_PTR getGLFuncAddress(const char *funcName) {  /* initializing static GLDispatch members*/ -android::Mutex GLDispatch::s_lock; +emugl::Mutex GLDispatch::s_lock;  void (GLAPIENTRY *GLDispatch::glActiveTexture)(GLenum) = NULL;  void (GLAPIENTRY *GLDispatch::glBindBuffer)(GLenum,GLuint) = NULL;  void (GLAPIENTRY *GLDispatch::glBindTexture)(GLenum, GLuint) = NULL; @@ -298,7 +298,7 @@ GLDispatch::GLDispatch():m_isLoaded(false){};  void GLDispatch::dispatchFuncs(GLESVersion version){ -    android::Mutex::Autolock mutex(s_lock); +    emugl::Mutex::AutoLock mutex(s_lock);      if(m_isLoaded)          return; diff --git a/emulator/opengl/host/libs/Translator/GLcommon/GLEScontext.cpp b/emulator/opengl/host/libs/Translator/GLcommon/GLEScontext.cpp index 6572719..46f039c 100644 --- a/emulator/opengl/host/libs/Translator/GLcommon/GLEScontext.cpp +++ b/emulator/opengl/host/libs/Translator/GLcommon/GLEScontext.cpp @@ -23,6 +23,7 @@  #include <GLcommon/TextureUtils.h>  #include <GLcommon/FramebufferData.h>  #include <strings.h> +#include <string.h>  //decleration  static void convertFixedDirectLoop(const char* dataIn,unsigned int strideIn,void* dataOut,unsigned int nBytes,unsigned int strideOut,int attribSize); @@ -84,7 +85,7 @@ void GLESConversionArrays::operator++(){  }  GLDispatch     GLEScontext::s_glDispatch; -android::Mutex GLEScontext::s_lock; +emugl::Mutex   GLEScontext::s_lock;  std::string*   GLEScontext::s_glExtensions= NULL;  std::string    GLEScontext::s_glVendor;  std::string    GLEScontext::s_glRenderer; diff --git a/emulator/opengl/host/libs/Translator/GLcommon/objectNameManager.cpp b/emulator/opengl/host/libs/Translator/GLcommon/objectNameManager.cpp index cfea855..3612211 100644 --- a/emulator/opengl/host/libs/Translator/GLcommon/objectNameManager.cpp +++ b/emulator/opengl/host/libs/Translator/GLcommon/objectNameManager.cpp @@ -18,12 +18,11 @@  #include <GLcommon/GLEScontext.h> -NameSpace::NameSpace(NamedObjectType p_type, GlobalNameSpace *globalNameSpace) : +NameSpace::NameSpace(NamedObjectType p_type, +                     GlobalNameSpace *globalNameSpace) :      m_nextName(0),      m_type(p_type), -    m_globalNameSpace(globalNameSpace) -{ -} +    m_globalNameSpace(globalNameSpace) {}  NameSpace::~NameSpace()  { @@ -35,14 +34,16 @@ NameSpace::~NameSpace()  }  ObjectLocalName -NameSpace::genName(ObjectLocalName p_localName, bool genGlobal, bool genLocal) +NameSpace::genName(ObjectLocalName p_localName, +                   bool genGlobal, bool genLocal)  { -      ObjectLocalName localName = p_localName;      if (genLocal) {          do {              localName = ++m_nextName; -        } while( localName == 0 || m_localToGlobalMap.find(localName) != m_localToGlobalMap.end() ); +        } while(localName == 0 || +                m_localToGlobalMap.find(localName) != +                        m_localToGlobalMap.end() );      }      if (genGlobal) { @@ -114,15 +115,9 @@ NameSpace::replaceGlobalName(ObjectLocalName p_localName, unsigned int p_globalN  } -GlobalNameSpace::GlobalNameSpace() -{ -    mutex_init(&m_lock); -} +GlobalNameSpace::GlobalNameSpace() : m_lock() {} -GlobalNameSpace::~GlobalNameSpace() -{ -    mutex_destroy(&m_lock); -} +GlobalNameSpace::~GlobalNameSpace() {}  unsigned int   GlobalNameSpace::genName(NamedObjectType p_type) @@ -130,7 +125,7 @@ GlobalNameSpace::genName(NamedObjectType p_type)      if ( p_type >= NUM_OBJECT_TYPES ) return 0;      unsigned int name = 0; -    mutex_lock(&m_lock); +    emugl::Mutex::AutoLock _lock(m_lock);      switch (p_type) {      case VERTEXBUFFER:          GLEScontext::dispatcher().glGenBuffers(1,&name); @@ -148,7 +143,6 @@ GlobalNameSpace::genName(NamedObjectType p_type)      default:          name = 0;      } -    mutex_unlock(&m_lock);      return name;  } @@ -160,11 +154,8 @@ GlobalNameSpace::deleteName(NamedObjectType p_type, unsigned int p_name)  typedef std::pair<NamedObjectType, ObjectLocalName> ObjectIDPair;  typedef std::map<ObjectIDPair, ObjectDataPtr> ObjectDataMap; -ShareGroup::ShareGroup(GlobalNameSpace *globalNameSpace) -{ -    mutex_init(&m_lock); - -    for (int i=0; i<NUM_OBJECT_TYPES; i++) { +ShareGroup::ShareGroup(GlobalNameSpace *globalNameSpace) : m_lock() { +    for (int i=0; i < NUM_OBJECT_TYPES; i++) {          m_nameSpace[i] = new NameSpace((NamedObjectType)i, globalNameSpace);      } @@ -173,27 +164,24 @@ ShareGroup::ShareGroup(GlobalNameSpace *globalNameSpace)  ShareGroup::~ShareGroup()  { -    mutex_lock(&m_lock); +    emugl::Mutex::AutoLock _lock(m_lock);      for (int t = 0; t < NUM_OBJECT_TYPES; t++) {          delete m_nameSpace[t];      } -    ObjectDataMap *map = (ObjectDataMap *)m_objectsData; -    if (map) delete map; - -    mutex_unlock(&m_lock); -    mutex_destroy(&m_lock); +    delete (ObjectDataMap *)m_objectsData;  }  ObjectLocalName -ShareGroup::genName(NamedObjectType p_type, ObjectLocalName p_localName, bool genLocal) +ShareGroup::genName(NamedObjectType p_type, +                    ObjectLocalName p_localName, +                    bool genLocal)  {      if (p_type >= NUM_OBJECT_TYPES) return 0; -    mutex_lock(&m_lock); -    ObjectLocalName localName = m_nameSpace[p_type]->genName(p_localName,true,genLocal); -    mutex_unlock(&m_lock); - +    emugl::Mutex::AutoLock _lock(m_lock); +    ObjectLocalName localName = +            m_nameSpace[p_type]->genName(p_localName, true, genLocal);      return localName;  } @@ -202,35 +190,28 @@ ShareGroup::genGlobalName(NamedObjectType p_type)  {      if (p_type >= NUM_OBJECT_TYPES) return 0; -    mutex_lock(&m_lock); -    unsigned int name = m_nameSpace[p_type]->genGlobalName(); -    mutex_unlock(&m_lock); - -    return name; +    emugl::Mutex::AutoLock _lock(m_lock); +    return m_nameSpace[p_type]->genGlobalName();  }  unsigned int -ShareGroup::getGlobalName(NamedObjectType p_type, ObjectLocalName p_localName) +ShareGroup::getGlobalName(NamedObjectType p_type, +                          ObjectLocalName p_localName)  {      if (p_type >= NUM_OBJECT_TYPES) return 0; -    mutex_lock(&m_lock); -    unsigned int globalName = m_nameSpace[p_type]->getGlobalName(p_localName); -    mutex_unlock(&m_lock); - -    return globalName; +    emugl::Mutex::AutoLock _lock(m_lock); +    return m_nameSpace[p_type]->getGlobalName(p_localName);  }  ObjectLocalName -ShareGroup::getLocalName(NamedObjectType p_type, unsigned int p_globalName) +ShareGroup::getLocalName(NamedObjectType p_type, +                         unsigned int p_globalName)  {      if (p_type >= NUM_OBJECT_TYPES) return 0; -    mutex_lock(&m_lock); -    ObjectLocalName localName = m_nameSpace[p_type]->getLocalName(p_globalName); -    mutex_unlock(&m_lock); - -    return localName; +    emugl::Mutex::AutoLock _lock(m_lock); +    return m_nameSpace[p_type]->getLocalName(p_globalName);  }  void @@ -238,13 +219,12 @@ ShareGroup::deleteName(NamedObjectType p_type, ObjectLocalName p_localName)  {      if (p_type >= NUM_OBJECT_TYPES) return; -    mutex_lock(&m_lock); +    emugl::Mutex::AutoLock _lock(m_lock);      m_nameSpace[p_type]->deleteName(p_localName);      ObjectDataMap *map = (ObjectDataMap *)m_objectsData;      if (map) {          map->erase( ObjectIDPair(p_type, p_localName) );      } -    mutex_unlock(&m_lock);  }  bool @@ -252,29 +232,29 @@ ShareGroup::isObject(NamedObjectType p_type, ObjectLocalName p_localName)  {      if (p_type >= NUM_OBJECT_TYPES) return 0; -    mutex_lock(&m_lock); -    bool exist = m_nameSpace[p_type]->isObject(p_localName); -    mutex_unlock(&m_lock); - -    return exist; +    emugl::Mutex::AutoLock _lock(m_lock); +    return m_nameSpace[p_type]->isObject(p_localName);  }  void -ShareGroup::replaceGlobalName(NamedObjectType p_type, ObjectLocalName p_localName, unsigned int p_globalName) +ShareGroup::replaceGlobalName(NamedObjectType p_type, +                              ObjectLocalName p_localName, +                              unsigned int p_globalName)  {      if (p_type >= NUM_OBJECT_TYPES) return; -    mutex_lock(&m_lock); +    emugl::Mutex::AutoLock _lock(m_lock);      m_nameSpace[p_type]->replaceGlobalName(p_localName, p_globalName); -    mutex_unlock(&m_lock);  }  void -ShareGroup::setObjectData(NamedObjectType p_type, ObjectLocalName p_localName, ObjectDataPtr data) +ShareGroup::setObjectData(NamedObjectType p_type, +                          ObjectLocalName p_localName, +                          ObjectDataPtr data)  {      if (p_type >= NUM_OBJECT_TYPES) return; -    mutex_lock(&m_lock); +    emugl::Mutex::AutoLock _lock(m_lock);      ObjectDataMap *map = (ObjectDataMap *)m_objectsData;      if (!map) { @@ -284,45 +264,36 @@ ShareGroup::setObjectData(NamedObjectType p_type, ObjectLocalName p_localName, O      ObjectIDPair id( p_type, p_localName );      map->insert( std::pair<ObjectIDPair, ObjectDataPtr>(id, data) ); - -    mutex_unlock(&m_lock);  }  ObjectDataPtr -ShareGroup::getObjectData(NamedObjectType p_type, ObjectLocalName p_localName) +ShareGroup::getObjectData(NamedObjectType p_type, +                          ObjectLocalName p_localName)  {      ObjectDataPtr ret;      if (p_type >= NUM_OBJECT_TYPES) return ret; -    mutex_lock(&m_lock); +    emugl::Mutex::AutoLock _lock(m_lock);      ObjectDataMap *map = (ObjectDataMap *)m_objectsData;      if (map) { -        ObjectDataMap::iterator i = map->find( ObjectIDPair(p_type, p_localName) ); +        ObjectDataMap::iterator i = +                map->find( ObjectIDPair(p_type, p_localName) );          if (i != map->end()) ret = (*i).second;      } - -    mutex_unlock(&m_lock); -      return ret;  }  ObjectNameManager::ObjectNameManager(GlobalNameSpace *globalNameSpace) : -    m_globalNameSpace(globalNameSpace) -{ -    mutex_init(&m_lock); -} +    m_lock(), m_globalNameSpace(globalNameSpace) {} -ObjectNameManager::~ObjectNameManager() -{ -    mutex_destroy(&m_lock); -} +ObjectNameManager::~ObjectNameManager() {}  ShareGroupPtr  ObjectNameManager::createShareGroup(void *p_groupName)  { -    mutex_lock(&m_lock); +    emugl::Mutex::AutoLock _lock(m_lock);      ShareGroupPtr shareGroupReturn; @@ -334,19 +305,19 @@ ObjectNameManager::createShareGroup(void *p_groupName)          //          // Group does not exist, create new group          // -        shareGroupReturn = ShareGroupPtr( new ShareGroup(m_globalNameSpace) ); -        m_groups.insert( std::pair<void *, ShareGroupPtr>(p_groupName, shareGroupReturn) ); +        shareGroupReturn = ShareGroupPtr(new ShareGroup(m_globalNameSpace)); +        m_groups.insert( +                std::pair<void*, ShareGroupPtr>( +                        p_groupName, shareGroupReturn));      } -    mutex_unlock(&m_lock); -      return shareGroupReturn;  }  ShareGroupPtr  ObjectNameManager::getShareGroup(void *p_groupName)  { -    mutex_lock(&m_lock); +    emugl::Mutex::AutoLock _lock(m_lock);      ShareGroupPtr shareGroupReturn(NULL); @@ -354,58 +325,45 @@ ObjectNameManager::getShareGroup(void *p_groupName)      if (s != m_groups.end()) {          shareGroupReturn = (*s).second;      } -    mutex_unlock(&m_lock);      return shareGroupReturn;  }  ShareGroupPtr -ObjectNameManager::attachShareGroup(void *p_groupName, void *p_existingGroupName) +ObjectNameManager::attachShareGroup(void *p_groupName, +                                    void *p_existingGroupName)  { -    mutex_lock(&m_lock); - -    ShareGroupPtr shareGroupReturn; +    emugl::Mutex::AutoLock _lock(m_lock);      ShareGroupsMap::iterator s( m_groups.find(p_existingGroupName) );      if (s == m_groups.end()) {          // ShareGroup did not found !!! -        mutex_unlock(&m_lock);          return ShareGroupPtr(NULL);      } -    shareGroupReturn = (*s).second; - -    if (m_groups.find(p_groupName) == m_groups.end()) -    { -        m_groups.insert( std::pair<void *, ShareGroupPtr>(p_groupName, shareGroupReturn) ); +    ShareGroupPtr shareGroupReturn((*s).second); +    if (m_groups.find(p_groupName) == m_groups.end()) { +        m_groups.insert( +                std::pair<void*, ShareGroupPtr>( +                        p_groupName, shareGroupReturn));      } - -    mutex_unlock(&m_lock); -      return shareGroupReturn;  }  void  ObjectNameManager::deleteShareGroup(void *p_groupName)  { -    mutex_lock(&m_lock); +    emugl::Mutex::AutoLock _lock(m_lock);      ShareGroupsMap::iterator s( m_groups.find(p_groupName) );      if (s != m_groups.end()) {          m_groups.erase(s);      } - -    mutex_unlock(&m_lock);  }  void *ObjectNameManager::getGlobalContext()  { -    void *ret = NULL; - -    mutex_lock(&m_lock); -    if (m_groups.size() > 0) ret = (*m_groups.begin()).first; -    mutex_unlock(&m_lock); - -    return ret; +    emugl::Mutex::AutoLock _lock(m_lock); +    return (m_groups.size() > 0) ? (*m_groups.begin()).first : NULL;  } diff --git a/emulator/opengl/host/libs/Translator/include/GLcommon/GLDispatch.h b/emulator/opengl/host/libs/Translator/include/GLcommon/GLDispatch.h index de7d563..18a989c 100644 --- a/emulator/opengl/host/libs/Translator/include/GLcommon/GLDispatch.h +++ b/emulator/opengl/host/libs/Translator/include/GLcommon/GLDispatch.h @@ -18,7 +18,7 @@  #include <GLES/gl.h>  #include <GLES2/gl2.h> -#include <utils/threads.h> +#include "emugl/common/mutex.h"  #include "gldefs.h"  #include "GLutils.h" @@ -260,8 +260,8 @@ public:      static void (GL_APIENTRY *glShaderSource)(GLuint shader, GLsizei count, const GLchar** string, const GLint* length);  private: -    bool                    m_isLoaded; -    static android::Mutex   s_lock; +    bool                  m_isLoaded; +    static emugl::Mutex   s_lock;  };  #endif diff --git a/emulator/opengl/host/libs/Translator/include/GLcommon/GLEScontext.h b/emulator/opengl/host/libs/Translator/include/GLcommon/GLEScontext.h index 20509fc..5aed0ad 100644 --- a/emulator/opengl/host/libs/Translator/include/GLcommon/GLEScontext.h +++ b/emulator/opengl/host/libs/Translator/include/GLcommon/GLEScontext.h @@ -20,7 +20,7 @@  #include "GLDispatch.h"  #include "GLESpointer.h"  #include "objectNameManager.h" -#include <utils/threads.h> +#include "emugl/common/mutex.h"  #include <string>  typedef std::map<GLenum,GLESpointer*>  ArraysMap; @@ -187,7 +187,7 @@ protected:      void initCapsLocked(const GLubyte * extensionString);      virtual void initExtensionString() =0; -    static android::Mutex s_lock; +    static emugl::Mutex   s_lock;      static GLDispatch     s_glDispatch;      bool                  m_initialized;      unsigned int          m_activeTexture; diff --git a/emulator/opengl/host/libs/Translator/include/GLcommon/objectNameManager.h b/emulator/opengl/host/libs/Translator/include/GLcommon/objectNameManager.h index 0a00644..4d4d038 100644 --- a/emulator/opengl/host/libs/Translator/include/GLcommon/objectNameManager.h +++ b/emulator/opengl/host/libs/Translator/include/GLcommon/objectNameManager.h @@ -16,8 +16,8 @@  #ifndef _OBJECT_NAME_MANAGER_H  #define _OBJECT_NAME_MANAGER_H -#include <cutils/threads.h>  #include <map> +#include "emugl/common/mutex.h"  #include "emugl/common/smart_ptr.h"  enum NamedObjectType { @@ -129,7 +129,7 @@ public:      void deleteName(NamedObjectType p_type, unsigned int p_name);  private: -    mutex_t m_lock; +    emugl::Mutex m_lock;  };  // @@ -204,7 +204,7 @@ private:      ~ShareGroup();  private: -    mutex_t m_lock; +    emugl::Mutex m_lock;      NameSpace *m_nameSpace[NUM_OBJECT_TYPES];      void *m_objectsData;  }; @@ -262,7 +262,7 @@ public:  private:      ShareGroupsMap m_groups; -    mutex_t m_lock; +    emugl::Mutex m_lock;      GlobalNameSpace *m_globalNameSpace;  }; diff --git a/emulator/opengl/host/libs/libOpenglRender/FrameBuffer.cpp b/emulator/opengl/host/libs/libOpenglRender/FrameBuffer.cpp index cfadf12..238f2c9 100644 --- a/emulator/opengl/host/libs/libOpenglRender/FrameBuffer.cpp +++ b/emulator/opengl/host/libs/libOpenglRender/FrameBuffer.cpp @@ -393,7 +393,7 @@ FrameBuffer::~FrameBuffer()  void FrameBuffer::setPostCallback(OnPostFn onPost, void* onPostContext)  { -    android::Mutex::Autolock mutex(m_lock); +    emugl::Mutex::AutoLock mutex(m_lock);      m_onPost = onPost;      m_onPostContext = onPostContext;      if (m_onPost && !m_fbImage) { @@ -490,7 +490,7 @@ HandleType FrameBuffer::genHandle()  HandleType FrameBuffer::createColorBuffer(int p_width, int p_height,                                            GLenum p_internalFormat)  { -    android::Mutex::Autolock mutex(m_lock); +    emugl::Mutex::AutoLock mutex(m_lock);      HandleType ret = 0;      ColorBufferPtr cb( ColorBuffer::create(p_width, p_height, p_internalFormat) ); @@ -505,7 +505,7 @@ HandleType FrameBuffer::createColorBuffer(int p_width, int p_height,  HandleType FrameBuffer::createRenderContext(int p_config, HandleType p_share,                                              bool p_isGL2)  { -    android::Mutex::Autolock mutex(m_lock); +    emugl::Mutex::AutoLock mutex(m_lock);      HandleType ret = 0;      RenderContextPtr share(NULL); @@ -527,7 +527,7 @@ HandleType FrameBuffer::createRenderContext(int p_config, HandleType p_share,  HandleType FrameBuffer::createWindowSurface(int p_config, int p_width, int p_height)  { -    android::Mutex::Autolock mutex(m_lock); +    emugl::Mutex::AutoLock mutex(m_lock);      HandleType ret = 0;      WindowSurfacePtr win( WindowSurface::create(p_config, p_width, p_height) ); @@ -541,19 +541,19 @@ HandleType FrameBuffer::createWindowSurface(int p_config, int p_width, int p_hei  void FrameBuffer::DestroyRenderContext(HandleType p_context)  { -    android::Mutex::Autolock mutex(m_lock); +    emugl::Mutex::AutoLock mutex(m_lock);      m_contexts.erase(p_context);  }  void FrameBuffer::DestroyWindowSurface(HandleType p_surface)  { -    android::Mutex::Autolock mutex(m_lock); +    emugl::Mutex::AutoLock mutex(m_lock);      m_windows.erase(p_surface);  }  void FrameBuffer::openColorBuffer(HandleType p_colorbuffer)  { -    android::Mutex::Autolock mutex(m_lock); +    emugl::Mutex::AutoLock mutex(m_lock);      ColorBufferMap::iterator c(m_colorbuffers.find(p_colorbuffer));      if (c == m_colorbuffers.end()) {          // bad colorbuffer handle @@ -564,7 +564,7 @@ void FrameBuffer::openColorBuffer(HandleType p_colorbuffer)  void FrameBuffer::closeColorBuffer(HandleType p_colorbuffer)  { -    android::Mutex::Autolock mutex(m_lock); +    emugl::Mutex::AutoLock mutex(m_lock);      ColorBufferMap::iterator c(m_colorbuffers.find(p_colorbuffer));      if (c == m_colorbuffers.end()) {          // bad colorbuffer handle @@ -577,7 +577,7 @@ void FrameBuffer::closeColorBuffer(HandleType p_colorbuffer)  bool FrameBuffer::flushWindowSurfaceColorBuffer(HandleType p_surface)  { -    android::Mutex::Autolock mutex(m_lock); +    emugl::Mutex::AutoLock mutex(m_lock);      WindowSurfaceMap::iterator w( m_windows.find(p_surface) );      if (w == m_windows.end()) { @@ -591,7 +591,7 @@ bool FrameBuffer::flushWindowSurfaceColorBuffer(HandleType p_surface)  bool FrameBuffer::setWindowSurfaceColorBuffer(HandleType p_surface,                                                HandleType p_colorbuffer)  { -    android::Mutex::Autolock mutex(m_lock); +    emugl::Mutex::AutoLock mutex(m_lock);      WindowSurfaceMap::iterator w( m_windows.find(p_surface) );      if (w == m_windows.end()) { @@ -614,7 +614,7 @@ bool FrameBuffer::updateColorBuffer(HandleType p_colorbuffer,                                      int x, int y, int width, int height,                                      GLenum format, GLenum type, void *pixels)  { -    android::Mutex::Autolock mutex(m_lock); +    emugl::Mutex::AutoLock mutex(m_lock);      ColorBufferMap::iterator c( m_colorbuffers.find(p_colorbuffer) );      if (c == m_colorbuffers.end()) { @@ -629,7 +629,7 @@ bool FrameBuffer::updateColorBuffer(HandleType p_colorbuffer,  bool FrameBuffer::bindColorBufferToTexture(HandleType p_colorbuffer)  { -    android::Mutex::Autolock mutex(m_lock); +    emugl::Mutex::AutoLock mutex(m_lock);      ColorBufferMap::iterator c( m_colorbuffers.find(p_colorbuffer) );      if (c == m_colorbuffers.end()) { @@ -642,7 +642,7 @@ bool FrameBuffer::bindColorBufferToTexture(HandleType p_colorbuffer)  bool FrameBuffer::bindColorBufferToRenderbuffer(HandleType p_colorbuffer)  { -    android::Mutex::Autolock mutex(m_lock); +    emugl::Mutex::AutoLock mutex(m_lock);      ColorBufferMap::iterator c( m_colorbuffers.find(p_colorbuffer) );      if (c == m_colorbuffers.end()) { @@ -657,7 +657,7 @@ bool FrameBuffer::bindContext(HandleType p_context,                                HandleType p_drawSurface,                                HandleType p_readSurface)  { -    android::Mutex::Autolock mutex(m_lock); +    emugl::Mutex::AutoLock mutex(m_lock);      WindowSurfacePtr draw(NULL), read(NULL);      RenderContextPtr ctx(NULL); diff --git a/emulator/opengl/host/libs/libOpenglRender/FrameBuffer.h b/emulator/opengl/host/libs/libOpenglRender/FrameBuffer.h index de0b71c..5b03624 100644 --- a/emulator/opengl/host/libs/libOpenglRender/FrameBuffer.h +++ b/emulator/opengl/host/libs/libOpenglRender/FrameBuffer.h @@ -20,7 +20,8 @@  #include "ColorBuffer.h"  #include "RenderContext.h"  #include "WindowSurface.h" -#include <utils/threads.h> +#include "emugl/common/mutex.h" +  #include <map>  #include <EGL/egl.h>  #include <stdint.h> @@ -111,7 +112,7 @@ private:      int m_y;      int m_width;      int m_height; -    android::Mutex m_lock; +    emugl::Mutex m_lock;      FBNativeWindowType m_nativeWindow;      FrameBufferCaps m_caps;      EGLDisplay m_eglDisplay; diff --git a/emulator/opengl/shared/OpenglCodecCommon/GLSharedGroup.cpp b/emulator/opengl/shared/OpenglCodecCommon/GLSharedGroup.cpp index c7da37a..a054562 100644 --- a/emulator/opengl/shared/OpenglCodecCommon/GLSharedGroup.cpp +++ b/emulator/opengl/shared/OpenglCodecCommon/GLSharedGroup.cpp @@ -242,19 +242,19 @@ GLSharedGroup::~GLSharedGroup()  BufferData * GLSharedGroup::getBufferData(GLuint bufferId)  { -    android::AutoMutex _lock(m_lock); +    emugl::Mutex::AutoLock _lock(m_lock);      return m_buffers.valueFor(bufferId);  }  void GLSharedGroup::addBufferData(GLuint bufferId, GLsizeiptr size, void * data)  { -    android::AutoMutex _lock(m_lock); +    emugl::Mutex::AutoLock _lock(m_lock);      m_buffers.add(bufferId, new BufferData(size, data));  }  void GLSharedGroup::updateBufferData(GLuint bufferId, GLsizeiptr size, void * data)  { -    android::AutoMutex _lock(m_lock); +    emugl::Mutex::AutoLock _lock(m_lock);      ssize_t idx = m_buffers.indexOfKey(bufferId);      if (idx >= 0) {          delete m_buffers.valueAt(idx); @@ -266,7 +266,7 @@ void GLSharedGroup::updateBufferData(GLuint bufferId, GLsizeiptr size, void * da  GLenum GLSharedGroup::subUpdateBufferData(GLuint bufferId, GLintptr offset, GLsizeiptr size, void * data)  { -    android::AutoMutex _lock(m_lock); +    emugl::Mutex::AutoLock _lock(m_lock);      BufferData * buf = m_buffers.valueFor(bufferId);      if ((!buf) || (buf->m_size < offset+size) || (offset < 0) || (size<0)) return GL_INVALID_VALUE; @@ -277,7 +277,7 @@ GLenum GLSharedGroup::subUpdateBufferData(GLuint bufferId, GLintptr offset, GLsi  void GLSharedGroup::deleteBufferData(GLuint bufferId)  { -    android::AutoMutex _lock(m_lock); +    emugl::Mutex::AutoLock _lock(m_lock);      ssize_t idx = m_buffers.indexOfKey(bufferId);      if (idx >= 0) {          delete m_buffers.valueAt(idx); @@ -287,7 +287,7 @@ void GLSharedGroup::deleteBufferData(GLuint bufferId)  void GLSharedGroup::addProgramData(GLuint program)  { -    android::AutoMutex _lock(m_lock); +    emugl::Mutex::AutoLock _lock(m_lock);      ProgramData *pData = m_programs.valueFor(program);      if (pData)      { @@ -300,7 +300,7 @@ void GLSharedGroup::addProgramData(GLuint program)  void GLSharedGroup::initProgramData(GLuint program, GLuint numIndexes)  { -    android::AutoMutex _lock(m_lock); +    emugl::Mutex::AutoLock _lock(m_lock);      ProgramData *pData = m_programs.valueFor(program);      if (pData)      { @@ -310,7 +310,7 @@ void GLSharedGroup::initProgramData(GLuint program, GLuint numIndexes)  bool GLSharedGroup::isProgramInitialized(GLuint program)  { -    android::AutoMutex _lock(m_lock); +    emugl::Mutex::AutoLock _lock(m_lock);      ProgramData* pData = m_programs.valueFor(program);      if (pData)      { @@ -321,7 +321,7 @@ bool GLSharedGroup::isProgramInitialized(GLuint program)  void GLSharedGroup::deleteProgramData(GLuint program)  { -    android::AutoMutex _lock(m_lock); +    emugl::Mutex::AutoLock _lock(m_lock);      ProgramData *pData = m_programs.valueFor(program);      if (pData)          delete pData; @@ -330,7 +330,7 @@ void GLSharedGroup::deleteProgramData(GLuint program)  void GLSharedGroup::attachShader(GLuint program, GLuint shader)  { -    android::AutoMutex _lock(m_lock); +    emugl::Mutex::AutoLock _lock(m_lock);      ProgramData* programData = m_programs.valueFor(program);      ssize_t idx = m_shaders.indexOfKey(shader);      if (programData && idx >= 0) { @@ -342,7 +342,7 @@ void GLSharedGroup::attachShader(GLuint program, GLuint shader)  void GLSharedGroup::detachShader(GLuint program, GLuint shader)  { -    android::AutoMutex _lock(m_lock); +    emugl::Mutex::AutoLock _lock(m_lock);      ProgramData* programData = m_programs.valueFor(program);      ssize_t idx = m_shaders.indexOfKey(shader);      if (programData && idx >= 0) { @@ -354,7 +354,7 @@ void GLSharedGroup::detachShader(GLuint program, GLuint shader)  void GLSharedGroup::setProgramIndexInfo(GLuint program, GLuint index, GLint base, GLint size, GLenum type, const char* name)  { -    android::AutoMutex _lock(m_lock); +    emugl::Mutex::AutoLock _lock(m_lock);      ProgramData* pData = m_programs.valueFor(program);      if (pData)      { @@ -382,7 +382,7 @@ void GLSharedGroup::setProgramIndexInfo(GLuint program, GLuint index, GLint base  GLenum GLSharedGroup::getProgramUniformType(GLuint program, GLint location)  { -    android::AutoMutex _lock(m_lock); +    emugl::Mutex::AutoLock _lock(m_lock);      ProgramData* pData = m_programs.valueFor(program);      GLenum type=0;      if (pData) @@ -394,21 +394,21 @@ GLenum GLSharedGroup::getProgramUniformType(GLuint program, GLint location)  bool  GLSharedGroup::isProgram(GLuint program)  { -    android::AutoMutex _lock(m_lock); +    emugl::Mutex::AutoLock _lock(m_lock);      ProgramData* pData = m_programs.valueFor(program);      return (pData!=NULL);  }  void GLSharedGroup::setupLocationShiftWAR(GLuint program)  { -    android::AutoMutex _lock(m_lock); +    emugl::Mutex::AutoLock _lock(m_lock);      ProgramData* pData = m_programs.valueFor(program);      if (pData) pData->setupLocationShiftWAR();  }  GLint GLSharedGroup::locationWARHostToApp(GLuint program, GLint hostLoc, GLint arrIndex)  { -    android::AutoMutex _lock(m_lock); +    emugl::Mutex::AutoLock _lock(m_lock);      ProgramData* pData = m_programs.valueFor(program);      if (pData) return pData->locationWARHostToApp(hostLoc, arrIndex);      else return hostLoc; @@ -416,7 +416,7 @@ GLint GLSharedGroup::locationWARHostToApp(GLuint program, GLint hostLoc, GLint a  GLint GLSharedGroup::locationWARAppToHost(GLuint program, GLint appLoc)  { -    android::AutoMutex _lock(m_lock); +    emugl::Mutex::AutoLock _lock(m_lock);      ProgramData* pData = m_programs.valueFor(program);      if (pData) return pData->locationWARAppToHost(appLoc);      else return appLoc; @@ -424,7 +424,7 @@ GLint GLSharedGroup::locationWARAppToHost(GLuint program, GLint appLoc)  bool GLSharedGroup::needUniformLocationWAR(GLuint program)  { -    android::AutoMutex _lock(m_lock); +    emugl::Mutex::AutoLock _lock(m_lock);      ProgramData* pData = m_programs.valueFor(program);      if (pData) return pData->needUniformLocationWAR();      return false; @@ -432,21 +432,21 @@ bool GLSharedGroup::needUniformLocationWAR(GLuint program)  GLint GLSharedGroup::getNextSamplerUniform(GLuint program, GLint index, GLint* val, GLenum* target) const  { -    android::AutoMutex _lock(m_lock); +    emugl::Mutex::AutoLock _lock(m_lock);      ProgramData* pData = m_programs.valueFor(program);      return pData ? pData->getNextSamplerUniform(index, val, target) : -1;  }  bool GLSharedGroup::setSamplerUniform(GLuint program, GLint appLoc, GLint val, GLenum* target)  { -    android::AutoMutex _lock(m_lock); +    emugl::Mutex::AutoLock _lock(m_lock);      ProgramData* pData = m_programs.valueFor(program);      return pData ? pData->setSamplerUniform(appLoc, val, target) : false;  }  bool GLSharedGroup::addShaderData(GLuint shader)  { -    android::AutoMutex _lock(m_lock); +    emugl::Mutex::AutoLock _lock(m_lock);      ShaderData* data = new ShaderData;      if (data) {          if (m_shaders.add(shader, data) < 0) { @@ -460,13 +460,13 @@ bool GLSharedGroup::addShaderData(GLuint shader)  ShaderData* GLSharedGroup::getShaderData(GLuint shader)  { -    android::AutoMutex _lock(m_lock); +    emugl::Mutex::AutoLock _lock(m_lock);      return m_shaders.valueFor(shader);  }  void GLSharedGroup::unrefShaderData(GLuint shader)  { -    android::AutoMutex _lock(m_lock); +    emugl::Mutex::AutoLock _lock(m_lock);      ssize_t idx = m_shaders.indexOfKey(shader);      if (idx >= 0) {          unrefShaderDataLocked(idx); diff --git a/emulator/opengl/shared/OpenglCodecCommon/GLSharedGroup.h b/emulator/opengl/shared/OpenglCodecCommon/GLSharedGroup.h index e7341dc..02278a2 100644 --- a/emulator/opengl/shared/OpenglCodecCommon/GLSharedGroup.h +++ b/emulator/opengl/shared/OpenglCodecCommon/GLSharedGroup.h @@ -33,8 +33,8 @@  #include <utils/KeyedVector.h>  #include <utils/List.h>  #include <utils/String8.h> -#include <utils/threads.h>  #include "FixedBuffer.h" +#include "emugl/common/mutex.h"  #include "emugl/common/smart_ptr.h"  struct BufferData { @@ -102,7 +102,7 @@ private:      android::DefaultKeyedVector<GLuint, BufferData*> m_buffers;      android::DefaultKeyedVector<GLuint, ProgramData*> m_programs;      android::DefaultKeyedVector<GLuint, ShaderData*> m_shaders; -    mutable android::Mutex m_lock; +    mutable emugl::Mutex m_lock;      void refShaderDataLocked(ssize_t shaderIdx);      void unrefShaderDataLocked(ssize_t shaderIdx); diff --git a/emulator/opengl/shared/emugl/common/Android.mk b/emulator/opengl/shared/emugl/common/Android.mk index 5c444fd..ae1c213 100644 --- a/emulator/opengl/shared/emugl/common/Android.mk +++ b/emulator/opengl/shared/emugl/common/Android.mk @@ -19,11 +19,11 @@ LOCAL_SRC_FILES := $(host_commonSources)  $(call emugl-export,CFLAGS,-m64)  $(call emugl-end-module) -  ### emugl_common_unittests ##############################################  host_commonSources := \ -    smart_ptr_unittest.cpp +    mutex_unittest.cpp \ +    smart_ptr_unittest.cpp \  $(call emugl-begin-host-executable,emugl_common_host_unittests)  LOCAL_SRC_FILES := $(host_commonSources) diff --git a/emulator/opengl/shared/emugl/common/mutex.h b/emulator/opengl/shared/emugl/common/mutex.h new file mode 100644 index 0000000..c6cdcf2 --- /dev/null +++ b/emulator/opengl/shared/emugl/common/mutex.h @@ -0,0 +1,92 @@ +// Copyright (C) 2014 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. + +#ifndef EMUGL_MUTEX_H +#define EMUGL_MUTEX_H + +#ifdef _WIN32 +#  define WIN32_LEAN_AND_MEAN 1 +#  include <windows.h> +#else +#  include <pthread.h> +#endif + +namespace emugl { + +// Simple wrapper class for mutexes. +class Mutex { +public: +    // Constructor. +    Mutex() { +#ifdef _WIN32 +        ::InitializeCriticalSection(&mLock); +#else +        ::pthread_mutex_init(&mLock, NULL); +#endif +    } + +    // Destructor. +    ~Mutex() { +#ifdef _WIN32 +        ::DeleteCriticalSection(&mLock); +#else +        ::pthread_mutex_destroy(&mLock); +#endif +    } + +    // Acquire the mutex. +    void lock() { +#ifdef _WIN32 +      ::EnterCriticalSection(&mLock); +#else +      ::pthread_mutex_lock(&mLock); +#endif +    } + +    // Release the mutex. +    void unlock() { +#ifdef _WIN32 +       ::LeaveCriticalSection(&mLock); +#else +       ::pthread_mutex_unlock(&mLock); +#endif +    } + +    // Helper class to lock / unlock a mutex automatically on scope +    // entry and exit. +    class AutoLock { +    public: +        AutoLock(Mutex& mutex) : mMutex(&mutex) { +            mMutex->lock(); +        } + +        ~AutoLock() { +            mMutex->unlock(); +        } +    private: +        Mutex* mMutex; +    }; + +private: +#ifdef _WIN32 +    CRITICAL_SECTION mLock; +#else +    pthread_mutex_t mLock; +#endif + +}; + +}  // namespace emugl + +#endif  // EMUGL_MUTEX_H diff --git a/emulator/opengl/shared/emugl/common/mutex_unittest.cpp b/emulator/opengl/shared/emugl/common/mutex_unittest.cpp new file mode 100644 index 0000000..e952d75 --- /dev/null +++ b/emulator/opengl/shared/emugl/common/mutex_unittest.cpp @@ -0,0 +1,108 @@ +// Copyright (C) 2014 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 "emugl/common/mutex.h" + +#include "emugl/common/testing/test_thread.h" + +#include <gtest/gtest.h> + +namespace emugl { + +// Check that construction and destruction doesn't crash. +TEST(Mutex, ConstructionDestruction) { +    Mutex lock; +} + +// Check that a simple lock + unlock works. +TEST(Mutex, LockUnlock) { +    Mutex lock; +    lock.lock(); +    lock.unlock(); +} + +// Check that AutoLock compiles and doesn't crash. +TEST(Mutex, AutoLock) { +    Mutex mutex; +    Mutex::AutoLock lock(mutex); +} + +// Wrapper class for threads. Does not use emugl::Thread intentionally. +// Common data type used by the following tests below. +struct ThreadParams { +    ThreadParams() : mutex(), counter(0) {} + +    Mutex mutex; +    int counter; +}; + +// This thread function uses Mutex::lock/unlock to synchronize a counter +// increment operation. +static void* threadFunction(void* param) { +    ThreadParams* p = static_cast<ThreadParams*>(param); + +    p->mutex.lock(); +    p->counter++; +    p->mutex.unlock(); +    return NULL; +} + +TEST(Mutex, Synchronization) { +    const size_t kNumThreads = 2000; +    TestThread* threads[kNumThreads]; +    ThreadParams p; + +    // Create and launch all threads. +    for (size_t n = 0; n < kNumThreads; ++n) { +        threads[n] = new TestThread(threadFunction, &p); +    } + +    // Wait until their completion. +    for (size_t n = 0; n < kNumThreads; ++n) { +        threads[n]->join(); +        delete threads[n]; +    } + +    EXPECT_EQ(static_cast<int>(kNumThreads), p.counter); +} + +// This thread function uses a Mutex::AutoLock to protect the counter. +static void* threadAutoLockFunction(void* param) { +    ThreadParams* p = static_cast<ThreadParams*>(param); + +    Mutex::AutoLock lock(p->mutex); +    p->counter++; +    return NULL; +} + +TEST(Mutex, AutoLockSynchronization) { +    const size_t kNumThreads = 2000; +    TestThread* threads[kNumThreads]; +    ThreadParams p; + +    // Create and launch all threads. +    for (size_t n = 0; n < kNumThreads; ++n) { +        threads[n] = new TestThread(threadAutoLockFunction, &p); +    } + +    // Wait until their completion. +    for (size_t n = 0; n < kNumThreads; ++n) { +        threads[n]->join(); +        delete threads[n]; +    } + +    EXPECT_EQ(static_cast<int>(kNumThreads), p.counter); +} + +}  // namespace emugl diff --git a/emulator/opengl/shared/emugl/common/testing/test_thread.h b/emulator/opengl/shared/emugl/common/testing/test_thread.h new file mode 100644 index 0000000..2d758b3 --- /dev/null +++ b/emulator/opengl/shared/emugl/common/testing/test_thread.h @@ -0,0 +1,78 @@ +// Copyright (C) 2014 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. + +#ifndef EMUGL_COMMON_TESTING_TEST_THREAD_H +#define EMUGL_COMMON_TESTING_TEST_THREAD_H + +#ifdef _WIN32 +#  define WIN32_LEAN_AND_MEAN 1 +#  include <windows.h> +#else +#  include <pthread.h> +#endif + +namespace emugl { + +// Very basic platform thread wrapper that only uses a tiny stack. +// This shall only be used during unit testing, and allows test code +// to not depend on the implementation of emugl::Thread. +class TestThread { +public: +    // Main thread function type. +    typedef void* (ThreadFunction)(void* param); + +    // Constructor actually launches a new platform thread. +    TestThread(ThreadFunction* func, void* funcParam) { +#ifdef _WIN32 +        mThread = CreateThread(NULL, +                            16384, +                            (DWORD WINAPI (*)(void*))func, +                            funcParam, +                            NULL, +                            NULL); +#else +        pthread_attr_t attr; +        pthread_attr_init(&attr); +        pthread_attr_setstacksize(&attr, 16384); +        pthread_create(&mThread,  &attr, func, funcParam); +        pthread_attr_destroy(&attr); +#endif +    } + +    ~TestThread() { +#ifdef _WIN32 +        CloseHandle(mThread); +#endif +    } + +    void join() { +#ifdef _WIN32 +        WaitForSingleObject(mThread, INFINITE); +#else +        void* ret = NULL; +        pthread_join(mThread, &ret); +#endif +    } + +private: +#ifdef _WIN32 +    HANDLE mThread; +#else +    pthread_t mThread; +#endif +}; + +}  // namespace emugl + +#endif  // EMUGL_COMMON_TESTING_TEST_THREAD_H diff --git a/emulator/opengl/tests/ut_renderer/Renderer.cpp b/emulator/opengl/tests/ut_renderer/Renderer.cpp index 22afadb..1102014 100644 --- a/emulator/opengl/tests/ut_renderer/Renderer.cpp +++ b/emulator/opengl/tests/ut_renderer/Renderer.cpp @@ -56,7 +56,7 @@ Renderer::Renderer()  int Renderer::createSurface(RenderingThread *thread, const ClientHandle & handle)  { -    android::Mutex::Autolock(this->m_mutex); +    emugl::Mutex::AutoLock(this->m_mutex);      assert(m_surfaces.find(handle) == m_surfaces.end());      if (handle.handle == 0) { @@ -75,7 +75,7 @@ int Renderer::createSurface(RenderingThread *thread, const ClientHandle & handle  int Renderer::destroySurface(RenderingThread *thread, const ClientHandle &handle)  { -    android::Mutex::Autolock(this->m_mutex); +    emugl::Mutex::AutoLock(this->m_mutex);      SurfaceMap::iterator i = m_surfaces.find(handle);      if (i == m_surfaces.end()) { @@ -90,7 +90,7 @@ int Renderer::destroySurface(RenderingThread *thread, const ClientHandle &handle  int Renderer::createContext(RenderingThread *thread, const ClientHandle &handle, ClientHandle shareCtx, int version)  { -    android::Mutex::Autolock(this->m_mutex); +    emugl::Mutex::AutoLock(this->m_mutex);      assert(m_ctxs.find(handle) == m_ctxs.end());      RendererContext *shared = NULL; @@ -115,7 +115,7 @@ int Renderer::createContext(RenderingThread *thread, const ClientHandle &handle,  int Renderer::destroyContext(RenderingThread *thread, const ClientHandle &handle)  { -    android::Mutex::Autolock(this->m_mutex); +    emugl::Mutex::AutoLock(this->m_mutex);      ContextMap::iterator i = m_ctxs.find(handle);      if (i == m_ctxs.end()) { @@ -133,7 +133,7 @@ int Renderer::makeCurrent(RenderingThread *thread,                            const ClientHandle &readSurface,                            const ClientHandle & ctx)  { -    android::Mutex::Autolock(this->m_mutex); +    emugl::Mutex::AutoLock(this->m_mutex);      RendererContext *currentContext = thread->currentContext(); @@ -172,7 +172,7 @@ int Renderer::makeCurrent(RenderingThread *thread,  int Renderer::swapBuffers(RenderingThread *thread,                            const ClientHandle &surface)  { -    android::Mutex::Autolock(this->m_mutex); +    emugl::Mutex::AutoLock(this->m_mutex);      SurfaceMap::iterator s = m_surfaces.find(surface);      if (s == m_surfaces.end()) { diff --git a/emulator/opengl/tests/ut_renderer/Renderer.h b/emulator/opengl/tests/ut_renderer/Renderer.h index cdf10b6..81f4077 100644 --- a/emulator/opengl/tests/ut_renderer/Renderer.h +++ b/emulator/opengl/tests/ut_renderer/Renderer.h @@ -19,7 +19,7 @@  #include "RendererSurface.h"  #include "RendererContext.h"  #include "NativeWindowing.h" -#include <utils/threads.h> +#include "emugl/common/mutex.h"  class RenderingThread; @@ -57,6 +57,6 @@ private:      NativeWindowing *m_nw;      EGLDisplay m_dpy; -    android::Mutex m_mutex; // single global mutex for the renderer class; +    emugl::Mutex m_mutex; // single global mutex for the renderer class;  };  #endif | 
