Reactor: Use std::shared_ptr to ref-count rr::Routines
The intrusive reference counting had no smart pointer, making it difficult to correctly manage reference counts. Most of the codebase did not call bind() and unbind() explictly, and relied on some other mechanism for keeping the routine alive.
By switching to std::shared_ptr, we automatically get guarantees that routine cache eviction will not destroy the routine while it is in use.
Bug: b/137524292
Bug: b/137649247
Change-Id: I38b5e8ba3ee084572a427a1de20f4f017ceaae5a
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/34168
Tested-by: Ben Clayton <bclayton@google.com>
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
diff --git a/src/Main/FrameBuffer.cpp b/src/Main/FrameBuffer.cpp
index 7d2e6a0..5e4f6c3 100644
--- a/src/Main/FrameBuffer.cpp
+++ b/src/Main/FrameBuffer.cpp
@@ -66,8 +66,6 @@
blitThread->join();
delete blitThread;
}
-
- delete blitRoutine;
}
void FrameBuffer::setCursorImage(sw::Surface *cursorImage)
@@ -154,8 +152,6 @@
if(memcmp(&blitState, &updateState, sizeof(BlitState)) != 0)
{
blitState = updateState;
- delete blitRoutine;
-
blitRoutine = copyRoutine(blitState);
blitFunction = (void(*)(void*, void*, Cursor*))blitRoutine->getEntry();
}
@@ -163,7 +159,7 @@
blitFunction(framebuffer, renderbuffer, &cursor);
}
- Routine *FrameBuffer::copyRoutine(const BlitState &state)
+ std::shared_ptr<Routine> FrameBuffer::copyRoutine(const BlitState &state)
{
const int width = state.width;
const int height = state.height;