Procházet zdrojové kódy

core: do not include windows.h in header files

Daniele Bartolini před 7 roky
rodič
revize
2f5d42e1f3
2 změnil soubory, kde provedl 48 přidání a 33 odebrání
  1. 40 0
      src/core/thread/atomic_int.cpp
  2. 8 33
      src/core/thread/atomic_int.h

+ 40 - 0
src/core/thread/atomic_int.cpp

@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2012-2018 Daniele Bartolini and individual contributors.
+ * License: https://github.com/dbartolini/crown/blob/master/LICENSE
+ */
+
+#include "core/platform.h"
+#include "core/thread/atomic_int.h"
+
+#if CROWN_PLATFORM_WINDOWS
+	#include <windows.h>
+#endif
+
+namespace crown
+{
+AtomicInt::AtomicInt(s32 val)
+{
+	store(val);
+}
+
+s32 AtomicInt::load()
+{
+#if CROWN_PLATFORM_POSIX && CROWN_COMPILER_GCC
+	__sync_fetch_and_add(&_val, 0);
+	return _val;
+#elif CROWN_PLATFORM_WINDOWS
+	InterlockedExchangeAdd((LONG*)&_val, (s32)0);
+	return _val;
+#endif
+}
+
+void AtomicInt::store(s32 val)
+{
+#if CROWN_PLATFORM_POSIX && CROWN_COMPILER_GCC
+	__sync_lock_test_and_set(&_val, val);
+#elif CROWN_PLATFORM_WINDOWS
+	InterlockedExchange((LONG*)&_val, val);
+#endif
+}
+
+} // namespace crown

+ 8 - 33
src/core/thread/atomic_int.h

@@ -5,12 +5,7 @@
 
 #pragma once
 
-#include "core/platform.h"
-
-#if CROWN_PLATFORM_WINDOWS
-	#include "core/types.h"
-	#include <windows.h>
-#endif
+#include "core/types.h"
 
 namespace crown
 {
@@ -19,36 +14,16 @@ namespace crown
 /// @ingroup Thread
 struct AtomicInt
 {
-#if CROWN_PLATFORM_POSIX && CROWN_COMPILER_GCC
-	mutable int _val;
-#elif CROWN_PLATFORM_WINDOWS
-	mutable LONG _val;
-#endif
+	s32 _val;
 
-	AtomicInt(int val)
-	{
-		store(val);
-	}
+	///
+	AtomicInt(s32 val);
 
-	int load() const
-	{
-#if CROWN_PLATFORM_POSIX && CROWN_COMPILER_GCC
-		__sync_fetch_and_add(&_val, 0);
-		return _val;
-#elif CROWN_PLATFORM_WINDOWS
-		InterlockedExchangeAdd(&_val, (s32)0);
-		return _val;
-#endif
-	}
+	///
+	s32 load();
 
-	void store(int val)
-	{
-#if CROWN_PLATFORM_POSIX && CROWN_COMPILER_GCC
-		__sync_lock_test_and_set(&_val, val);
-#elif CROWN_PLATFORM_WINDOWS
-		InterlockedExchange(&_val, val);
-#endif
-	}
+	///
+	void store(s32 val);
 };
 
 } // namespace crown