summaryrefslogtreecommitdiff
path: root/source/libs/asura-lib-utils/io
diff options
context:
space:
mode:
Diffstat (limited to 'source/libs/asura-lib-utils/io')
-rw-r--r--source/libs/asura-lib-utils/io/binding/_io_task.cpp36
-rw-r--r--source/libs/asura-lib-utils/io/data_buffer.cpp9
-rw-r--r--source/libs/asura-lib-utils/io/data_buffer.h3
-rw-r--r--source/libs/asura-lib-utils/io/file.h11
-rw-r--r--source/libs/asura-lib-utils/io/io_task.cpp29
-rw-r--r--source/libs/asura-lib-utils/io/io_task.h10
6 files changed, 95 insertions, 3 deletions
diff --git a/source/libs/asura-lib-utils/io/binding/_io_task.cpp b/source/libs/asura-lib-utils/io/binding/_io_task.cpp
new file mode 100644
index 0000000..c03ff2a
--- /dev/null
+++ b/source/libs/asura-lib-utils/io/binding/_io_task.cpp
@@ -0,0 +1,36 @@
+#include "../io_task.h"
+
+using namespace std;
+
+namespace AsuraEngine
+{
+ namespace IO
+ {
+
+ LUAX_REGISTRY(IOTask)
+ {
+ LUAX_REGISTER_METHODS(state,
+ { "New", _New }
+ );
+ }
+
+ LUAX_POSTPROCESS(IOTask)
+ {
+
+ }
+
+ // task = IOTask.New(path, dst)
+ LUAX_IMPL_METHOD(IOTask, _New)
+ {
+ LUAX_STATE(L);
+
+ cc8* path = state.CheckParam<cc8*>(1);
+ DataBuffer* db = state.CheckUserdata<DataBuffer>(2);
+ IOTask* task = new IOTask(path, db);
+ task->PushLuaxUserdata(state);
+ task->SetLuaxMemberRef(state, task->mDstRef, 2);
+ return 1;
+ }
+
+ }
+}
diff --git a/source/libs/asura-lib-utils/io/data_buffer.cpp b/source/libs/asura-lib-utils/io/data_buffer.cpp
index 3c0100b..000869d 100644
--- a/source/libs/asura-lib-utils/io/data_buffer.cpp
+++ b/source/libs/asura-lib-utils/io/data_buffer.cpp
@@ -2,6 +2,8 @@
#include <cstring>
#include "data_buffer.h"
+using namespace AEThreading;
+
namespace AsuraEngine
{
namespace IO
@@ -16,6 +18,7 @@ namespace AsuraEngine
: mSize(size)
, mBytes(nullptr)
{
+ lock(mMutex);
mBytes = new byte[size];
memset(mBytes, 0, size);
}
@@ -34,6 +37,7 @@ namespace AsuraEngine
void DataBuffer::Refactor(size_t size)
{
+ lock(mMutex);
if (!mBytes || mSize != size)
{
delete[] mBytes;
@@ -50,6 +54,7 @@ namespace AsuraEngine
size_t DataBuffer::Load(const void* data, std::size_t size)
{
+ lock(mMutex);
size_t len = mSize > size ? size : mSize;
memcpy(mBytes, data, len);
return len;
@@ -57,6 +62,7 @@ namespace AsuraEngine
void DataBuffer::Move(void* bytes, std::size_t size)
{
+ lock(mMutex);
if (!mBytes)
{
delete[] mBytes;
@@ -72,10 +78,11 @@ namespace AsuraEngine
void DataBuffer::Clear()
{
+ lock(mMutex);
if (mBytes)
memset(mBytes, 0, mSize);
}
-
+
std::size_t DataBuffer::GetSize()
{
return mSize;
diff --git a/source/libs/asura-lib-utils/io/data_buffer.h b/source/libs/asura-lib-utils/io/data_buffer.h
index c63a248..9dfe541 100644
--- a/source/libs/asura-lib-utils/io/data_buffer.h
+++ b/source/libs/asura-lib-utils/io/data_buffer.h
@@ -4,6 +4,7 @@
#include <cstdlib>
#include "../scripting/portable.hpp"
+#include "../threading/mutex.h"
namespace AsuraEngine
{
@@ -39,6 +40,8 @@ namespace AsuraEngine
byte* mBytes;
size_t mSize;
+ AEThreading::Mutex mMutex;
+
LUAX_DECL_METHOD(_New);
LUAX_DECL_METHOD(_GetData);
LUAX_DECL_METHOD(_GetSize);
diff --git a/source/libs/asura-lib-utils/io/file.h b/source/libs/asura-lib-utils/io/file.h
index 4a6d38b..56077e0 100644
--- a/source/libs/asura-lib-utils/io/file.h
+++ b/source/libs/asura-lib-utils/io/file.h
@@ -4,6 +4,7 @@
#include "physfs/physfs.h"
#include "../scripting/portable.hpp"
+#include "../threading/thread.h"
#include "file_data.h"
@@ -58,6 +59,7 @@ namespace AsuraEngine
///
size_t Read(ASURA_OUT DataBuffer* dst, size_t length);
size_t ReadAll(ASURA_OUT DataBuffer* dst);
+ size_t ReadAsync(ASURA_OUT DataBuffer* dst);
///
/// Ƿļβ
@@ -70,6 +72,11 @@ namespace AsuraEngine
bool Write(ASURA_REF DataBuffer* src);
///
+ /// 첽дļдļtaskthreadĶС
+ ///
+ bool WriteAsync(ASURA_REF DataBuffer* src, AEThreading::Thread* thread);
+
+ ///
/// ˻壬ǿջдļ
///
bool Flush();
@@ -118,8 +125,10 @@ namespace AsuraEngine
LUAX_DECL_METHOD(_GetMode);
LUAX_DECL_METHOD(_GetSize);
LUAX_DECL_METHOD(_Read);
- LUAX_DECL_METHOD(_IsEOF);
LUAX_DECL_METHOD(_Write);
+ LUAX_DECL_METHOD(_ReadAsync);
+ LUAX_DECL_METHOD(_WriteAsync);
+ LUAX_DECL_METHOD(_IsEOF);
LUAX_DECL_METHOD(_Flush);
LUAX_DECL_METHOD(_Tell);
LUAX_DECL_METHOD(_Seek);
diff --git a/source/libs/asura-lib-utils/io/io_task.cpp b/source/libs/asura-lib-utils/io/io_task.cpp
index e69de29..a96c293 100644
--- a/source/libs/asura-lib-utils/io/io_task.cpp
+++ b/source/libs/asura-lib-utils/io/io_task.cpp
@@ -0,0 +1,29 @@
+#include "io_task.h"
+
+namespace AsuraEngine
+{
+ namespace IO
+ {
+
+ IOTask::IOTask(const std::string& path, DataBuffer* buffer)
+ : mPath(path)
+ , mDst(buffer)
+ {
+ }
+
+ IOTask::~IOTask()
+ {
+ }
+
+ bool IOTask::Execute()
+ {
+ return true;
+ }
+
+ void IOTask::Invoke()
+ {
+
+ }
+
+ }
+}
diff --git a/source/libs/asura-lib-utils/io/io_task.h b/source/libs/asura-lib-utils/io/io_task.h
index b91a88c..aa5b38e 100644
--- a/source/libs/asura-lib-utils/io/io_task.h
+++ b/source/libs/asura-lib-utils/io/io_task.h
@@ -16,7 +16,7 @@ namespace AsuraEngine
///
/// ȡļ
///
- class IOTask
+ class IOTask ASURA_FINAL
: public AEScripting::Portable<IOTask>
, public AEThreading::ThreadTask
{
@@ -24,13 +24,21 @@ namespace AsuraEngine
LUAX_DECL_FACTORY(IOTask);
+ IOTask(const std::string& path, DataBuffer* buffer);
+ ~IOTask();
+
bool Execute() override ;
+ void Invoke() override;
private:
std::string mPath;
DataBuffer* mDst;
+ Luax::LuaxMemberRef mDstRef;
+
+ LUAX_DECL_METHOD(_New);
+
};
}