Fix Vulkan semaphore data race

Fixes a data race in VkSemaphoreExternalLinux.hpp caused by the static
counter variable not being atomic.

Confirmed to fix a TSAN error found in Dawn tests using SwiftShader.

Bug: chromium:454630430
Change-Id: I008351b1d749ed0c9611087741694a6dd47b0381
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/76648
Reviewed-by: Yuly Novikov <ynovikov@chromium.org>
Tested-by: Yuly Novikov <ynovikov@chromium.org>
Tested-by: Shahbaz Youssefi <syoussefi@google.com>
Commit-Queue: Shahbaz Youssefi <syoussefi@google.com>
Reviewed-by: Shahbaz Youssefi <syoussefi@google.com>
Kokoro-Result: kokoro <noreply+kokoro@google.com>
Presubmit-Ready: Yuly Novikov <ynovikov@chromium.org>
diff --git a/src/Vulkan/VkSemaphoreExternalLinux.hpp b/src/Vulkan/VkSemaphoreExternalLinux.hpp
index 3689ad9..6578fa0 100644
--- a/src/Vulkan/VkSemaphoreExternalLinux.hpp
+++ b/src/Vulkan/VkSemaphoreExternalLinux.hpp
@@ -18,6 +18,7 @@
 #include "System/Linux/MemFd.hpp"
 #include "System/Memory.hpp"
 
+#include <atomic>
 #include <errno.h>
 #include <pthread.h>
 #include <string.h>
@@ -142,7 +143,7 @@
 		const size_t size = sw::memoryPageSize();
 		// To be exportable, the PosixSemaphore must be stored in a shared
 		// memory region.
-		static int counter = 0;
+		static std::atomic<int> counter = 0;
 		char name[40];
 		snprintf(name, sizeof(name), "SwiftShader.Semaphore.%d", ++counter);
 		if(!memfd.allocate(name, size))