Move the code generation mutex to Reactor.

Generation of the routines for copying surfaces and blitting
were not protected by the same critical section as the renderer.

Change-Id: I10eb386bdeebb04abc999b3313dc2c3b52adc090
Reviewed-on: https://swiftshader-review.googlesource.com/2772
Tested-by: Greg Hartman <ghartman@google.com>
Reviewed-by: Greg Hartman <ghartman@google.com>
Reviewed-by: Nicolas Capens <capn@google.com>
diff --git a/src/Reactor/Nucleus.cpp b/src/Reactor/Nucleus.cpp
index 4a819cb..49ec859 100644
--- a/src/Reactor/Nucleus.cpp
+++ b/src/Reactor/Nucleus.cpp
@@ -66,6 +66,7 @@
 	LLVMContext *Nucleus::context = 0;
 	Module *Nucleus::module = 0;
 	llvm::Function *Nucleus::function = 0;
+	BackoffLock Nucleus::codegenMutex;
 
 	class Builder : public IRBuilder<>
 	{
@@ -73,6 +74,8 @@
 
 	Nucleus::Nucleus()
 	{
+		codegenMutex.lock();   // Reactor and LLVM are currently not thread safe
+
 		InitializeNativeTarget();
 		JITEmitDebugInfo = false;
 
@@ -129,6 +132,8 @@
 		routineManager = 0;
 		function = 0;
 		module = 0;
+
+		codegenMutex.unlock();
 	}
 
 	Routine *Nucleus::acquireRoutine(const wchar_t *name, bool runOptimizations)