All of lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Sakamoto <o-takashi@sakamocchi.jp>
To: clemens@ladisch.de, tiwai@suse.de, perex@perex.cz
Cc: alsa-devel@alsa-project.org,
	linux1394-devel@lists.sourceforge.net, ffado-devel@lists.sf.net
Subject: Re: [PATCH 02/13] libhinawa: add hinawa context
Date: Wed, 28 Jan 2015 00:35:22 +0900	[thread overview]
Message-ID: <54C7B03A.10901@sakamocchi.jp> (raw)
In-Reply-To: <1422185674-16431-3-git-send-email-o-takashi@sakamocchi.jp>

On 2015年01月25日 20:34, Takashi Sakamoto wrote:
> In this library, 'transaction' consists of a pair of a request and
> a response. To achieve the transaction, a requester should wait for
> a response from the receiver.
> 
> Typically, to achieve the transaction, applications which transfer
> requests are blocked with read(2) or poll(2) to wait responses. But
> this operation is not good for GUI applications because these
> blocking API stops a thread of event loop.
> 
> To avoid this situation, this commit adds own 'context'. The context
> is running on own thread and execute poll(2). This context can be
> written directly with pthreads(7) and select(2)/poll(2)/epoll(7),
> but in this time I apply GMainContext/GThread in glib to save my
> time.
> 
> Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>

I realize this comment is bad. The strange circuit turned on in my brain
when creating this patch...

This library needs to handle any asynchronous events such as bus-reset
(from FireWire subsystem) or lock/unlock events (from ALSA), thus should
do poll regardless of transactions. In this reason, own thread is required.

> ---
>  libhinawa/Makefile.am          |  3 +++
>  libhinawa/README               |  1 +
>  libhinawa/configure.ac         |  7 +++++
>  libhinawa/src/Makefile.am      | 24 +++++++++++++++++
>  libhinawa/src/hinawa_context.c | 60 ++++++++++++++++++++++++++++++++++++++++++
>  libhinawa/src/hinawa_context.h | 10 +++++++
>  6 files changed, 105 insertions(+)
>  create mode 100644 libhinawa/src/Makefile.am
>  create mode 100644 libhinawa/src/hinawa_context.c
>  create mode 100644 libhinawa/src/hinawa_context.h
> 
> diff --git a/libhinawa/Makefile.am b/libhinawa/Makefile.am
> index e39f07b..05f5d58 100644
> --- a/libhinawa/Makefile.am
> +++ b/libhinawa/Makefile.am
> @@ -1,2 +1,5 @@
>  # Include m4 macros
>  ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS}
> +
> +SUBDIRS =					\
> +	src
> diff --git a/libhinawa/README b/libhinawa/README
> index 234ed91..db9b82a 100644
> --- a/libhinawa/README
> +++ b/libhinawa/README
> @@ -2,6 +2,7 @@ Requirements
>  - GNU Autoconf 2.62 or later
>  - GNU Automake 1.10.1 or later
>  - GNU libtool 2.2.6 or later
> +- Glib 2.32.4 or later
>  
>  How to build
>   $ ./autogen.sh
> diff --git a/libhinawa/configure.ac b/libhinawa/configure.ac
> index 2eeef0d..5ecb7ec 100644
> --- a/libhinawa/configure.ac
> +++ b/libhinawa/configure.ac
> @@ -19,6 +19,9 @@ AC_INIT([hinawa], [my_version], [o-takashi@sakamocchi.jp])
>  AC_CONFIG_AUX_DIR([config])
>  # The directory for M4 macros
>  AC_CONFIG_MACRO_DIR([m4])
> +
> +# The directory for sources
> +AC_CONFIG_SRCDIR([src])
>  # The header for variables with AC_DEFINE
>  AC_CONFIG_HEADERS([config.h])
>  
> @@ -39,9 +42,13 @@ AC_SUBST(LT_IFACE)
>  # Detect C language compiler
>  AC_PROG_CC
>  
> +# Glib 2.32 or later
> +AM_PATH_GLIB_2_0([2.32.4], [], [], [gobject])
> +
>  # The files generated from *.in
>  AC_CONFIG_FILES([
>    Makefile
> +  src/Makefile
>  ])
>  
>  # Generate scripts and launch
> diff --git a/libhinawa/src/Makefile.am b/libhinawa/src/Makefile.am
> new file mode 100644
> index 0000000..5673255
> --- /dev/null
> +++ b/libhinawa/src/Makefile.am
> @@ -0,0 +1,24 @@
> +# Remove auto-generated files when cleaning
> +CLEANFILES =
> +
> +AM_CPPFLAGS =					\
> +	 -I$(top_builddir)			\
> +	 -I$(top_srcdir)
> +
> +AM_CFLAGS =					\
> +	$(GLIB_CFLAGS)				\
> +	-Wall
> +
> +lib_LTLIBRARIES =				\
> +	libhinawa.la
> +
> +libhinawa_la_LDFLAGS =				\
> +	-version-info $(LT_IFACE)
> +
> +libhinawa_la_LIBADD =				\
> +	$(GLIB_LIBS)
> +
> +libhinawa_la_SOURCES =				\
> +	hinawa_context.c
> +
> +pkginclude_HEADERS =
> diff --git a/libhinawa/src/hinawa_context.c b/libhinawa/src/hinawa_context.c
> new file mode 100644
> index 0000000..dd20d21
> --- /dev/null
> +++ b/libhinawa/src/hinawa_context.c
> @@ -0,0 +1,60 @@
> +#include "hinawa_context.h"
> +
> +static GMainContext *ctx;
> +static GThread *thread;
> +
> +static gboolean running;
> +static gint counter;
> +
> +static gpointer run_main_loop(gpointer data)
> +{
> +	while (running)
> +		g_main_context_iteration(ctx, TRUE);
> +
> +	g_thread_exit(NULL);
> +
> +	return NULL;
> +}
> +
> +static GMainContext *get_my_context(GError **exception)
> +{
> +	if (ctx == NULL)
> +		ctx = g_main_context_new();
> +
> +	if (thread == NULL) {
> +		thread = g_thread_try_new("gmain", run_main_loop, NULL,
> +					  exception);
> +		if (*exception != NULL) {
> +			g_main_context_unref(ctx);
> +			ctx = NULL;
> +		}
> +	}
> +
> +	return ctx;
> +}
> +
> +gpointer hinawa_context_add_src(GSource *src, gint fd, GIOCondition event,
> +				GError **exception)
> +{
> +	GMainContext *ctx;
> +
> +	ctx = get_my_context(exception);
> +	if (*exception != NULL)
> +		return NULL;
> +	running = TRUE;
> +
> +	/* NOTE: The returned ID is never used. */
> +	g_source_attach(src, ctx);
> +
> +	return g_source_add_unix_fd(src, fd, event);
> +}
> +
> +void hinawa_context_remove_src(GSource *src)
> +{
> +	g_source_destroy(src);
> +	if (g_atomic_int_dec_and_test(&counter)) {
> +		running = FALSE;
> +		g_thread_join(thread);
> +		thread = NULL;
> +	}
> +}
> diff --git a/libhinawa/src/hinawa_context.h b/libhinawa/src/hinawa_context.h
> new file mode 100644
> index 0000000..97666c6
> --- /dev/null
> +++ b/libhinawa/src/hinawa_context.h
> @@ -0,0 +1,10 @@
> +#ifndef __ALSA_TOOLS_HINAWA_CONTEXT_H__
> +#define __ALSA_TOOLS_HINAWA_CONTEXT_H__
> +
> +#include <glib.h>
> +#include <glib-object.h>
> +
> +gpointer hinawa_context_add_src(GSource *src, gint fd, GIOCondition event,
> +				GError **exception);
> +
> +#endif
> 


