More fixes discovered based on Deedra's work.
This commit is contained in:
1 parent
de31e5b513
commit
17052c5147
22 files changed
+561
-76
No files matched your search
+9
-2
@@ -1,5 +1,6 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
#include "reader_events.h"
|
||||
#include "text_limits.h"
|
||||
#include <condition_variable>
|
||||
#include <cstdio>
|
||||
#include <deque>
|
||||
@@ -21,11 +22,13 @@ struct ReaderEventQueue::State {
|
||||
std::mutex mutex;
|
||||
std::condition_variable changed;
|
||||
std::deque<GVariant *> pending;
|
||||
size_t pendingBytes = 0;
|
||||
bool stopping = false, overflowReported = false;
|
||||
|
||||
void clear() {
|
||||
for (auto *parameters : pending) g_variant_unref(parameters);
|
||||
pending.clear();
|
||||
pendingBytes = 0;
|
||||
}
|
||||
bool send(GVariant *parameters, unsigned &failures) {
|
||||
GError *error = nullptr;
|
||||
@@ -64,6 +67,7 @@ struct ReaderEventQueue::State {
|
||||
if (state->stopping) break;
|
||||
parameters = state->pending.front();
|
||||
state->pending.pop_front();
|
||||
state->pendingBytes -= g_variant_get_size(parameters);
|
||||
}
|
||||
const char *source = nullptr, *kind = nullptr;
|
||||
g_variant_get_child(parameters, 0, "&s", &source);
|
||||
@@ -100,17 +104,20 @@ bool ReaderEventQueue::start(GDBusConnection *connection, const ReaderEndpoint &
|
||||
|
||||
bool ReaderEventQueue::submit(GVariant *parameters) {
|
||||
parameters = g_variant_ref_sink(parameters);
|
||||
const size_t bytes = g_variant_get_size(parameters);
|
||||
if (state_) {
|
||||
std::lock_guard<std::mutex> lock(state_->mutex);
|
||||
// Keep memory bounded if the reader remains unavailable. Do not reorder
|
||||
// actions or evict the focus on which queued editor actions depend.
|
||||
if (!state_->stopping && state_->pending.size() < 128) {
|
||||
if (!state_->stopping && state_->pending.size() < 128 &&
|
||||
bytes <= max_reader_event_bytes && bytes <= max_reader_queue_bytes - state_->pendingBytes) {
|
||||
state_->pending.push_back(parameters);
|
||||
state_->pendingBytes += bytes;
|
||||
state_->changed.notify_one();
|
||||
return true;
|
||||
}
|
||||
if (!state_->stopping && !state_->overflowReported) {
|
||||
std::fprintf(stderr, "wine-access: reader event queue full; feedback dropped\n");
|
||||
std::fprintf(stderr, "wine-access: reader event size or queue limit reached; feedback dropped\n");
|
||||
state_->overflowReported = true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user