mirror of
https://github.com/mkxp-z/mkxp-z.git
synced 2025-08-04 14:05:32 +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
|
@ -1,23 +1,23 @@
|
||||||
/*
|
/*
|
||||||
** filesystem-binding.cpp
|
** filesystem-binding.cpp
|
||||||
**
|
**
|
||||||
** This file is part of mkxp.
|
** This file is part of mkxp.
|
||||||
**
|
**
|
||||||
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
||||||
**
|
**
|
||||||
** mkxp is free software: you can redistribute it and/or modify
|
** mkxp is free software: you can redistribute it and/or modify
|
||||||
** it under the terms of the GNU General Public License as published by
|
** it under the terms of the GNU General Public License as published by
|
||||||
** the Free Software Foundation, either version 2 of the License, or
|
** the Free Software Foundation, either version 2 of the License, or
|
||||||
** (at your option) any later version.
|
** (at your option) any later version.
|
||||||
**
|
**
|
||||||
** mkxp is distributed in the hope that it will be useful,
|
** mkxp is distributed in the hope that it will be useful,
|
||||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
** GNU General Public License for more details.
|
** GNU General Public License for more details.
|
||||||
**
|
**
|
||||||
** You should have received a copy of the GNU General Public License
|
** You should have received a copy of the GNU General Public License
|
||||||
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "src/config.h"
|
#include "src/config.h"
|
||||||
|
|
||||||
|
@ -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