VkSemaphore: Unlock/Lock the mutex outside the blocking_call.

marl::blocking_call() calls the passed function on another thread.
Attempting to unlock a mutex on a different thread that locked it is
illegal.

Also lock for destruction.

Bug: b/140421726
Change-Id: I87226176bc3a1a454d9c79a139f4d42e51f66814
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/43908
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Tested-by: Ben Clayton <bclayton@google.com>
Kokoro-Result: kokoro <noreply+kokoro@google.com>
diff --git a/src/Vulkan/VkSemaphore.cpp b/src/Vulkan/VkSemaphore.cpp
index 8daef84..df9f72c 100644
--- a/src/Vulkan/VkSemaphore.cpp
+++ b/src/Vulkan/VkSemaphore.cpp
@@ -141,11 +141,11 @@
 			// call, it is assumed that this is negligible
 			// compared with the actual semaphore wait()
 			// operation.
-			marl::blocking_call([ext, &lock]() {
-				lock.unlock();
+			lock.unlock();
+			marl::blocking_call([ext]() {
 				ext->wait();
-				lock.lock();
 			});
+			lock.lock();
 		}
 
 		// If the import was temporary, reset the semaphore to its previous state.
@@ -187,6 +187,7 @@
 
 void Semaphore::destroy(const VkAllocationCallbacks *pAllocator)
 {
+	std::unique_lock<std::mutex> lock(mutex);
 	while(tempExternal)
 	{
 		External *ext = tempExternal;