fix: delete UvTaskRunner's timers only after they're closed (#43561)
* fix: free UvTaskRunner timers only after they are closed * refactor: UvTaskRunner now holds UvHandles
This commit is contained in:
parent
25f4691e78
commit
cc5aa65cb4
3 changed files with 42 additions and 35 deletions
|
@ -15,6 +15,7 @@
|
|||
#include "base/memory/raw_ptr.h"
|
||||
#include "base/memory/raw_ptr_exclusion.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "base/types/to_address.h"
|
||||
#include "gin/public/context_holder.h"
|
||||
#include "gin/public/gin_embedders.h"
|
||||
#include "uv.h" // NOLINT(build/include_directory)
|
||||
|
@ -58,11 +59,25 @@ template <typename T,
|
|||
std::is_same<T, uv_udp_t>::value>::type* = nullptr>
|
||||
class UvHandle {
|
||||
public:
|
||||
UvHandle() : t_(new T) {}
|
||||
UvHandle() : t_{new T} {}
|
||||
~UvHandle() { reset(); }
|
||||
|
||||
UvHandle(UvHandle&&) = default;
|
||||
UvHandle& operator=(UvHandle&&) = default;
|
||||
|
||||
UvHandle(const UvHandle&) = delete;
|
||||
UvHandle& operator=(const UvHandle&) = delete;
|
||||
|
||||
T* get() { return t_; }
|
||||
T* operator->() { return t_; }
|
||||
const T* get() const { return t_; }
|
||||
const T* operator->() const { return t_; }
|
||||
|
||||
uv_handle_t* handle() { return reinterpret_cast<uv_handle_t*>(t_); }
|
||||
|
||||
// compare by handle pointer address
|
||||
auto operator<=>(const UvHandle& that) const = default;
|
||||
|
||||
void reset() {
|
||||
auto* h = handle();
|
||||
if (h != nullptr) {
|
||||
|
@ -80,6 +95,16 @@ class UvHandle {
|
|||
RAW_PTR_EXCLUSION T* t_ = {};
|
||||
};
|
||||
|
||||
// Helper for comparing UvHandles and raw uv pointers, e.g. as map keys
|
||||
struct UvHandleCompare {
|
||||
using is_transparent = void;
|
||||
|
||||
template <typename U, typename V>
|
||||
bool operator()(U const& u, V const& v) const {
|
||||
return base::to_address(u) < base::to_address(v);
|
||||
}
|
||||
};
|
||||
|
||||
class NodeBindings {
|
||||
public:
|
||||
enum class BrowserEnvironment { kBrowser, kRenderer, kUtility, kWorker };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue