aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>2022-05-03 07:57:47 +0900
committer坂本 貴史 <o-takashi@sakamocchi.jp>2022-05-03 08:31:29 +0900
commit85e59ec314c2610bfdbf9d50d19ad759d6f558a3 (patch)
tree497b0db2444d36f4a39f0dbe63d7a5745094282b
parentb82cc209ff8d71927f898f03833bad55b443c3f3 (diff)
downloadlibhinoko-85e59ec314c2610bfdbf9d50d19ad759d6f558a3.tar.gz
fw_iso_resource: code refactoring to add cache of file descriptor
GSource generated by call of Hinoko.FwIsoResource.create_source() accesses to private data of Hinoko.FwIsoResource to refer to file descriptor, however it's necessarily convenient since it's planned to make the class as interface. This commit puts cache of file descriptor for private structure for the source. Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
-rw-r--r--src/fw_iso_resource.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/src/fw_iso_resource.c b/src/fw_iso_resource.c
index d968a8a..6ce7324 100644
--- a/src/fw_iso_resource.c
+++ b/src/fw_iso_resource.c
@@ -60,6 +60,7 @@ typedef struct {
gpointer tag;
gsize len;
guint8 *buf;
+ int fd;
} FwIsoResourceSource;
enum fw_iso_resource_sig_type {
@@ -319,21 +320,18 @@ static gboolean check_src(GSource *source)
static gboolean dispatch_src(GSource *source, GSourceFunc cb, gpointer user_data)
{
FwIsoResourceSource *src = (FwIsoResourceSource *)source;
- HinokoFwIsoResource *self = src->self;
- HinokoFwIsoResourcePrivate *priv =
- hinoko_fw_iso_resource_get_instance_private(self);
GIOCondition condition;
ssize_t len;
const union fw_cdev_event *ev;
- if (priv->fd < 0)
+ if (src->fd < 0)
return G_SOURCE_REMOVE;
condition = g_source_query_unix_fd(source, src->tag);
if (condition & G_IO_ERR)
return G_SOURCE_REMOVE;
- len = read(priv->fd, src->buf, src->len);
+ len = read(src->fd, src->buf, src->len);
if (len <= 0) {
if (errno == EAGAIN)
return G_SOURCE_CONTINUE;
@@ -345,7 +343,7 @@ static gboolean dispatch_src(GSource *source, GSourceFunc cb, gpointer user_data
switch (ev->common.type) {
case FW_CDEV_EVENT_ISO_RESOURCE_ALLOCATED:
case FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED:
- handle_fw_iso_resource_event(self, &ev->iso_resource);
+ handle_fw_iso_resource_event(src->self, &ev->iso_resource);
break;
default:
break;
@@ -401,6 +399,7 @@ void hinoko_fw_iso_resource_create_source(HinokoFwIsoResource *self,
src->len = (gsize)page_size;
src->tag = g_source_add_unix_fd(*source, priv->fd, G_IO_IN);
+ src->fd = priv->fd;
src->self = g_object_ref(self);
}