Fix GL resource access thread safety

Add resource manager lock, and ContextPtr to automatically take it

Affects: Everything, dEQP-EGL.functional.sharing.gles2.multithread.*
Bug: b/112184433
Change-Id: Ifdc5b18c738f92bbab08217f672a8ed6093e1672
Reviewed-on: https://swiftshader-review.googlesource.com/20388
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Tested-by: Chris Forbes <chrisforbes@google.com>
diff --git a/src/OpenGL/libGLESv2/main.cpp b/src/OpenGL/libGLESv2/main.cpp
index 0924a75..aaabcbd 100644
--- a/src/OpenGL/libGLESv2/main.cpp
+++ b/src/OpenGL/libGLESv2/main.cpp
@@ -75,7 +75,7 @@
 
 namespace es2
 {
-es2::Context *getContext()
+Context *getContextLocked()
 {
 	egl::Context *context = libEGL->clientGetCurrentContext();
 
@@ -88,17 +88,23 @@
 	return nullptr;
 }
 
+ContextPtr getContext()
+{
+	return ContextPtr{getContextLocked()};
+}
+
 Device *getDevice()
 {
-	Context *context = getContext();
+	Context *context = getContextLocked();
 
 	return context ? context->getDevice() : nullptr;
 }
 
 // Records an error code
+// Assumed to already hold the context lock for the current context
 void error(GLenum errorCode)
 {
-	es2::Context *context = es2::getContext();
+	es2::Context *context = es2::getContextLocked();
 
 	if(context)
 	{