mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-26 07:00:13 -05:00
Work on main loop
Make a main-loop object with associated helper functions to handle async methods. rtloop -> data_loop Handle async results a lot better. Remove REMOVE_MEM command. We don't need it. Handle stream memory updates better.
This commit is contained in:
parent
98dbb6424d
commit
8fac22afdb
26 changed files with 926 additions and 583 deletions
|
|
@ -421,7 +421,7 @@ refill_buffer (PinosConnection *conn, ConnectionBuffer *buf)
|
|||
buf->n_fds = (cmsg->cmsg_len - ((char *)CMSG_DATA (cmsg) - (char *)cmsg)) / sizeof (int);
|
||||
memcpy (buf->fds, CMSG_DATA (cmsg), buf->n_fds * sizeof (int));
|
||||
}
|
||||
PINOS_DEBUG_CONTROL ("connection %p: %d read %zd bytes and %d fds\n", conn, conn->fd, len, buf->n_fds);
|
||||
PINOS_DEBUG_CONTROL ("connection %p: %d read %zd bytes and %d fds", conn, conn->fd, len, buf->n_fds);
|
||||
|
||||
return TRUE;
|
||||
|
||||
|
|
@ -594,12 +594,6 @@ pinos_connection_parse_cmd (PinosConnection *conn,
|
|||
memcpy (command, conn->in.data, sizeof (PinosControlCmdAddMem));
|
||||
break;
|
||||
|
||||
case PINOS_CONTROL_CMD_REMOVE_MEM:
|
||||
if (conn->in.size < sizeof (PinosControlCmdRemoveMem))
|
||||
return FALSE;
|
||||
memcpy (command, conn->in.data, sizeof (PinosControlCmdRemoveMem));
|
||||
break;
|
||||
|
||||
case PINOS_CONTROL_CMD_USE_BUFFERS:
|
||||
connection_parse_use_buffers (conn, command);
|
||||
break;
|
||||
|
|
@ -748,11 +742,6 @@ pinos_connection_add_cmd (PinosConnection *conn,
|
|||
memcpy (p, command, sizeof (PinosControlCmdAddMem));
|
||||
break;
|
||||
|
||||
case PINOS_CONTROL_CMD_REMOVE_MEM:
|
||||
p = connection_add_cmd (conn, cmd, sizeof (PinosControlCmdRemoveMem));
|
||||
memcpy (p, command, sizeof (PinosControlCmdRemoveMem));
|
||||
break;
|
||||
|
||||
case PINOS_CONTROL_CMD_USE_BUFFERS:
|
||||
connection_add_use_buffers (conn, command);
|
||||
break;
|
||||
|
|
@ -830,7 +819,7 @@ pinos_connection_flush (PinosConnection *conn)
|
|||
buf->buffer_size -= len;
|
||||
buf->n_fds = 0;
|
||||
|
||||
PINOS_DEBUG_CONTROL ("connection %p: %d written %zd bytes and %u fds\n", conn, conn->fd, len, buf->n_fds);
|
||||
PINOS_DEBUG_CONTROL ("connection %p: %d written %zd bytes and %u fds", conn, conn->fd, len, buf->n_fds);
|
||||
|
||||
return TRUE;
|
||||
|
||||
|
|
|
|||
|
|
@ -52,8 +52,6 @@ typedef enum {
|
|||
|
||||
/* both */
|
||||
PINOS_CONTROL_CMD_ADD_MEM = 64,
|
||||
PINOS_CONTROL_CMD_REMOVE_MEM = 65,
|
||||
|
||||
PINOS_CONTROL_CMD_USE_BUFFERS = 66,
|
||||
PINOS_CONTROL_CMD_PROCESS_BUFFER = 67,
|
||||
|
||||
|
|
@ -146,13 +144,6 @@ typedef struct {
|
|||
size_t size;
|
||||
} PinosControlCmdAddMem;
|
||||
|
||||
/* PINOS_CONTROL_CMD_REMOVE_MEM */
|
||||
typedef struct {
|
||||
SpaDirection direction;
|
||||
uint32_t port_id;
|
||||
uint32_t mem_id;
|
||||
} PinosControlCmdRemoveMem;
|
||||
|
||||
typedef struct {
|
||||
uint32_t mem_id;
|
||||
off_t offset;
|
||||
|
|
|
|||
|
|
@ -1,84 +0,0 @@
|
|||
/* Pinos
|
||||
* Copyright (C) 2015 Wim Taymans <wim.taymans@gmail.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef __PINOS_MAIN_LOOP_H__
|
||||
#define __PINOS_MAIN_LOOP_H__
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define PINOS_TYPE_MAIN_LOOP (pinos_main_loop_get_type ())
|
||||
#define PINOS_IS_MAIN_LOOP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PINOS_TYPE_MAIN_LOOP))
|
||||
#define PINOS_IS_MAIN_LOOP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PINOS_TYPE_MAIN_LOOP))
|
||||
#define PINOS_MAIN_LOOP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PINOS_TYPE_MAIN_LOOP, PinosMainLoopClass))
|
||||
#define PINOS_MAIN_LOOP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PINOS_TYPE_MAIN_LOOP, PinosMainLoop))
|
||||
#define PINOS_MAIN_LOOP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PINOS_TYPE_MAIN_LOOP, PinosMainLoopClass))
|
||||
#define PINOS_MAIN_LOOP_CAST(obj) ((PinosMainLoop*)(obj))
|
||||
#define PINOS_MAIN_LOOP_CLASS_CAST(klass) ((PinosMainLoopClass*)(klass))
|
||||
|
||||
typedef struct _PinosMainLoop PinosMainLoop;
|
||||
typedef struct _PinosMainLoopClass PinosMainLoopClass;
|
||||
typedef struct _PinosMainLoopPrivate PinosMainLoopPrivate;
|
||||
|
||||
|
||||
/**
|
||||
* PinosMainLoop:
|
||||
*
|
||||
* Pinos main loop object class.
|
||||
*/
|
||||
struct _PinosMainLoop {
|
||||
GObject object;
|
||||
|
||||
PinosMainLoopPrivate *priv;
|
||||
};
|
||||
|
||||
/**
|
||||
* PinosMainLoopClass:
|
||||
*
|
||||
* Pinos main loop object class.
|
||||
*/
|
||||
struct _PinosMainLoopClass {
|
||||
GObjectClass parent_class;
|
||||
};
|
||||
|
||||
/* normal GObject stuff */
|
||||
GType pinos_main_loop_get_type (void);
|
||||
|
||||
PinosMainLoop * pinos_main_loop_new (GMainContext * context,
|
||||
const gchar *name);
|
||||
|
||||
GMainLoop * pinos_main_loop_get_impl (PinosMainLoop *loop);
|
||||
|
||||
gboolean pinos_main_loop_start (PinosMainLoop *loop, GError **error);
|
||||
void pinos_main_loop_stop (PinosMainLoop *loop);
|
||||
|
||||
void pinos_main_loop_lock (PinosMainLoop *loop);
|
||||
void pinos_main_loop_unlock (PinosMainLoop *loop);
|
||||
|
||||
void pinos_main_loop_wait (PinosMainLoop *loop);
|
||||
void pinos_main_loop_signal (PinosMainLoop *loop, gboolean wait_for_accept);
|
||||
void pinos_main_loop_accept (PinosMainLoop *loop);
|
||||
|
||||
gboolean pinos_main_loop_in_thread (PinosMainLoop *loop);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __PINOS_MAIN_LOOP_H__ */
|
||||
|
|
@ -2,12 +2,12 @@ pinos_headers = [
|
|||
'context.h',
|
||||
'format.h',
|
||||
'introspect.h',
|
||||
'mainloop.h',
|
||||
'pinos.h',
|
||||
'properties.h',
|
||||
'stream.h',
|
||||
'ringbuffer.h',
|
||||
'subscribe.h',
|
||||
'thread-mainloop.h',
|
||||
]
|
||||
|
||||
pinos_sources = [
|
||||
|
|
@ -15,13 +15,13 @@ pinos_sources = [
|
|||
'context.c',
|
||||
'format.c',
|
||||
'introspect.c',
|
||||
'mainloop.c',
|
||||
'properties.c',
|
||||
'serialize.c',
|
||||
'stream.c',
|
||||
'pinos.c',
|
||||
'ringbuffer.c',
|
||||
'subscribe.c',
|
||||
'thread-mainloop.c',
|
||||
gdbus_target,
|
||||
]
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ extern const char g_log_domain_pinos[];
|
|||
#include <pinos/client/context.h>
|
||||
#include <pinos/client/enumtypes.h>
|
||||
#include <pinos/client/introspect.h>
|
||||
#include <pinos/client/mainloop.h>
|
||||
#include <pinos/client/thread-mainloop.h>
|
||||
#include <pinos/client/properties.h>
|
||||
#include <pinos/client/ringbuffer.h>
|
||||
#include <pinos/client/stream.h>
|
||||
|
|
|
|||
|
|
@ -992,7 +992,7 @@ parse_connection (PinosStream *stream)
|
|||
{
|
||||
PinosControlCmdAddMem p;
|
||||
int fd;
|
||||
MemId mid;
|
||||
MemId mid, *m;
|
||||
|
||||
if (!pinos_connection_parse_cmd (conn, &p))
|
||||
break;
|
||||
|
|
@ -1001,27 +1001,25 @@ parse_connection (PinosStream *stream)
|
|||
if (fd == -1)
|
||||
break;
|
||||
|
||||
mid.id = p.mem_id;
|
||||
mid.fd = fd;
|
||||
mid.flags = p.flags;
|
||||
mid.ptr = NULL;
|
||||
mid.size = p.size;
|
||||
m = find_mem (stream, p.mem_id);
|
||||
if (m) {
|
||||
g_debug ("update mem %u, fd %d, flags %d, size %zd", p.mem_id, fd, p.flags, p.size);
|
||||
|
||||
g_debug ("add mem %u, fd %d, flags %d, size %zd", p.mem_id, fd, p.flags, p.size);
|
||||
g_array_append_val (priv->mem_ids, mid);
|
||||
break;
|
||||
}
|
||||
case PINOS_CONTROL_CMD_REMOVE_MEM:
|
||||
{
|
||||
PinosControlCmdRemoveMem p;
|
||||
MemId *mid;
|
||||
m->id = p.mem_id;
|
||||
m->fd = fd;
|
||||
m->flags = p.flags;
|
||||
m->ptr = NULL;
|
||||
m->size = p.size;
|
||||
} else {
|
||||
mid.id = p.mem_id;
|
||||
mid.fd = fd;
|
||||
mid.flags = p.flags;
|
||||
mid.ptr = NULL;
|
||||
mid.size = p.size;
|
||||
|
||||
if (!pinos_connection_parse_cmd (conn, &p))
|
||||
break;
|
||||
|
||||
g_debug ("stream %p: remove mem %d", stream, p.mem_id);
|
||||
if ((mid = find_mem (stream, p.mem_id)))
|
||||
mid->cleanup = true;
|
||||
g_debug ("add mem %u, fd %d, flags %d, size %zd", p.mem_id, fd, p.flags, p.size);
|
||||
g_array_append_val (priv->mem_ids, mid);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PINOS_CONTROL_CMD_USE_BUFFERS:
|
||||
|
|
@ -1181,7 +1179,6 @@ parse_rtconnection (PinosStream *stream)
|
|||
case PINOS_CONTROL_CMD_SET_FORMAT:
|
||||
case PINOS_CONTROL_CMD_SET_PROPERTY:
|
||||
case PINOS_CONTROL_CMD_ADD_MEM:
|
||||
case PINOS_CONTROL_CMD_REMOVE_MEM:
|
||||
case PINOS_CONTROL_CMD_USE_BUFFERS:
|
||||
case PINOS_CONTROL_CMD_NODE_COMMAND:
|
||||
g_warning ("got unexpected connection %d", cmd);
|
||||
|
|
|
|||
|
|
@ -18,9 +18,9 @@
|
|||
*/
|
||||
|
||||
#include "pinos.h"
|
||||
#include "mainloop.h"
|
||||
#include "thread-mainloop.h"
|
||||
|
||||
struct _PinosMainLoopPrivate
|
||||
struct _PinosThreadMainLoopPrivate
|
||||
{
|
||||
GMainContext *maincontext;
|
||||
GMainLoop *mainloop;
|
||||
|
|
@ -38,10 +38,10 @@ struct _PinosMainLoopPrivate
|
|||
gint n_waiting_for_accept;
|
||||
};
|
||||
|
||||
#define PINOS_MAIN_LOOP_GET_PRIVATE(obj) \
|
||||
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), PINOS_TYPE_MAIN_LOOP, PinosMainLoopPrivate))
|
||||
#define PINOS_THREAD_MAIN_LOOP_GET_PRIVATE(obj) \
|
||||
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), PINOS_TYPE_THREAD_MAIN_LOOP, PinosThreadMainLoopPrivate))
|
||||
|
||||
G_DEFINE_TYPE (PinosMainLoop, pinos_main_loop, G_TYPE_OBJECT);
|
||||
G_DEFINE_TYPE (PinosThreadMainLoop, pinos_thread_main_loop, G_TYPE_OBJECT);
|
||||
|
||||
enum
|
||||
{
|
||||
|
|
@ -52,13 +52,13 @@ enum
|
|||
};
|
||||
|
||||
static void
|
||||
pinos_main_loop_get_property (GObject *_object,
|
||||
pinos_thread_main_loop_get_property (GObject *_object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
PinosMainLoop *loop = PINOS_MAIN_LOOP (_object);
|
||||
PinosMainLoopPrivate *priv = loop->priv;
|
||||
PinosThreadMainLoop *loop = PINOS_THREAD_MAIN_LOOP (_object);
|
||||
PinosThreadMainLoopPrivate *priv = loop->priv;
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_MAIN_CONTEXT:
|
||||
|
|
@ -80,13 +80,13 @@ pinos_main_loop_get_property (GObject *_object,
|
|||
}
|
||||
|
||||
static void
|
||||
pinos_main_loop_set_property (GObject *_object,
|
||||
pinos_thread_main_loop_set_property (GObject *_object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
PinosMainLoop *loop = PINOS_MAIN_LOOP (_object);
|
||||
PinosMainLoopPrivate *priv = loop->priv;
|
||||
PinosThreadMainLoop *loop = PINOS_THREAD_MAIN_LOOP (_object);
|
||||
PinosThreadMainLoopPrivate *priv = loop->priv;
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_MAIN_CONTEXT:
|
||||
|
|
@ -104,22 +104,22 @@ pinos_main_loop_set_property (GObject *_object,
|
|||
}
|
||||
|
||||
static void
|
||||
pinos_main_loop_constructed (GObject * object)
|
||||
pinos_thread_main_loop_constructed (GObject * object)
|
||||
{
|
||||
PinosMainLoop *loop = PINOS_MAIN_LOOP (object);
|
||||
PinosMainLoopPrivate *priv = loop->priv;
|
||||
PinosThreadMainLoop *loop = PINOS_THREAD_MAIN_LOOP (object);
|
||||
PinosThreadMainLoopPrivate *priv = loop->priv;
|
||||
|
||||
priv->mainloop = g_main_loop_new (priv->maincontext, FALSE);
|
||||
g_debug ("mainloop %p: contructed %p %p", loop, priv->maincontext, priv->mainloop);
|
||||
g_debug ("thread-mainloop %p: contructed %p %p", loop, priv->maincontext, priv->mainloop);
|
||||
|
||||
G_OBJECT_CLASS (pinos_main_loop_parent_class)->constructed (object);
|
||||
G_OBJECT_CLASS (pinos_thread_main_loop_parent_class)->constructed (object);
|
||||
}
|
||||
|
||||
static void
|
||||
pinos_main_loop_finalize (GObject * object)
|
||||
pinos_thread_main_loop_finalize (GObject * object)
|
||||
{
|
||||
PinosMainLoop *loop = PINOS_MAIN_LOOP (object);
|
||||
PinosMainLoopPrivate *priv = loop->priv;
|
||||
PinosThreadMainLoop *loop = PINOS_THREAD_MAIN_LOOP (object);
|
||||
PinosThreadMainLoopPrivate *priv = loop->priv;
|
||||
|
||||
if (priv->maincontext)
|
||||
g_main_context_unref (priv->maincontext);
|
||||
|
|
@ -130,23 +130,23 @@ pinos_main_loop_finalize (GObject * object)
|
|||
g_cond_clear (&priv->cond);
|
||||
g_cond_clear (&priv->accept_cond);
|
||||
|
||||
G_OBJECT_CLASS (pinos_main_loop_parent_class)->finalize (object);
|
||||
G_OBJECT_CLASS (pinos_thread_main_loop_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
pinos_main_loop_class_init (PinosMainLoopClass * klass)
|
||||
pinos_thread_main_loop_class_init (PinosThreadMainLoopClass * klass)
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
g_type_class_add_private (klass, sizeof (PinosMainLoopPrivate));
|
||||
g_type_class_add_private (klass, sizeof (PinosThreadMainLoopPrivate));
|
||||
|
||||
gobject_class->constructed = pinos_main_loop_constructed;
|
||||
gobject_class->finalize = pinos_main_loop_finalize;
|
||||
gobject_class->set_property = pinos_main_loop_set_property;
|
||||
gobject_class->get_property = pinos_main_loop_get_property;
|
||||
gobject_class->constructed = pinos_thread_main_loop_constructed;
|
||||
gobject_class->finalize = pinos_thread_main_loop_finalize;
|
||||
gobject_class->set_property = pinos_thread_main_loop_set_property;
|
||||
gobject_class->get_property = pinos_thread_main_loop_get_property;
|
||||
|
||||
/**
|
||||
* PinosMainLoop:main-context
|
||||
* PinosThreadMainLoop:main-context
|
||||
*
|
||||
* The GMainContext of the loop.
|
||||
*/
|
||||
|
|
@ -160,7 +160,7 @@ pinos_main_loop_class_init (PinosMainLoopClass * klass)
|
|||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
/**
|
||||
* PinosMainLoop:name
|
||||
* PinosThreadMainLoop:name
|
||||
*
|
||||
* The name of the loop as specified at construction time.
|
||||
*/
|
||||
|
|
@ -174,7 +174,7 @@ pinos_main_loop_class_init (PinosMainLoopClass * klass)
|
|||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
/**
|
||||
* PinosMainLoop:main-loop
|
||||
* PinosThreadMainLoop:main-loop
|
||||
*
|
||||
* The GMainLoop of the loop.
|
||||
*/
|
||||
|
|
@ -189,9 +189,9 @@ pinos_main_loop_class_init (PinosMainLoopClass * klass)
|
|||
}
|
||||
|
||||
static void
|
||||
pinos_main_loop_init (PinosMainLoop * loop)
|
||||
pinos_thread_main_loop_init (PinosThreadMainLoop * loop)
|
||||
{
|
||||
PinosMainLoopPrivate *priv = loop->priv = PINOS_MAIN_LOOP_GET_PRIVATE (loop);
|
||||
PinosThreadMainLoopPrivate *priv = loop->priv = PINOS_THREAD_MAIN_LOOP_GET_PRIVATE (loop);
|
||||
|
||||
g_mutex_init (&priv->lock);
|
||||
g_cond_init (&priv->cond);
|
||||
|
|
@ -199,21 +199,21 @@ pinos_main_loop_init (PinosMainLoop * loop)
|
|||
}
|
||||
|
||||
/**
|
||||
* pinos_main_loop_new:
|
||||
* pinos_thread_main_loop_new:
|
||||
* @context: a #GMainContext
|
||||
* @name: a thread name
|
||||
*
|
||||
* Make a new #PinosMainLoop that will run a mainloop on @context in
|
||||
* Make a new #PinosThreadMainLoop that will run a mainloop on @context in
|
||||
* a thread with @name.
|
||||
*
|
||||
* Returns: a #PinosMainLoop
|
||||
* Returns: a #PinosThreadMainLoop
|
||||
*/
|
||||
PinosMainLoop *
|
||||
pinos_main_loop_new (GMainContext * context, const gchar *name)
|
||||
PinosThreadMainLoop *
|
||||
pinos_thread_main_loop_new (GMainContext * context, const gchar *name)
|
||||
{
|
||||
PinosMainLoop *loop;
|
||||
PinosThreadMainLoop *loop;
|
||||
|
||||
loop = g_object_new (PINOS_TYPE_MAIN_LOOP,
|
||||
loop = g_object_new (PINOS_TYPE_THREAD_MAIN_LOOP,
|
||||
"main-context", context,
|
||||
"name", name,
|
||||
NULL);
|
||||
|
|
@ -221,8 +221,8 @@ pinos_main_loop_new (GMainContext * context, const gchar *name)
|
|||
}
|
||||
|
||||
/**
|
||||
* pinos_main_loop_get_impl:
|
||||
* @loop: a #PinosMainLoop
|
||||
* pinos_thread_main_loop_get_impl:
|
||||
* @loop: a #PinosThreadMainLoop
|
||||
*
|
||||
* Get the #GMainLoop used by @loop.
|
||||
*
|
||||
|
|
@ -230,11 +230,11 @@ pinos_main_loop_new (GMainContext * context, const gchar *name)
|
|||
* @loop is valid.
|
||||
*/
|
||||
GMainLoop *
|
||||
pinos_main_loop_get_impl (PinosMainLoop *loop)
|
||||
pinos_thread_main_loop_get_impl (PinosThreadMainLoop *loop)
|
||||
{
|
||||
PinosMainLoopPrivate *priv;
|
||||
PinosThreadMainLoopPrivate *priv;
|
||||
|
||||
g_return_val_if_fail (PINOS_IS_MAIN_LOOP (loop), NULL);
|
||||
g_return_val_if_fail (PINOS_IS_THREAD_MAIN_LOOP (loop), NULL);
|
||||
|
||||
priv = loop->priv;
|
||||
|
||||
|
|
@ -247,8 +247,8 @@ static gint
|
|||
do_poll (GPollFD *ufds, guint nfsd, gint timeout_)
|
||||
{
|
||||
gint res;
|
||||
PinosMainLoop *loop = g_private_get (&loop_key);
|
||||
PinosMainLoopPrivate *priv = loop->priv;
|
||||
PinosThreadMainLoop *loop = g_private_get (&loop_key);
|
||||
PinosThreadMainLoopPrivate *priv = loop->priv;
|
||||
|
||||
g_mutex_unlock (&priv->lock);
|
||||
res = priv->poll_func (ufds, nfsd, timeout_);
|
||||
|
|
@ -258,9 +258,9 @@ do_poll (GPollFD *ufds, guint nfsd, gint timeout_)
|
|||
}
|
||||
|
||||
static gpointer
|
||||
handle_mainloop (PinosMainLoop *loop)
|
||||
handle_mainloop (PinosThreadMainLoop *loop)
|
||||
{
|
||||
PinosMainLoopPrivate *priv = loop->priv;
|
||||
PinosThreadMainLoopPrivate *priv = loop->priv;
|
||||
|
||||
g_mutex_lock (&priv->lock);
|
||||
g_private_set (&loop_key, loop);
|
||||
|
|
@ -269,9 +269,9 @@ handle_mainloop (PinosMainLoop *loop)
|
|||
g_main_context_set_poll_func (priv->maincontext, do_poll);
|
||||
|
||||
g_main_context_push_thread_default (priv->maincontext);
|
||||
g_debug ("mainloop %p: run mainloop %p context %p", loop, priv->mainloop, priv->maincontext);
|
||||
g_debug ("thread-mainloop %p: run mainloop %p context %p", loop, priv->mainloop, priv->maincontext);
|
||||
g_main_loop_run (priv->mainloop);
|
||||
g_debug ("mainloop %p: done", loop);
|
||||
g_debug ("thread-mainloop %p: done", loop);
|
||||
g_main_context_pop_thread_default (priv->maincontext);
|
||||
|
||||
g_main_context_set_poll_func (priv->maincontext, priv->poll_func);
|
||||
|
|
@ -283,8 +283,8 @@ handle_mainloop (PinosMainLoop *loop)
|
|||
|
||||
|
||||
/**
|
||||
* pinos_main_loop_start:
|
||||
* @loop: a #PinosMainLoop
|
||||
* pinos_thread_main_loop_start:
|
||||
* @loop: a #PinosThreadMainLoop
|
||||
* @error: am optional #GError
|
||||
*
|
||||
* Start the thread to handle @loop.
|
||||
|
|
@ -293,11 +293,11 @@ handle_mainloop (PinosMainLoop *loop)
|
|||
* and @error will contain more information.
|
||||
*/
|
||||
gboolean
|
||||
pinos_main_loop_start (PinosMainLoop *loop, GError **error)
|
||||
pinos_thread_main_loop_start (PinosThreadMainLoop *loop, GError **error)
|
||||
{
|
||||
PinosMainLoopPrivate *priv;
|
||||
PinosThreadMainLoopPrivate *priv;
|
||||
|
||||
g_return_val_if_fail (PINOS_IS_MAIN_LOOP (loop), FALSE);
|
||||
g_return_val_if_fail (PINOS_IS_THREAD_MAIN_LOOP (loop), FALSE);
|
||||
priv = loop->priv;
|
||||
g_return_val_if_fail (priv->thread == NULL, FALSE);
|
||||
|
||||
|
|
@ -307,21 +307,21 @@ pinos_main_loop_start (PinosMainLoop *loop, GError **error)
|
|||
}
|
||||
|
||||
/**
|
||||
* pinos_main_loop_stop:
|
||||
* @loop: a #PinosMainLoop
|
||||
* pinos_thread_main_loop_stop:
|
||||
* @loop: a #PinosThreadMainLoop
|
||||
*
|
||||
* Quit the main loop and stop its thread.
|
||||
*/
|
||||
void
|
||||
pinos_main_loop_stop (PinosMainLoop *loop)
|
||||
pinos_thread_main_loop_stop (PinosThreadMainLoop *loop)
|
||||
{
|
||||
PinosMainLoopPrivate *priv;
|
||||
PinosThreadMainLoopPrivate *priv;
|
||||
|
||||
g_return_if_fail (PINOS_IS_MAIN_LOOP (loop));
|
||||
g_return_if_fail (PINOS_IS_THREAD_MAIN_LOOP (loop));
|
||||
priv = loop->priv;
|
||||
|
||||
g_return_if_fail (priv->thread != NULL);
|
||||
g_return_if_fail (!pinos_main_loop_in_thread (loop));
|
||||
g_return_if_fail (!pinos_thread_main_loop_in_thread (loop));
|
||||
|
||||
g_mutex_lock (&priv->lock);
|
||||
g_main_loop_quit (priv->mainloop);
|
||||
|
|
@ -332,54 +332,54 @@ pinos_main_loop_stop (PinosMainLoop *loop)
|
|||
}
|
||||
|
||||
/**
|
||||
* pinos_main_loop_lock:
|
||||
* @loop: a #PinosMainLoop
|
||||
* pinos_thread_main_loop_lock:
|
||||
* @loop: a #PinosThreadMainLoop
|
||||
*
|
||||
* Lock the mutex associated with @loop.
|
||||
*/
|
||||
void
|
||||
pinos_main_loop_lock (PinosMainLoop *loop)
|
||||
pinos_thread_main_loop_lock (PinosThreadMainLoop *loop)
|
||||
{
|
||||
PinosMainLoopPrivate *priv;
|
||||
PinosThreadMainLoopPrivate *priv;
|
||||
|
||||
g_return_if_fail (PINOS_IS_MAIN_LOOP (loop));
|
||||
g_return_if_fail (PINOS_IS_THREAD_MAIN_LOOP (loop));
|
||||
priv = loop->priv;
|
||||
g_return_if_fail (!pinos_main_loop_in_thread (loop));
|
||||
g_return_if_fail (!pinos_thread_main_loop_in_thread (loop));
|
||||
|
||||
g_mutex_lock (&priv->lock);
|
||||
}
|
||||
|
||||
/**
|
||||
* pinos_main_loop_unlock:
|
||||
* @loop: a #PinosMainLoop
|
||||
* pinos_thread_main_loop_unlock:
|
||||
* @loop: a #PinosThreadMainLoop
|
||||
*
|
||||
* Unlock the mutex associated with @loop.
|
||||
*/
|
||||
void
|
||||
pinos_main_loop_unlock (PinosMainLoop *loop)
|
||||
pinos_thread_main_loop_unlock (PinosThreadMainLoop *loop)
|
||||
{
|
||||
PinosMainLoopPrivate *priv;
|
||||
PinosThreadMainLoopPrivate *priv;
|
||||
|
||||
g_return_if_fail (PINOS_IS_MAIN_LOOP (loop));
|
||||
g_return_if_fail (PINOS_IS_THREAD_MAIN_LOOP (loop));
|
||||
priv = loop->priv;
|
||||
g_return_if_fail (!pinos_main_loop_in_thread (loop));
|
||||
g_return_if_fail (!pinos_thread_main_loop_in_thread (loop));
|
||||
|
||||
g_mutex_unlock (&priv->lock);
|
||||
}
|
||||
|
||||
/**
|
||||
* pinos_main_loop_signal:
|
||||
* @loop: a #PinosMainLoop
|
||||
* pinos_thread_main_loop_signal:
|
||||
* @loop: a #PinosThreadMainLoop
|
||||
*
|
||||
* Signal the main thread of @loop. If @wait_for_accept is %TRUE,
|
||||
* this function waits until pinos_main_loop_accept() is called.
|
||||
* this function waits until pinos_thread_main_loop_accept() is called.
|
||||
*/
|
||||
void
|
||||
pinos_main_loop_signal (PinosMainLoop *loop, gboolean wait_for_accept)
|
||||
pinos_thread_main_loop_signal (PinosThreadMainLoop *loop, gboolean wait_for_accept)
|
||||
{
|
||||
PinosMainLoopPrivate *priv;
|
||||
PinosThreadMainLoopPrivate *priv;
|
||||
|
||||
g_return_if_fail (PINOS_IS_MAIN_LOOP (loop));
|
||||
g_return_if_fail (PINOS_IS_THREAD_MAIN_LOOP (loop));
|
||||
priv = loop->priv;
|
||||
|
||||
if (priv->n_waiting > 0)
|
||||
|
|
@ -394,19 +394,19 @@ pinos_main_loop_signal (PinosMainLoop *loop, gboolean wait_for_accept)
|
|||
}
|
||||
|
||||
/**
|
||||
* pinos_main_loop_wait:
|
||||
* @loop: a #PinosMainLoop
|
||||
* pinos_thread_main_loop_wait:
|
||||
* @loop: a #PinosThreadMainLoop
|
||||
*
|
||||
* Wait for the loop thread to call pinos_main_loop_signal().
|
||||
* Wait for the loop thread to call pinos_thread_main_loop_signal().
|
||||
*/
|
||||
void
|
||||
pinos_main_loop_wait (PinosMainLoop *loop)
|
||||
pinos_thread_main_loop_wait (PinosThreadMainLoop *loop)
|
||||
{
|
||||
PinosMainLoopPrivate *priv;
|
||||
PinosThreadMainLoopPrivate *priv;
|
||||
|
||||
g_return_if_fail (PINOS_IS_MAIN_LOOP (loop));
|
||||
g_return_if_fail (PINOS_IS_THREAD_MAIN_LOOP (loop));
|
||||
priv = loop->priv;
|
||||
g_return_if_fail (!pinos_main_loop_in_thread (loop));
|
||||
g_return_if_fail (!pinos_thread_main_loop_in_thread (loop));
|
||||
|
||||
priv->n_waiting ++;
|
||||
|
||||
|
|
@ -417,19 +417,19 @@ pinos_main_loop_wait (PinosMainLoop *loop)
|
|||
}
|
||||
|
||||
/**
|
||||
* pinos_main_loop_accept:
|
||||
* @loop: a #PinosMainLoop
|
||||
* pinos_thread_main_loop_accept:
|
||||
* @loop: a #PinosThreadMainLoop
|
||||
*
|
||||
* Signal the loop thread waiting for accept with pinos_main_loop_signal().
|
||||
* Signal the loop thread waiting for accept with pinos_thread_main_loop_signal().
|
||||
*/
|
||||
void
|
||||
pinos_main_loop_accept (PinosMainLoop *loop)
|
||||
pinos_thread_main_loop_accept (PinosThreadMainLoop *loop)
|
||||
{
|
||||
PinosMainLoopPrivate *priv;
|
||||
PinosThreadMainLoopPrivate *priv;
|
||||
|
||||
g_return_if_fail (PINOS_IS_MAIN_LOOP (loop));
|
||||
g_return_if_fail (PINOS_IS_THREAD_MAIN_LOOP (loop));
|
||||
priv = loop->priv;
|
||||
g_return_if_fail (!pinos_main_loop_in_thread (loop));
|
||||
g_return_if_fail (!pinos_thread_main_loop_in_thread (loop));
|
||||
|
||||
g_assert (priv->n_waiting_for_accept > 0);
|
||||
priv->n_waiting_for_accept--;
|
||||
|
|
@ -438,17 +438,17 @@ pinos_main_loop_accept (PinosMainLoop *loop)
|
|||
}
|
||||
|
||||
/**
|
||||
* pinos_main_loop_in_thread:
|
||||
* @loop: a #PinosMainLoop
|
||||
* pinos_thread_main_loop_in_thread:
|
||||
* @loop: a #PinosThreadMainLoop
|
||||
*
|
||||
* Check if we are inside the thread of @loop.
|
||||
*
|
||||
* Returns: %TRUE when called inside the thread of @loop.
|
||||
*/
|
||||
gboolean
|
||||
pinos_main_loop_in_thread (PinosMainLoop *loop)
|
||||
pinos_thread_main_loop_in_thread (PinosThreadMainLoop *loop)
|
||||
{
|
||||
g_return_val_if_fail (PINOS_IS_MAIN_LOOP (loop), FALSE);
|
||||
g_return_val_if_fail (PINOS_IS_THREAD_MAIN_LOOP (loop), FALSE);
|
||||
|
||||
return g_thread_self() == loop->priv->thread;
|
||||
}
|
||||
84
pinos/client/thread-mainloop.h
Normal file
84
pinos/client/thread-mainloop.h
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
/* Pinos
|
||||
* Copyright (C) 2015 Wim Taymans <wim.taymans@gmail.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef __PINOS_THREAD_MAIN_LOOP_H__
|
||||
#define __PINOS_THREAD_MAIN_LOOP_H__
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define PINOS_TYPE_THREAD_MAIN_LOOP (pinos_thread_main_loop_get_type ())
|
||||
#define PINOS_IS_THREAD_MAIN_LOOP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PINOS_TYPE_THREAD_MAIN_LOOP))
|
||||
#define PINOS_IS_THREAD_MAIN_LOOP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PINOS_TYPE_THREAD_MAIN_LOOP))
|
||||
#define PINOS_THREAD_MAIN_LOOP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PINOS_TYPE_THREAD_MAIN_LOOP, PinosThreadMainLoopClass))
|
||||
#define PINOS_THREAD_MAIN_LOOP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PINOS_TYPE_THREAD_MAIN_LOOP, PinosThreadMainLoop))
|
||||
#define PINOS_THREAD_MAIN_LOOP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PINOS_TYPE_THREAD_MAIN_LOOP, PinosThreadMainLoopClass))
|
||||
#define PINOS_THREAD_MAIN_LOOP_CAST(obj) ((PinosThreadMainLoop*)(obj))
|
||||
#define PINOS_THREAD_MAIN_LOOP_CLASS_CAST(klass) ((PinosThreadMainLoopClass*)(klass))
|
||||
|
||||
typedef struct _PinosThreadMainLoop PinosThreadMainLoop;
|
||||
typedef struct _PinosThreadMainLoopClass PinosThreadMainLoopClass;
|
||||
typedef struct _PinosThreadMainLoopPrivate PinosThreadMainLoopPrivate;
|
||||
|
||||
|
||||
/**
|
||||
* PinosThreadMainLoop:
|
||||
*
|
||||
* Pinos main loop object class.
|
||||
*/
|
||||
struct _PinosThreadMainLoop {
|
||||
GObject object;
|
||||
|
||||
PinosThreadMainLoopPrivate *priv;
|
||||
};
|
||||
|
||||
/**
|
||||
* PinosThreadMainLoopClass:
|
||||
*
|
||||
* Pinos main loop object class.
|
||||
*/
|
||||
struct _PinosThreadMainLoopClass {
|
||||
GObjectClass parent_class;
|
||||
};
|
||||
|
||||
/* normal GObject stuff */
|
||||
GType pinos_thread_main_loop_get_type (void);
|
||||
|
||||
PinosThreadMainLoop * pinos_thread_main_loop_new (GMainContext * context,
|
||||
const gchar *name);
|
||||
|
||||
GMainLoop * pinos_thread_main_loop_get_impl (PinosThreadMainLoop *loop);
|
||||
|
||||
gboolean pinos_thread_main_loop_start (PinosThreadMainLoop *loop, GError **error);
|
||||
void pinos_thread_main_loop_stop (PinosThreadMainLoop *loop);
|
||||
|
||||
void pinos_thread_main_loop_lock (PinosThreadMainLoop *loop);
|
||||
void pinos_thread_main_loop_unlock (PinosThreadMainLoop *loop);
|
||||
|
||||
void pinos_thread_main_loop_wait (PinosThreadMainLoop *loop);
|
||||
void pinos_thread_main_loop_signal (PinosThreadMainLoop *loop, gboolean wait_for_accept);
|
||||
void pinos_thread_main_loop_accept (PinosThreadMainLoop *loop);
|
||||
|
||||
gboolean pinos_thread_main_loop_in_thread (PinosThreadMainLoop *loop);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __PINOS_THREAD_MAIN_LOOP_H__ */
|
||||
Loading…
Add table
Add a link
Reference in a new issue