mirror of
https://github.com/mkxp-z/mkxp-z.git
synced 2025-08-04 22:15:33 +02:00
Make load_data properly work in threads
This commit is contained in:
parent
35d776abd7
commit
8b0bb010ba
1 changed files with 209 additions and 205 deletions
|
@ -74,6 +74,18 @@ static VALUE fileIntForPath(const char *path, bool rubyExc) {
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if RAPI_MAJOR > 2
|
||||||
|
typedef struct {
|
||||||
|
SDL_RWops *ops;
|
||||||
|
void *dst;
|
||||||
|
int length;
|
||||||
|
} fileIntReadCbArgs;
|
||||||
|
|
||||||
|
void call_RWread_cb(fileIntReadCbArgs *args) {
|
||||||
|
SDL_RWread(args->ops, args->dst, 1, args->length);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
RB_METHOD(fileIntRead) {
|
RB_METHOD(fileIntRead) {
|
||||||
|
|
||||||
int length = -1;
|
int length = -1;
|
||||||
|
@ -100,7 +112,17 @@ RB_METHOD(fileIntRead) {
|
||||||
|
|
||||||
VALUE data = rb_str_new(0, length);
|
VALUE data = rb_str_new(0, length);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#if RAPI_MAJOR > 2
|
||||||
|
fileIntReadCbArgs cbargs {ops, RSTRING_PTR(data), length};
|
||||||
|
rb_thread_call_without_gvl([](void* args) -> void* {
|
||||||
|
call_RWread_cb((fileIntReadCbArgs*)args);
|
||||||
|
return 0;
|
||||||
|
}, (void*)&cbargs, 0, 0);
|
||||||
|
#elif
|
||||||
SDL_RWread(ops, RSTRING_PTR(data), 1, length);
|
SDL_RWread(ops, RSTRING_PTR(data), 1, length);
|
||||||
|
#endif
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
@ -161,17 +183,6 @@ kernelLoadDataInt(const char *filename, bool rubyExc, bool raw) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if RAPI_MAJOR >= 2
|
|
||||||
typedef struct {
|
|
||||||
const char *filename;
|
|
||||||
bool loadRaw;
|
|
||||||
} loadDataRubyArgs;
|
|
||||||
|
|
||||||
VALUE call_kernelLoadDataInt_cb(loadDataRubyArgs *args) {
|
|
||||||
return kernelLoadDataInt(args->filename, true, args->loadRaw);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
RB_METHOD(kernelLoadData) {
|
RB_METHOD(kernelLoadData) {
|
||||||
RB_UNUSED_PARAM;
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
@ -184,14 +195,7 @@ RB_METHOD(kernelLoadData) {
|
||||||
if (raw != Qnil && raw != Qtrue && raw != Qfalse) {
|
if (raw != Qnil && raw != Qtrue && raw != Qfalse) {
|
||||||
rb_raise(rb_eTypeError, "load_data: second argument must be Boolean");
|
rb_raise(rb_eTypeError, "load_data: second argument must be Boolean");
|
||||||
}
|
}
|
||||||
#if RAPI_MAJOR >= 2
|
|
||||||
loadDataRubyArgs ldargs {RSTRING_PTR(filename), RTEST(raw)};
|
|
||||||
return (VALUE)rb_thread_call_without_gvl([](void* args) -> void* {
|
|
||||||
return ((void*)call_kernelLoadDataInt_cb((loadDataRubyArgs*)args));
|
|
||||||
}, (void*)&ldargs, 0, 0);
|
|
||||||
#else
|
|
||||||
return kernelLoadDataInt(RSTRING_PTR(filename), true, RTEST(raw));
|
return kernelLoadDataInt(RSTRING_PTR(filename), true, RTEST(raw));
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(kernelSaveData) {
|
RB_METHOD(kernelSaveData) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue