mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-05 03:21:42 +00:00
wpiutil: uv::Async: Keep weak reference to loop
Other handles can only be used within the loop itself, but Async is intended to be used from another thread. This introduces the possibility of a race condition between the loop being destroyed and the Async being destroyed. Change Async to keep a weak reference to a loop and check it before performing libuv operations.
This commit is contained in:
@@ -104,7 +104,9 @@ class Handle : public std::enable_shared_from_this<Handle> {
|
||||
*
|
||||
* @return True if the handle is closing or closed, false otherwise.
|
||||
*/
|
||||
bool IsClosing() const noexcept { return uv_is_closing(m_uv_handle) != 0; }
|
||||
bool IsClosing() const noexcept {
|
||||
return m_closed || uv_is_closing(m_uv_handle) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Request handle to be closed.
|
||||
@@ -219,6 +221,7 @@ class Handle : public std::enable_shared_from_this<Handle> {
|
||||
|
||||
void Keep() noexcept { m_self = shared_from_this(); }
|
||||
void Release() noexcept { m_self.reset(); }
|
||||
void ForceClosed() noexcept { m_closed = true; }
|
||||
|
||||
static void AllocBuf(uv_handle_t* handle, size_t size, uv_buf_t* buf);
|
||||
static void DefaultFreeBuf(Buffer& buf);
|
||||
|
||||
Reference in New Issue
Block a user