drm_hwcomposer: Introduce SharedFd, use standard c++ RAII for UniqueFd
We use too much dup() system calls for present fence propagating.
Also when propagating acquire fence we use additional logic for
skipping such propagation for the validate/test cycle.
Both issues can be solved by introducing SharedFd, which will track
reference count of fd object.
After that the UniqueFd is used very rarely and can be simplified by
wrapping it into std::unique_ptr without caring too much of adding
an extra malloc/free operation.
Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
diff --git a/utils/UEvent.h b/utils/UEvent.h
index 64992a1..5b9ecea 100644
--- a/utils/UEvent.h
+++ b/utils/UEvent.h
@@ -24,7 +24,7 @@
#include <optional>
#include <string>
-#include "UniqueFd.h"
+#include "fd.h"
#include "log.h"
namespace android {
@@ -32,7 +32,7 @@
class UEvent {
public:
static auto CreateInstance() -> std::unique_ptr<UEvent> {
- auto fd = UniqueFd(
+ auto fd = MakeUniqueFd(
socket(PF_NETLINK, SOCK_DGRAM | SOCK_CLOEXEC, NETLINK_KOBJECT_UEVENT));
if (!fd) {
@@ -46,7 +46,7 @@
addr.nl_groups = UINT32_MAX;
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast)
- const int ret = bind(fd.Get(), (struct sockaddr *)&addr, sizeof(addr));
+ const int ret = bind(*fd, (struct sockaddr *)&addr, sizeof(addr));
if (ret != 0) {
ALOGE("Failed to bind uevent socket: errno=%i", errno);
return {};
@@ -59,7 +59,7 @@
constexpr int kUEventBufferSize = 1024;
char buffer[kUEventBufferSize];
ssize_t ret = 0;
- ret = read(fd_.Get(), &buffer, sizeof(buffer));
+ ret = read(*fd_, &buffer, sizeof(buffer));
if (ret == 0)
return {};