mirror of
https://github.com/lihop/godot-xterm.git
synced 2025-07-04 04:55:30 +02:00
feat(pty): add multithread support
Adds the option `use_threads` to PTY (enabled by default) which improves performance when enabled. For example, running `time cat file.txt` where file is ~4.5MB will take ~0.250s with threads enabled, versus >20s when disabled.
This commit is contained in:
parent
46f3aa12bf
commit
a0c9777264
3 changed files with 118 additions and 42 deletions
|
@ -3,8 +3,11 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <godot_cpp/classes/mutex.hpp>
|
||||
#include <godot_cpp/classes/node.hpp>
|
||||
#include <godot_cpp/classes/os.hpp>
|
||||
#include <godot_cpp/classes/semaphore.hpp>
|
||||
#include <godot_cpp/classes/thread.hpp>
|
||||
#include <uv.h>
|
||||
|
||||
namespace godot
|
||||
|
@ -52,6 +55,9 @@ namespace godot
|
|||
bool get_use_os_env() const;
|
||||
void set_use_os_env(const bool value);
|
||||
|
||||
void set_use_threads(bool p_use);
|
||||
bool is_using_threads() const;
|
||||
|
||||
String get_pts() const;
|
||||
|
||||
Error fork(const String &file = "", const PackedStringArray &args = PackedStringArray(), const String &cwd = ".", const int cols = 80, const int rows = 24);
|
||||
|
@ -62,7 +68,6 @@ namespace godot
|
|||
void write(const Variant &data) const;
|
||||
|
||||
void _notification(int p_what);
|
||||
void _run(uv_run_mode mode);
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
@ -85,11 +90,21 @@ namespace godot
|
|||
void _on_exit(int exit_code, int exit_signal);
|
||||
void _close();
|
||||
|
||||
Ref<Thread> thread;
|
||||
Ref<Mutex> buffer_write_mutex;
|
||||
Ref<Semaphore> buffer_cleared;
|
||||
PackedByteArray buffer;
|
||||
SafeFlag stop_thread;
|
||||
uv_async_t async_handle;
|
||||
bool use_threads;
|
||||
void _thread_func();
|
||||
|
||||
#if defined(__linux__) || defined(__APPLE__)
|
||||
uv_pipe_t pipe;
|
||||
Error _pipe_open(const int fd);
|
||||
#endif
|
||||
|
||||
static void _read_cb(uv_stream_t *pipe, ssize_t nread, const uv_buf_t *buf);
|
||||
static Error uv_err_to_godot_err(const int uv_err);
|
||||
};
|
||||
} // namespace godot
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue