mirror of
https://github.com/TomHarte/CLK.git
synced 2025-01-12 00:30:31 +00:00
Reduce modal-related thread hopping.
This commit is contained in:
parent
b097b1296b
commit
51ed3f2ed0
@ -939,12 +939,14 @@ using BufferingScanTarget = Outputs::Display::BufferingScanTarget;
|
|||||||
|
|
||||||
- (void)updateFrameBuffer {
|
- (void)updateFrameBuffer {
|
||||||
// TODO: rethink BufferingScanTarget::perform. Is it now really just for guarding the modals?
|
// TODO: rethink BufferingScanTarget::perform. Is it now really just for guarding the modals?
|
||||||
|
if(_scanTarget.has_new_modals()) {
|
||||||
_scanTarget.perform([=] {
|
_scanTarget.perform([=] {
|
||||||
const Outputs::Display::ScanTarget::Modals *const newModals = _scanTarget.new_modals();
|
const Outputs::Display::ScanTarget::Modals *const newModals = _scanTarget.new_modals();
|
||||||
if(newModals) {
|
if(newModals) {
|
||||||
[self setModals:*newModals];
|
[self setModals:*newModals];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@synchronized(self) {
|
@synchronized(self) {
|
||||||
if(!_frameBufferRenderPass) return;
|
if(!_frameBufferRenderPass) return;
|
||||||
|
@ -302,7 +302,7 @@ size_t BufferingScanTarget::write_area_data_size() const {
|
|||||||
void BufferingScanTarget::set_modals(Modals modals) {
|
void BufferingScanTarget::set_modals(Modals modals) {
|
||||||
perform([=] {
|
perform([=] {
|
||||||
modals_ = modals;
|
modals_ = modals;
|
||||||
modals_are_dirty_ = true;
|
modals_are_dirty_.store(true, std::memory_order::memory_order_relaxed);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -374,10 +374,12 @@ void BufferingScanTarget::set_line_buffer(Line *line_buffer, LineMetadata *metad
|
|||||||
}
|
}
|
||||||
|
|
||||||
const Outputs::Display::ScanTarget::Modals *BufferingScanTarget::new_modals() {
|
const Outputs::Display::ScanTarget::Modals *BufferingScanTarget::new_modals() {
|
||||||
if(!modals_are_dirty_) {
|
const auto modals_are_dirty = modals_are_dirty_.load(std::memory_order::memory_order_relaxed);
|
||||||
|
if(!modals_are_dirty) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
modals_are_dirty_ = false;
|
|
||||||
|
modals_are_dirty_.store(false, std::memory_order::memory_order_relaxed);
|
||||||
|
|
||||||
// MAJOR SHARP EDGE HERE: assume that because the new_modals have been fetched then the caller will
|
// MAJOR SHARP EDGE HERE: assume that because the new_modals have been fetched then the caller will
|
||||||
// now ensure their texture buffer is appropriate. They might provide a new pointer and might now.
|
// now ensure their texture buffer is appropriate. They might provide a new pointer and might now.
|
||||||
@ -392,3 +394,7 @@ const Outputs::Display::ScanTarget::Modals *BufferingScanTarget::new_modals() {
|
|||||||
const Outputs::Display::ScanTarget::Modals &BufferingScanTarget::modals() const {
|
const Outputs::Display::ScanTarget::Modals &BufferingScanTarget::modals() const {
|
||||||
return modals_;
|
return modals_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool BufferingScanTarget::has_new_modals() const {
|
||||||
|
return modals_are_dirty_.load(std::memory_order::memory_order_relaxed);
|
||||||
|
}
|
||||||
|
@ -161,6 +161,11 @@ class BufferingScanTarget: public Outputs::Display::ScanTarget {
|
|||||||
/// @returns the current @c Modals.
|
/// @returns the current @c Modals.
|
||||||
const Modals &modals() const;
|
const Modals &modals() const;
|
||||||
|
|
||||||
|
/// @returns @c true if new modals are available; @c false otherwise.
|
||||||
|
///
|
||||||
|
/// Safe to call from any thread.
|
||||||
|
bool has_new_modals() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// ScanTarget overrides.
|
// ScanTarget overrides.
|
||||||
void set_modals(Modals) final;
|
void set_modals(Modals) final;
|
||||||
@ -253,7 +258,7 @@ class BufferingScanTarget: public Outputs::Display::ScanTarget {
|
|||||||
// Current modals and whether they've yet been returned
|
// Current modals and whether they've yet been returned
|
||||||
// from a call to @c get_new_modals.
|
// from a call to @c get_new_modals.
|
||||||
Modals modals_;
|
Modals modals_;
|
||||||
bool modals_are_dirty_ = false;
|
std::atomic<bool> modals_are_dirty_ = false;
|
||||||
|
|
||||||
// Provides a per-data size implementation of end_data; a previous
|
// Provides a per-data size implementation of end_data; a previous
|
||||||
// implementation used blind memcpy and that turned into something
|
// implementation used blind memcpy and that turned into something
|
||||||
|
Loading…
x
Reference in New Issue
Block a user