------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
mailing list linux1394-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux1394-devel

  reply	other threads:[~2015-01-27 15:35 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-25 11:34 [RFC][PATCH 00/13] alsa-tools: libhinawa for control applications of FireWire devices Takashi Sakamoto
2015-01-25 11:34 ` [PATCH 01/13] libhinawa: add build definitions Takashi Sakamoto
2015-01-25 11:34 ` [PATCH 02/13] libhinawa: add hinawa context Takashi Sakamoto
2015-01-27 15:35   ` Takashi Sakamoto [this message]
2015-01-25 11:34 ` [PATCH 03/13] libhinawa: support GTK-Doc to generate references Takashi Sakamoto
2015-01-25 11:34 ` [PATCH 04/13] libhinawa: add 'fw_unit' object as a listener for FireWire unit Takashi Sakamoto
2015-01-25 11:34 ` [PATCH 05/13] libhinawa: support GObject Introspection for language bindings Takashi Sakamoto
2015-01-25 11:34 ` [PATCH 06/13] libhinawa: add 'fw_resp' object as a responder for FireWire transaction Takashi Sakamoto
2015-01-25 11:34 ` [PATCH 07/13] libhinawa: add 'fw_req' object as requester " Takashi Sakamoto
2015-01-25 11:34 ` [PATCH 08/13] libhinawa: add 'fw_fcp' object as a helper of FCP transaction Takashi Sakamoto
2015-01-25 11:34 ` [PATCH 09/13] libhinawa: add 'snd_unit' object as a listener for ALSA FireWire devices Takashi Sakamoto
2015-01-25 11:34 ` [PATCH 10/13] libhinawa: add 'snd_dice' object as a helper for Dice notification Takashi Sakamoto
2015-01-25 11:34 ` [PATCH 11/13] libhinawa: add 'snd_efw' object as a helper for EFW transaction Takashi Sakamoto
2015-01-25 11:34 ` [PATCH 12/13] libhinawa: add 'unit_query' as a query for ALSA FireWire devices Takashi Sakamoto
2015-01-25 11:34 ` [PATCH 13/13] libhinawa: add sample scripts Takashi Sakamoto
2015-01-25 12:14   ` [alsa-devel] " Alexander E. Patrakov
2015-01-27 15:09     ` Takashi Sakamoto
2015-01-27 15:16       ` Alexander E. Patrakov
2015-01-26 23:05 ` [FFADO-devel] [RFC][PATCH 00/13] alsa-tools: libhinawa for control applications of FireWire devices Jonathan Woithe
2015-03-20  9:28 ` Damien Zammit
2015-03-20 10:09   ` [alsa-devel] " Clemens Ladisch

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=54C7B03A.10901@sakamocchi.jp \
    --to=o-takashi@sakamocchi.jp \
    --cc=alsa-devel@alsa-project.org \
    --cc=clemens@ladisch.de \
    --cc=ffado-devel@lists.sf.net \
    --cc=linux1394-devel@lists.sourceforge.net \
    --cc=perex@perex.cz \
    --cc=tiwai@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.