Skip to content

Commit

Permalink
Avoid copying the mutex in KqueueHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
gansm committed Jul 24, 2023
1 parent 84a8dcc commit f02cf27
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
13 changes: 12 additions & 1 deletion final/eventloop/kqueue_timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,17 @@ static std::vector<struct kevent> time_events{};
class KqueueHandler
{
public:
// Constructor
KqueueHandler() = default;

// Copy constructor - no mutex copies
KqueueHandler (const KqueueHandler&)
{ }

// Move constructor - no mutex copies
KqueueHandler (KqueueHandler&&) noexcept
{ }

// Overloaded operator
void operator () (Monitor* monitor, short revents)
{
Expand Down Expand Up @@ -152,7 +163,7 @@ class KqueueHandler

private:
// Data members
std::mutex timer_nodes_mutex{};
mutable std::mutex timer_nodes_mutex{};
};


Expand Down
14 changes: 13 additions & 1 deletion final/eventloop/posix_timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class SigAlrmHandler
operator HandlerReturnType () const noexcept
{
// Converts a member function pointer to a function pointer
return invoke;
return &invoke;
};

private:
Expand Down Expand Up @@ -285,6 +285,18 @@ class SigAlrmHandlerInstaller
}

private:
// Disable copy constructor
SigAlrmHandlerInstaller (const SigAlrmHandlerInstaller&) = delete;

// Disable move constructor
SigAlrmHandlerInstaller (SigAlrmHandlerInstaller&&) noexcept = delete;

// Disable copy assignment operator (=)
auto operator = (const SigAlrmHandlerInstaller&) -> SigAlrmHandlerInstaller& = delete;

// Disable move assignment operator (=)
auto operator = (SigAlrmHandlerInstaller&&) noexcept -> SigAlrmHandlerInstaller& = delete;

// Data member
struct sigaction original_signal_handle{};
};
Expand Down

0 comments on commit f02cf27

Please sign in to comment.