summaryrefslogtreecommitdiff
path: root/source/libs/asura-lib-utils
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2019-03-27 09:07:54 +0800
committerchai <chaifix@163.com>2019-03-27 09:07:54 +0800
commit66c5fdc564dd892ed265132d6c1378dbe3cebcee (patch)
tree909848ed622b35c8653c961c9ebed8c574bb150e /source/libs/asura-lib-utils
parentd9041d6e12ded456c17622f7f2e7bbacb9e99b1a (diff)
*misc
Diffstat (limited to 'source/libs/asura-lib-utils')
-rw-r--r--source/libs/asura-lib-utils/io/binding/_file.cpp6
-rw-r--r--source/libs/asura-lib-utils/io/file.h3
-rw-r--r--source/libs/asura-lib-utils/io/file_data.h2
-rw-r--r--source/libs/asura-lib-utils/io/io_task.cpp0
-rw-r--r--source/libs/asura-lib-utils/io/io_task.h39
-rw-r--r--source/libs/asura-lib-utils/io/reloadable.h2
-rw-r--r--source/libs/asura-lib-utils/threading/coroutine.cpp0
-rw-r--r--source/libs/asura-lib-utils/threading/coroutine.h31
-rw-r--r--source/libs/asura-lib-utils/threading/mutex.cpp0
-rw-r--r--source/libs/asura-lib-utils/threading/mutex.h21
-rw-r--r--source/libs/asura-lib-utils/threading/thread.cpp14
-rw-r--r--source/libs/asura-lib-utils/threading/thread.h60
-rw-r--r--source/libs/asura-lib-utils/threading/thread_impl_posix.cpp0
-rw-r--r--source/libs/asura-lib-utils/threading/thread_impl_posix.h0
-rw-r--r--source/libs/asura-lib-utils/threading/thread_impl_sdl.cpp0
-rw-r--r--source/libs/asura-lib-utils/threading/thread_impl_sdl.h0
-rw-r--r--source/libs/asura-lib-utils/threading/thread_impl_std.cpp0
-rw-r--r--source/libs/asura-lib-utils/threading/thread_impl_std.h0
-rw-r--r--source/libs/asura-lib-utils/threading/thread_impl_win32.cpp0
-rw-r--r--source/libs/asura-lib-utils/threading/thread_impl_win32.h35
-rw-r--r--source/libs/asura-lib-utils/threading/thread_task.cpp0
-rw-r--r--source/libs/asura-lib-utils/threading/thread_task.h27
-rw-r--r--source/libs/asura-lib-utils/utils_config.h6
-rw-r--r--source/libs/asura-lib-utils/utils_module.cpp3
-rw-r--r--source/libs/asura-lib-utils/utils_module.h2
25 files changed, 247 insertions, 4 deletions
diff --git a/source/libs/asura-lib-utils/io/binding/_file.cpp b/source/libs/asura-lib-utils/io/binding/_file.cpp
index 0baffd5..0670379 100644
--- a/source/libs/asura-lib-utils/io/binding/_file.cpp
+++ b/source/libs/asura-lib-utils/io/binding/_file.cpp
@@ -32,8 +32,8 @@ namespace AsuraEngine
{
LUAX_REGISTER_ENUM(state, "EFileMode",
{ "CLOSED", FILE_MODE_CLOSED },
- { "READ", FILE_MODE_READ },
- { "WRITE", FILE_MODE_WRITE },
+ { "READ", FILE_MODE_READ },
+ { "WRITE", FILE_MODE_WRITE },
{ "APPEND", FILE_MODE_APPEND }
);
@@ -130,7 +130,7 @@ namespace AsuraEngine
return 1;
}
- // isWrite = file:Write(data buffer)
+ // isWrite = file:Write(data buffer[, size])
LUAX_IMPL_METHOD(File, _Write)
{
LUAX_PREPARE(L, File);
diff --git a/source/libs/asura-lib-utils/io/file.h b/source/libs/asura-lib-utils/io/file.h
index b09eaaa..4a6d38b 100644
--- a/source/libs/asura-lib-utils/io/file.h
+++ b/source/libs/asura-lib-utils/io/file.h
@@ -108,6 +108,9 @@ namespace AsuraEngine
BufferMode mBufferMode; ///< д뻺ģʽ
size_t mBufferSize; ///< д뻺С
+ LUAX_DECL_ENUM(FileMode);
+ LUAX_DECL_ENUM(BufferMode);
+
LUAX_DECL_METHOD(_New);
LUAX_DECL_METHOD(_Open);
LUAX_DECL_METHOD(_Close);
diff --git a/source/libs/asura-lib-utils/io/file_data.h b/source/libs/asura-lib-utils/io/file_data.h
index 106e068..9aa0e3b 100644
--- a/source/libs/asura-lib-utils/io/file_data.h
+++ b/source/libs/asura-lib-utils/io/file_data.h
@@ -56,10 +56,10 @@ namespace AsuraEngine
std::string mExtension; ///< չ
std::string mName; ///< ͺ׺ļ
+ LUAX_DECL_METHOD(_GetDataBuffer);
LUAX_DECL_METHOD(_GetFileName);
LUAX_DECL_METHOD(_GetExtension);
LUAX_DECL_METHOD(_GetName);
- LUAX_DECL_METHOD(_GetDataBuffer);
};
diff --git a/source/libs/asura-lib-utils/io/io_task.cpp b/source/libs/asura-lib-utils/io/io_task.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/source/libs/asura-lib-utils/io/io_task.cpp
diff --git a/source/libs/asura-lib-utils/io/io_task.h b/source/libs/asura-lib-utils/io/io_task.h
new file mode 100644
index 0000000..b91a88c
--- /dev/null
+++ b/source/libs/asura-lib-utils/io/io_task.h
@@ -0,0 +1,39 @@
+#ifndef __ASURA_IO_TASK_H__
+#define __ASURA_IO_TASK_H__
+
+#include <string>
+
+#include "../scripting/portable.hpp"
+#include "../threading/thread_task.h"
+
+#include "data_buffer.h"
+
+namespace AsuraEngine
+{
+ namespace IO
+ {
+
+ ///
+ /// ȡļ
+ ///
+ class IOTask
+ : public AEScripting::Portable<IOTask>
+ , public AEThreading::ThreadTask
+ {
+ public:
+
+ LUAX_DECL_FACTORY(IOTask);
+
+ bool Execute() override ;
+
+ private:
+
+ std::string mPath;
+ DataBuffer* mDst;
+
+ };
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/source/libs/asura-lib-utils/io/reloadable.h b/source/libs/asura-lib-utils/io/reloadable.h
index cf30296..22a721c 100644
--- a/source/libs/asura-lib-utils/io/reloadable.h
+++ b/source/libs/asura-lib-utils/io/reloadable.h
@@ -24,4 +24,6 @@ namespace AsuraEngine
}
}
+namespace AEIO = AsuraEngine::IO;
+
#endif \ No newline at end of file
diff --git a/source/libs/asura-lib-utils/threading/coroutine.cpp b/source/libs/asura-lib-utils/threading/coroutine.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/source/libs/asura-lib-utils/threading/coroutine.cpp
diff --git a/source/libs/asura-lib-utils/threading/coroutine.h b/source/libs/asura-lib-utils/threading/coroutine.h
new file mode 100644
index 0000000..1ac6b21
--- /dev/null
+++ b/source/libs/asura-lib-utils/threading/coroutine.h
@@ -0,0 +1,31 @@
+#ifndef __ASURA_COROUTINE_H__
+#define __ASURA_COROUTINE_H__
+
+#include <asura-lib-utils/scripting/portable.hpp>
+
+namespace AsuraEngine
+{
+ namespace Threading
+ {
+
+ ///
+ /// luaЭ̣һЩ߼
+ ///
+ class Coroutine ASURA_FINAL
+ : public AEScripting::Portable<Coroutine>
+ {
+ public:
+
+ LUAX_DECL_FACTORY(Coroutine);
+
+ private:
+
+ LUAX_DECL_METHOD(_New);
+ LUAX_DECL_METHOD(_Run);
+
+ };
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/source/libs/asura-lib-utils/threading/mutex.cpp b/source/libs/asura-lib-utils/threading/mutex.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/source/libs/asura-lib-utils/threading/mutex.cpp
diff --git a/source/libs/asura-lib-utils/threading/mutex.h b/source/libs/asura-lib-utils/threading/mutex.h
new file mode 100644
index 0000000..893c6e5
--- /dev/null
+++ b/source/libs/asura-lib-utils/threading/mutex.h
@@ -0,0 +1,21 @@
+#ifndef __ASURA_MUTEX_H__
+#define __ASURA_MUTEX_H__
+
+namespace AsuraEngine
+{
+ namespace Threading
+ {
+
+ class Mutex
+ {
+ public:
+
+ void Lock();
+ void Unlock();
+
+ };
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/source/libs/asura-lib-utils/threading/thread.cpp b/source/libs/asura-lib-utils/threading/thread.cpp
new file mode 100644
index 0000000..c77f3ab
--- /dev/null
+++ b/source/libs/asura-lib-utils/threading/thread.cpp
@@ -0,0 +1,14 @@
+#include "thread.h"
+
+namespace AsuraEngine
+{
+ namespace Threading
+ {
+
+ bool Thread::Enqueue(ThreadTask* task)
+ {
+
+ }
+
+ }
+} \ No newline at end of file
diff --git a/source/libs/asura-lib-utils/threading/thread.h b/source/libs/asura-lib-utils/threading/thread.h
new file mode 100644
index 0000000..0058144
--- /dev/null
+++ b/source/libs/asura-lib-utils/threading/thread.h
@@ -0,0 +1,60 @@
+#ifndef __ASURA_THREAD_H__
+#define __ASURA_THREAD_H__
+
+#include <queue>
+#include <asura-lib-utils/scripting/portable.hpp>
+
+#include "thread_task.h"
+
+namespace AsuraEngine
+{
+ namespace Threading
+ {
+
+ class ThreadImpl;
+
+ ///
+ /// ߳壬ÿ߳άһtask queue
+ ///
+ class Thread ASURA_FINAL
+ : public AEScripting::Portable<Thread>
+ {
+ public:
+
+ LUAX_DECL_FACTORY(Thread);
+
+ bool Enqueue(ThreadTask* task);
+
+ void Run();
+
+ private:
+
+ ///
+ /// С
+ ///
+ std::queue<ThreadTask*> mTaskQueue;
+
+ ThreadImpl* mImpl;
+
+ LUAX_DECL_METHOD(_Enqueue);
+ LUAX_DECL_METHOD(_Run);
+
+ };
+
+ ///
+ /// ̵߳ľʵ֣û͸ģһ׼ֲԣ
+ /// 1: win32
+ /// 2: posix
+ /// 3: SDL
+ /// 4: std::thread
+ ///
+ ASURA_ABSTRACT class ThreadImpl
+ {
+ public:
+
+ };
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/source/libs/asura-lib-utils/threading/thread_impl_posix.cpp b/source/libs/asura-lib-utils/threading/thread_impl_posix.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/source/libs/asura-lib-utils/threading/thread_impl_posix.cpp
diff --git a/source/libs/asura-lib-utils/threading/thread_impl_posix.h b/source/libs/asura-lib-utils/threading/thread_impl_posix.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/source/libs/asura-lib-utils/threading/thread_impl_posix.h
diff --git a/source/libs/asura-lib-utils/threading/thread_impl_sdl.cpp b/source/libs/asura-lib-utils/threading/thread_impl_sdl.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/source/libs/asura-lib-utils/threading/thread_impl_sdl.cpp
diff --git a/source/libs/asura-lib-utils/threading/thread_impl_sdl.h b/source/libs/asura-lib-utils/threading/thread_impl_sdl.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/source/libs/asura-lib-utils/threading/thread_impl_sdl.h
diff --git a/source/libs/asura-lib-utils/threading/thread_impl_std.cpp b/source/libs/asura-lib-utils/threading/thread_impl_std.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/source/libs/asura-lib-utils/threading/thread_impl_std.cpp
diff --git a/source/libs/asura-lib-utils/threading/thread_impl_std.h b/source/libs/asura-lib-utils/threading/thread_impl_std.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/source/libs/asura-lib-utils/threading/thread_impl_std.h
diff --git a/source/libs/asura-lib-utils/threading/thread_impl_win32.cpp b/source/libs/asura-lib-utils/threading/thread_impl_win32.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/source/libs/asura-lib-utils/threading/thread_impl_win32.cpp
diff --git a/source/libs/asura-lib-utils/threading/thread_impl_win32.h b/source/libs/asura-lib-utils/threading/thread_impl_win32.h
new file mode 100644
index 0000000..3dd2a8e
--- /dev/null
+++ b/source/libs/asura-lib-utils/threading/thread_impl_win32.h
@@ -0,0 +1,35 @@
+#ifndef __ASURA_THREAD_WIN32_H__
+#define __ASURA_THREAD_WIN32_H__
+
+#include "../utils_config.h"
+
+#if ASURA_THREAD_WIN32
+
+#include <windows.h>
+#include "thread.h"
+
+namespace AsuraEngine
+{
+ namespace Threading
+ {
+
+ ///
+ /// Threadwin32ʵ֡
+ ///
+ class ThreadImplWin32 : public ThreadImpl
+ {
+ public:
+
+
+ private:
+
+ HANDLE mHandle;
+
+ };
+
+ }
+}
+
+#endif // #if ASURA_THREAD_WIN32
+
+#endif \ No newline at end of file
diff --git a/source/libs/asura-lib-utils/threading/thread_task.cpp b/source/libs/asura-lib-utils/threading/thread_task.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/source/libs/asura-lib-utils/threading/thread_task.cpp
diff --git a/source/libs/asura-lib-utils/threading/thread_task.h b/source/libs/asura-lib-utils/threading/thread_task.h
new file mode 100644
index 0000000..35e159c
--- /dev/null
+++ b/source/libs/asura-lib-utils/threading/thread_task.h
@@ -0,0 +1,27 @@
+#ifndef __ASURA_THRAD_TASK_H__
+#define __ASURA_THRAD_TASK_H__
+
+#include <asura-lib-utils/type.h>
+
+namespace AsuraEngine
+{
+ namespace Threading
+ {
+
+ ///
+ /// ϣһ̴߳񣬼̳TaskдExecute
+ ///
+ ASURA_ABSTRACT class ThreadTask
+ {
+ public:
+
+ virtual bool Execute() = 0;
+
+ };
+
+ }
+}
+
+namespace AEThreading = AsuraEngine::Threading;
+
+#endif \ No newline at end of file
diff --git a/source/libs/asura-lib-utils/utils_config.h b/source/libs/asura-lib-utils/utils_config.h
index e69de29..836eb07 100644
--- a/source/libs/asura-lib-utils/utils_config.h
+++ b/source/libs/asura-lib-utils/utils_config.h
@@ -0,0 +1,6 @@
+#ifndef __ASURA_UTILS_CONFIG_H__
+#define __ASURA_UTILS_CONFIG_H__
+
+#define ASURA_THREAD_WIN32 1
+
+#endif \ No newline at end of file
diff --git a/source/libs/asura-lib-utils/utils_module.cpp b/source/libs/asura-lib-utils/utils_module.cpp
index f335ec5..a0539ed 100644
--- a/source/libs/asura-lib-utils/utils_module.cpp
+++ b/source/libs/asura-lib-utils/utils_module.cpp
@@ -1,6 +1,7 @@
#include "utils_module.h"
using namespace AsuraEngine::IO;
+using namespace AsuraEngine::Threading;
namespace AsuraEngine
{
@@ -12,6 +13,8 @@ namespace AsuraEngine
LUAX_REGISTER_FACTORY(state, DataBuffer);
LUAX_REGISTER_FACTORY(state, FileData);
LUAX_REGISTER_FACTORY(state, File);
+ // Threading
+ LUAX_REGISTER_FACTORY(state, Thread);
}
void UtilsModule::Finalize(Luax::LuaxState& state)
diff --git a/source/libs/asura-lib-utils/utils_module.h b/source/libs/asura-lib-utils/utils_module.h
index bf80d27..ae875b9 100644
--- a/source/libs/asura-lib-utils/utils_module.h
+++ b/source/libs/asura-lib-utils/utils_module.h
@@ -6,6 +6,8 @@
#include "io/file_data.h"
#include "io/file.h"
+#include "threading/thread.h"
+
#include "module.h"
namespace AsuraEngine