Przeglądaj źródła

Added thread test.

Branimir Karadžić 11 lat temu
rodzic
commit
d8ef558932
4 zmienionych plików z 52 dodań i 1 usunięć
  1. 1 1
      include/bx/macros.h
  2. 8 0
      include/bx/readerwriter.h
  3. 5 0
      include/bx/thread.h
  4. 38 0
      tests/thread.cpp

+ 1 - 1
include/bx/macros.h

@@ -74,7 +74,7 @@
 // #define BX_STATIC_ASSERT(_condition, ...) static_assert(_condition, "" __VA_ARGS__)
 // #define BX_STATIC_ASSERT(_condition, ...) static_assert(_condition, "" __VA_ARGS__)
 #define BX_STATIC_ASSERT(_condition, ...) typedef char BX_CONCATENATE(BX_STATIC_ASSERT_, __LINE__)[1][(_condition)]
 #define BX_STATIC_ASSERT(_condition, ...) typedef char BX_CONCATENATE(BX_STATIC_ASSERT_, __LINE__)[1][(_condition)]
 
 
-#define BX_CACHE_LINE_ALIGN_MARKER() BX_ALIGN_STRUCT(BX_CACHE_LINE_SIZE, struct) {}
+#define BX_CACHE_LINE_ALIGN_MARKER() BX_ALIGN_STRUCT(BX_CACHE_LINE_SIZE, struct) BX_CONCATENATE(bx_cache_line_marker_compiler_stfu, __COUNTER__) {}
 #define BX_CACHE_LINE_ALIGN(_def) BX_CACHE_LINE_ALIGN_MARKER(); _def; BX_CACHE_LINE_ALIGN_MARKER()
 #define BX_CACHE_LINE_ALIGN(_def) BX_CACHE_LINE_ALIGN_MARKER(); _def; BX_CACHE_LINE_ALIGN_MARKER()
 
 
 #define BX_ALIGN_STRUCT_16(_struct) BX_ALIGN_STRUCT(16, _struct)
 #define BX_ALIGN_STRUCT_16(_struct) BX_ALIGN_STRUCT(16, _struct)

+ 8 - 0
include/bx/readerwriter.h

@@ -117,11 +117,19 @@ namespace bx
 		return result;
 		return result;
 	}
 	}
 
 
+	/// Skip _offset bytes forward.
 	inline int64_t skip(SeekerI* _seeker, int64_t _offset)
 	inline int64_t skip(SeekerI* _seeker, int64_t _offset)
 	{
 	{
 		return _seeker->seek(_offset, Whence::Current);
 		return _seeker->seek(_offset, Whence::Current);
 	}
 	}
 
 
+	/// Seek to any position in file.
+	inline int64_t seek(SeekerI* _seeker, int64_t _offset = 0, Whence::Enum _whence = Whence::Current)
+	{
+		return _seeker->seek(_offset, _whence);
+	}
+
+	/// Returns size of file.
 	inline int64_t getSize(SeekerI* _seeker)
 	inline int64_t getSize(SeekerI* _seeker)
 	{
 	{
 		int64_t offset = _seeker->seek();
 		int64_t offset = _seeker->seek();

+ 5 - 0
include/bx/thread.h

@@ -117,6 +117,11 @@ namespace bx
 			return m_running;
 			return m_running;
 		}
 		}
 
 
+		int32_t getExitCode() const
+		{
+			return m_exitCode;
+		}
+
 	private:
 	private:
 		int32_t entry()
 		int32_t entry()
 		{
 		{

+ 38 - 0
tests/thread.cpp

@@ -0,0 +1,38 @@
+/*
+ * Copyright 2010-2013 Branimir Karadzic. All rights reserved.
+ * License: http://www.opensource.org/licenses/BSD-2-Clause
+ */
+
+#include "test.h"
+#include <bx/thread.h>
+
+int32_t threadExit0(void*)
+{
+	return 0;
+}
+
+int32_t threadExit1(void*)
+{
+	return 1;
+}
+
+TEST(thread)
+{
+	bx::Thread th;
+
+	CHECK_EQUAL(th.isRunning(), false);
+
+	th.init(threadExit0);
+	CHECK_EQUAL(th.isRunning(), true);
+	th.shutdown();
+
+	CHECK_EQUAL(th.isRunning(), false);
+	CHECK_EQUAL(th.getExitCode(), 0);
+
+	th.init(threadExit1);
+	CHECK_EQUAL(th.isRunning(), true);
+	th.shutdown();
+
+	CHECK_EQUAL(th.isRunning(), false);
+	CHECK_EQUAL(th.getExitCode(), 1);
+}