]> git.alsa-project.org Git - alsa-gobject.git/commitdiff
timer: user-instance: add an argument for open(2) flag into API to open ALSA timer...
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Mon, 10 Feb 2020 08:04:09 +0000 (17:04 +0900)
committer坂本 貴史 <o-takashi@sakamocchi.jp>
Tue, 11 Feb 2020 12:01:11 +0000 (21:01 +0900)
As long as using the created Gsource with GMainContext, the call of poll(2)
system call with infinite timeout surely returns when quit() method is
called for the context. All of GMainContext implements GWakeup with eventfd
and the call of quit() emits event via file descriptor of eventfd. This
brings wakeup from blocking when poll(2) is called with inifinite timeout.
This means that it's safe for event polling without O_NONBLOCK.

On the other hand, there are many options for file descriptors; e.g.
O_APPEND and O_CLOEXEC. For the case, glib framework has no support.

This commit adds an argument for the open flags.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
src/timer/user-instance.c
src/timer/user-instance.h

index 9db4b1e949855fd9b2f8413b1263a33b98715102..d3b0c4869014456b6f471eef7c15d4e21913eb09 100644 (file)
@@ -96,11 +96,13 @@ static void alsatimer_user_instance_init(ALSATimerUserInstance *self)
 /**
  * alsatimer_user_instance_open:
  * @self: A #ALSATimerUserInstance.
+ * @open_flag: The flag of open(2) system call. O_RDONLY is forced to fulfil internally.
  * @error: A #GError.
  *
  * Open ALSA Timer character device to allocate queue.
  */
-void alsatimer_user_instance_open(ALSATimerUserInstance *self, GError **error)
+void alsatimer_user_instance_open(ALSATimerUserInstance *self, gint open_flag,
+                                  GError **error)
 {
     ALSATimerUserInstancePrivate *priv;
     char *devnode;
@@ -112,7 +114,8 @@ void alsatimer_user_instance_open(ALSATimerUserInstance *self, GError **error)
     if (*error != NULL)
         return;
 
-    priv->fd = open(devnode, O_RDONLY);
+    open_flag |= O_RDONLY;
+    priv->fd = open(devnode, open_flag);
     g_free(devnode);
     if (priv->fd < 0) {
         generate_error(error, errno);
index 311b92e3b02a9de76737948ed7fb46d0b5a11173..76329eddb26baae83b88cf0e9d31ce557652fb82 100644 (file)
@@ -74,7 +74,8 @@ GType alsatimer_user_instance_get_type() G_GNUC_CONST;
 
 ALSATimerUserInstance *alsatimer_user_instance_new();
 
-void alsatimer_user_instance_open(ALSATimerUserInstance *self, GError **error);
+void alsatimer_user_instance_open(ALSATimerUserInstance *self, gint open_flag,
+                                  GError **error);
 
 void alsatimer_user_instance_attach(ALSATimerUserInstance *self,
                                     ALSATimerDeviceId *device_id,