mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-18 07:00:06 -05:00
Remove SpaQueue, use SpaList instead
This commit is contained in:
parent
89bc235924
commit
d0f95fc323
20 changed files with 153 additions and 237 deletions
|
|
@ -42,7 +42,7 @@ struct _PinosArray {
|
|||
#define pinos_array_get_unchecked(a,idx,t) pinos_array_get_unchecked_s(a,idx,sizeof(t),t)
|
||||
#define pinos_array_check_index(a,idx,t) pinos_array_check_index_s(a,idx,sizeof(t))
|
||||
|
||||
#define PINOS_ARRAY_FOREACH(pos, array) \
|
||||
#define pinos_array_for_each(pos, array) \
|
||||
for (pos = (array)->data; \
|
||||
(const char *) pos < ((const char *) (array)->data + (array)->size); \
|
||||
(pos)++)
|
||||
|
|
|
|||
|
|
@ -1,83 +0,0 @@
|
|||
/* Simple Plugin API
|
||||
* Copyright (C) 2016 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_LIST_H__
|
||||
#define __PINOS_LIST_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct _PinosList PinosList;
|
||||
|
||||
#include <spa/defs.h>
|
||||
|
||||
struct _PinosList {
|
||||
PinosList *next;
|
||||
PinosList *prev;
|
||||
};
|
||||
|
||||
static inline void
|
||||
pinos_list_init (PinosList *list)
|
||||
{
|
||||
list->next = list;
|
||||
list->prev = list;
|
||||
}
|
||||
|
||||
static inline void
|
||||
pinos_list_insert (PinosList *list,
|
||||
PinosList *elem)
|
||||
{
|
||||
elem->prev = list;
|
||||
elem->next = list->next;
|
||||
list->next = elem;
|
||||
elem->next->prev = elem;
|
||||
}
|
||||
|
||||
static inline void
|
||||
pinos_list_remove (PinosList *elem)
|
||||
{
|
||||
elem->prev->next = elem->next;
|
||||
elem->next->prev = elem->prev;
|
||||
elem->next = NULL;
|
||||
elem->prev = NULL;
|
||||
}
|
||||
|
||||
#define PINOS_CONTAINER_OF(ptr, sample, member) \
|
||||
(__typeof__(sample))((char *)(ptr) - \
|
||||
offsetof(__typeof__(*sample), member))
|
||||
|
||||
#define PINOS_LIST_FOREACH(pos, head, member) \
|
||||
for (pos = PINOS_CONTAINER_OF((head)->next, pos, member); \
|
||||
&pos->member != (head); \
|
||||
pos = PINOS_CONTAINER_OF(pos->member.next, pos, member))
|
||||
|
||||
#define PINOS_LIST_FOREACH_SAFE(pos, tmp, head, member) \
|
||||
for (pos = PINOS_CONTAINER_OF((head)->next, pos, member), \
|
||||
tmp = PINOS_CONTAINER_OF((pos)->member.next, tmp, member); \
|
||||
&pos->member != (head); \
|
||||
pos = tmp, \
|
||||
tmp = PINOS_CONTAINER_OF(pos->member.next, tmp, member))
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* __PINOS_LIST_H__ */
|
||||
|
|
@ -20,7 +20,7 @@
|
|||
#ifndef __PINOS_SIGNAL_H__
|
||||
#define __PINOS_SIGNAL_H__
|
||||
|
||||
#include <pinos/client/list.h>
|
||||
#include <spa/include/spa/list.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
@ -30,26 +30,26 @@ typedef struct _PinosSignal PinosSignal;
|
|||
typedef struct _PinosListener PinosListener;
|
||||
|
||||
struct _PinosListener {
|
||||
PinosList link;
|
||||
SpaList link;
|
||||
void (*notify) (PinosListener *listener, void *data);
|
||||
void *user_data;
|
||||
};
|
||||
|
||||
struct _PinosSignal {
|
||||
PinosList listeners;
|
||||
SpaList listeners;
|
||||
};
|
||||
|
||||
static inline void
|
||||
pinos_signal_init (PinosSignal *signal)
|
||||
{
|
||||
pinos_list_init (&signal->listeners);
|
||||
spa_list_init (&signal->listeners);
|
||||
}
|
||||
|
||||
static inline void
|
||||
pinos_signal_add (PinosSignal *signal,
|
||||
PinosListener *listener)
|
||||
{
|
||||
pinos_list_insert (signal->listeners.prev, &listener->link);
|
||||
spa_list_insert (signal->listeners.prev, &listener->link);
|
||||
}
|
||||
|
||||
static inline void
|
||||
|
|
@ -58,7 +58,7 @@ pinos_signal_emit (PinosSignal *signal,
|
|||
{
|
||||
PinosListener *l, *next;
|
||||
|
||||
PINOS_LIST_FOREACH_SAFE (l, next, &signal->listeners, link)
|
||||
spa_list_for_each_safe (l, next, &signal->listeners, link)
|
||||
l->notify (l, data);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -142,7 +142,7 @@ clear_buffers (PinosStream *stream)
|
|||
PinosStreamPrivate *priv = stream->priv;
|
||||
BufferId *bid;
|
||||
|
||||
PINOS_ARRAY_FOREACH (bid, &priv->buffer_ids) {
|
||||
pinos_array_for_each (bid, &priv->buffer_ids) {
|
||||
g_signal_emit (stream, signals[SIGNAL_REMOVE_BUFFER], 0, bid->id);
|
||||
bid->buf = NULL;
|
||||
}
|
||||
|
|
@ -730,7 +730,7 @@ find_mem (PinosStream *stream, uint32_t id)
|
|||
PinosStreamPrivate *priv = stream->priv;
|
||||
MemId *mid;
|
||||
|
||||
PINOS_ARRAY_FOREACH (mid, &priv->mem_ids) {
|
||||
pinos_array_for_each (mid, &priv->mem_ids) {
|
||||
if (mid->id == id)
|
||||
return mid;
|
||||
}
|
||||
|
|
@ -747,7 +747,7 @@ find_buffer (PinosStream *stream, uint32_t id)
|
|||
} else {
|
||||
BufferId *bid;
|
||||
|
||||
PINOS_ARRAY_FOREACH (bid, &priv->buffer_ids) {
|
||||
pinos_array_for_each (bid, &priv->buffer_ids) {
|
||||
if (bid->id == id)
|
||||
return bid;
|
||||
}
|
||||
|
|
@ -1706,7 +1706,7 @@ pinos_stream_get_empty_buffer (PinosStream *stream)
|
|||
priv = stream->priv;
|
||||
g_return_val_if_fail (priv->direction == SPA_DIRECTION_OUTPUT, FALSE);
|
||||
|
||||
PINOS_ARRAY_FOREACH (bid, &priv->buffer_ids) {
|
||||
pinos_array_for_each (bid, &priv->buffer_ids) {
|
||||
if (!bid->used)
|
||||
return bid->id;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,6 @@
|
|||
#include "pinos/server/client-node.h"
|
||||
|
||||
#include "spa/include/spa/node.h"
|
||||
#include "spa/include/spa/queue.h"
|
||||
#include "spa/lib/memfd-wrappers.h"
|
||||
|
||||
#define MAX_INPUTS 64
|
||||
|
|
@ -87,8 +86,6 @@ typedef struct {
|
|||
|
||||
uint32_t buffer_mem_id;
|
||||
PinosMemblock buffer_mem;
|
||||
|
||||
SpaQueue ready;
|
||||
} SpaProxyPort;
|
||||
|
||||
struct _SpaProxy
|
||||
|
|
@ -169,7 +166,6 @@ clear_buffers (SpaProxy *this, SpaProxyPort *port)
|
|||
pinos_memblock_free (&port->buffer_mem);
|
||||
|
||||
port->n_buffers = 0;
|
||||
SPA_QUEUE_INIT (&port->ready);
|
||||
}
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -211,7 +211,6 @@ pinos_client_dispose (GObject * object)
|
|||
g_list_free_full (copy, g_object_unref);
|
||||
g_list_free (priv->objects);
|
||||
|
||||
pinos_registry_remove_object (&priv->daemon->registry, &client->object);
|
||||
client_unregister_object (client);
|
||||
|
||||
G_OBJECT_CLASS (pinos_client_parent_class)->dispose (object);
|
||||
|
|
@ -224,6 +223,9 @@ pinos_client_finalize (GObject * object)
|
|||
PinosClientPrivate *priv = client->priv;
|
||||
|
||||
pinos_log_debug ("client %p: finalize", client);
|
||||
|
||||
pinos_registry_remove_object (&priv->daemon->registry, &client->object);
|
||||
|
||||
g_clear_object (&priv->daemon);
|
||||
g_clear_object (&priv->iface);
|
||||
g_free (priv->sender);
|
||||
|
|
|
|||
|
|
@ -735,8 +735,8 @@ pinos_daemon_get_property (GObject *_object,
|
|||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
PinosDaemon *daemon = PINOS_DAEMON (_object);
|
||||
PinosDaemonPrivate *priv = daemon->priv;
|
||||
PinosDaemon *this = PINOS_DAEMON (_object);
|
||||
PinosDaemonPrivate *priv = this->priv;
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_PROPERTIES:
|
||||
|
|
@ -752,7 +752,7 @@ pinos_daemon_get_property (GObject *_object,
|
|||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (daemon, prop_id, pspec);
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (this, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -763,8 +763,8 @@ pinos_daemon_set_property (GObject *_object,
|
|||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
PinosDaemon *daemon = PINOS_DAEMON (_object);
|
||||
PinosDaemonPrivate *priv = daemon->priv;
|
||||
PinosDaemon *this = PINOS_DAEMON (_object);
|
||||
PinosDaemonPrivate *priv = this->priv;
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_PROPERTIES:
|
||||
|
|
@ -774,7 +774,7 @@ pinos_daemon_set_property (GObject *_object,
|
|||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (daemon, prop_id, pspec);
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (this, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -811,7 +811,6 @@ pinos_daemon_dispose (GObject * object)
|
|||
|
||||
pinos_daemon_stop (this);
|
||||
|
||||
pinos_registry_remove_object (&this->registry, &this->object);
|
||||
|
||||
G_OBJECT_CLASS (pinos_daemon_parent_class)->dispose (object);
|
||||
}
|
||||
|
|
@ -819,10 +818,13 @@ pinos_daemon_dispose (GObject * object)
|
|||
static void
|
||||
pinos_daemon_finalize (GObject * object)
|
||||
{
|
||||
PinosDaemon *daemon = PINOS_DAEMON_CAST (object);
|
||||
PinosDaemonPrivate *priv = daemon->priv;
|
||||
PinosDaemon *this = PINOS_DAEMON_CAST (object);
|
||||
PinosDaemonPrivate *priv = this->priv;
|
||||
|
||||
pinos_log_debug ("daemon %p: finalize", object);
|
||||
|
||||
pinos_registry_remove_object (&this->registry, &this->object);
|
||||
|
||||
g_clear_object (&priv->server_manager);
|
||||
g_clear_object (&priv->iface);
|
||||
g_clear_object (&priv->data_loop);
|
||||
|
|
@ -888,11 +890,12 @@ pinos_daemon_init (PinosDaemon * daemon)
|
|||
g_signal_connect (priv->iface, "handle-create-node", (GCallback) handle_create_node, daemon);
|
||||
g_signal_connect (priv->iface, "handle-create-client-node", (GCallback) handle_create_client_node, daemon);
|
||||
|
||||
priv->object_added.notify = on_registry_object_added;
|
||||
priv->object_removed.notify = on_registry_object_removed;
|
||||
|
||||
pinos_registry_init (&daemon->registry);
|
||||
|
||||
priv->object_added.notify = on_registry_object_added;
|
||||
pinos_signal_add (&daemon->registry.object_added, &priv->object_added);
|
||||
|
||||
priv->object_removed.notify = on_registry_object_removed;
|
||||
pinos_signal_add (&daemon->registry.object_removed, &priv->object_removed);
|
||||
|
||||
priv->server_manager = g_dbus_object_manager_server_new (PINOS_DBUS_OBJECT_PREFIX);
|
||||
|
|
|
|||
|
|
@ -882,8 +882,6 @@ pinos_link_dispose (GObject * object)
|
|||
if (this->output)
|
||||
pinos_port_unlink (this->output, this);
|
||||
|
||||
pinos_registry_remove_object (&priv->daemon->registry, &this->object);
|
||||
|
||||
link_unregister_object (this);
|
||||
|
||||
pinos_main_loop_defer_cancel (priv->main_loop, this, 0);
|
||||
|
|
@ -898,6 +896,9 @@ pinos_link_finalize (GObject * object)
|
|||
PinosLinkPrivate *priv = this->priv;
|
||||
|
||||
pinos_log_debug ("link %p: finalize", this);
|
||||
|
||||
pinos_registry_remove_object (&priv->daemon->registry, &this->object);
|
||||
|
||||
g_clear_object (&priv->daemon);
|
||||
g_clear_object (&priv->iface);
|
||||
g_free (priv->object_path);
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
#include <gio/gio.h>
|
||||
|
||||
#include "spa/include/spa/queue.h"
|
||||
#include "spa/include/spa/list.h"
|
||||
#include "spa/include/spa/ringbuffer.h"
|
||||
#include "pinos/client/log.h"
|
||||
#include "pinos/server/main-loop.h"
|
||||
|
|
@ -54,7 +54,7 @@ struct _WorkItem {
|
|||
PinosDeferFunc func;
|
||||
gpointer *data;
|
||||
GDestroyNotify notify;
|
||||
WorkItem *next;
|
||||
SpaList list;
|
||||
};
|
||||
|
||||
struct _PinosMainLoopPrivate
|
||||
|
|
@ -70,7 +70,7 @@ struct _PinosMainLoopPrivate
|
|||
SpaPollFd fds[1];
|
||||
SpaPollItem wakeup;
|
||||
|
||||
SpaQueue work;
|
||||
SpaList work;
|
||||
WorkItem *free_list;
|
||||
|
||||
gulong work_id;
|
||||
|
|
@ -315,7 +315,7 @@ pinos_main_loop_finalize (GObject * obj)
|
|||
|
||||
pinos_log_debug ("main-loop %p: finalize", this);
|
||||
|
||||
g_slice_free_chain (WorkItem, priv->free_list, next);
|
||||
g_slice_free_chain (WorkItem, priv->free_list, list.next);
|
||||
|
||||
G_OBJECT_CLASS (pinos_main_loop_parent_class)->finalize (obj);
|
||||
}
|
||||
|
|
@ -359,7 +359,7 @@ pinos_main_loop_init (PinosMainLoop * this)
|
|||
this->poll.remove_item = do_remove_item;
|
||||
this->poll.invoke = do_invoke;
|
||||
|
||||
SPA_QUEUE_INIT (&priv->work);
|
||||
spa_list_init (&priv->work);
|
||||
spa_ringbuffer_init (&priv->buffer, DATAS_SIZE);
|
||||
}
|
||||
|
||||
|
|
@ -383,22 +383,15 @@ static gboolean
|
|||
process_work_queue (PinosMainLoop *this)
|
||||
{
|
||||
PinosMainLoopPrivate *priv = this->priv;
|
||||
WorkItem *prev, *item, *next;
|
||||
WorkItem *item, *tmp;
|
||||
|
||||
priv->work_id = 0;
|
||||
|
||||
for (item = priv->work.head, prev = NULL; item; prev = item, item = next) {
|
||||
next = item->next;
|
||||
|
||||
spa_list_for_each_safe (item, tmp, &priv->work, list) {
|
||||
if (item->seq != SPA_ID_INVALID)
|
||||
continue;
|
||||
|
||||
if (priv->work.tail == item)
|
||||
priv->work.tail = prev;
|
||||
if (prev == NULL)
|
||||
priv->work.head = next;
|
||||
else
|
||||
prev->next = next;
|
||||
spa_list_remove (&item->list);
|
||||
|
||||
if (item->func) {
|
||||
pinos_log_debug ("main-loop %p: process work item %p", this, item->obj);
|
||||
|
|
@ -407,10 +400,8 @@ process_work_queue (PinosMainLoop *this)
|
|||
if (item->notify)
|
||||
item->notify (item->data);
|
||||
|
||||
item->next = priv->free_list;
|
||||
item->list.next = &priv->free_list->list;
|
||||
priv->free_list = item;
|
||||
|
||||
item = prev;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
|
@ -432,7 +423,7 @@ pinos_main_loop_defer (PinosMainLoop *loop,
|
|||
|
||||
if (priv->free_list) {
|
||||
item = priv->free_list;
|
||||
priv->free_list = item->next;
|
||||
priv->free_list = SPA_CONTAINER_OF (item->list.next, WorkItem, list);
|
||||
} else {
|
||||
item = g_slice_new (WorkItem);
|
||||
}
|
||||
|
|
@ -441,7 +432,6 @@ pinos_main_loop_defer (PinosMainLoop *loop,
|
|||
item->func = func;
|
||||
item->data = data;
|
||||
item->notify = notify;
|
||||
item->next = NULL;
|
||||
|
||||
if (SPA_RESULT_IS_ASYNC (res)) {
|
||||
item->seq = SPA_RESULT_ASYNC_SEQ (res);
|
||||
|
|
@ -453,7 +443,7 @@ pinos_main_loop_defer (PinosMainLoop *loop,
|
|||
have_work = TRUE;
|
||||
pinos_log_debug ("main-loop %p: defer object %p", loop, obj);
|
||||
}
|
||||
SPA_QUEUE_PUSH_TAIL (&priv->work, WorkItem, next, item);
|
||||
spa_list_insert (priv->work.prev, &item->list);
|
||||
|
||||
if (priv->work_id == 0 && have_work)
|
||||
priv->work_id = g_idle_add ((GSourceFunc) process_work_queue, loop);
|
||||
|
|
@ -473,7 +463,7 @@ pinos_main_loop_defer_cancel (PinosMainLoop *loop,
|
|||
g_return_if_fail (PINOS_IS_MAIN_LOOP (loop));
|
||||
priv = loop->priv;
|
||||
|
||||
for (item = priv->work.head; item; item = item->next) {
|
||||
spa_list_for_each (item, &priv->work, list) {
|
||||
if ((id == 0 || item->id == id) && (obj == NULL || item->obj == obj)) {
|
||||
pinos_log_debug ("main-loop %p: cancel defer %d for object %p", loop, item->seq, item->obj);
|
||||
item->seq = SPA_ID_INVALID;
|
||||
|
|
@ -498,7 +488,7 @@ pinos_main_loop_defer_complete (PinosMainLoop *loop,
|
|||
g_return_val_if_fail (PINOS_IS_MAIN_LOOP (loop), FALSE);
|
||||
priv = loop->priv;
|
||||
|
||||
for (item = priv->work.head; item; item = item->next) {
|
||||
spa_list_for_each (item, &priv->work, list) {
|
||||
if (item->obj == obj && item->seq == seq) {
|
||||
pinos_log_debug ("main-loop %p: found defered %d for object %p", loop, seq, obj);
|
||||
item->seq = SPA_ID_INVALID;
|
||||
|
|
|
|||
|
|
@ -708,7 +708,6 @@ pinos_node_dispose (GObject * obj)
|
|||
pinos_log_debug ("node %p: dispose", node);
|
||||
pinos_node_set_state (node, PINOS_NODE_STATE_SUSPENDED);
|
||||
|
||||
pinos_registry_remove_object (&priv->daemon->registry, &node->object);
|
||||
node_unregister_object (node);
|
||||
|
||||
pinos_main_loop_defer_cancel (priv->main_loop, node, 0);
|
||||
|
|
@ -723,6 +722,9 @@ pinos_node_finalize (GObject * obj)
|
|||
PinosNodePrivate *priv = node->priv;
|
||||
|
||||
pinos_log_debug ("node %p: finalize", node);
|
||||
|
||||
pinos_registry_remove_object (&priv->daemon->registry, &node->object);
|
||||
|
||||
g_clear_object (&priv->daemon);
|
||||
g_clear_object (&priv->iface);
|
||||
g_clear_object (&priv->data_loop);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue