mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	pulse-server: message: store pointer to impl directly
Store a pointer to the owner `impl` object instead of the (embedded) `stat` object. This way `message_free()` can be simplified since the owner `impl` does not need to be passed explicitly.
This commit is contained in:
		
							parent
							
								
									b843b0ab29
								
							
						
					
					
						commit
						080a97c0bb
					
				
					 5 changed files with 27 additions and 30 deletions
				
			
		| 
						 | 
					@ -159,10 +159,10 @@ void client_free(struct client *client)
 | 
				
			||||||
		pending_sample_free(p);
 | 
							pending_sample_free(p);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (client->message)
 | 
						if (client->message)
 | 
				
			||||||
		message_free(impl, client->message, false, false);
 | 
							message_free(client->message, false, false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	spa_list_consume(msg, &client->out_messages, link)
 | 
						spa_list_consume(msg, &client->out_messages, link)
 | 
				
			||||||
		message_free(impl, msg, true, false);
 | 
							message_free(msg, true, false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	spa_list_consume(o, &client->operations, link)
 | 
						spa_list_consume(o, &client->operations, link)
 | 
				
			||||||
		operation_free(o);
 | 
							operation_free(o);
 | 
				
			||||||
| 
						 | 
					@ -220,14 +220,12 @@ int client_queue_message(struct client *client, struct message *msg)
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
error:
 | 
					error:
 | 
				
			||||||
	message_free(impl, msg, false, false);
 | 
						message_free(msg, false, false);
 | 
				
			||||||
	return res;
 | 
						return res;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int client_try_flush_messages(struct client *client)
 | 
					static int client_try_flush_messages(struct client *client)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct impl *impl = client->impl;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	pw_log_trace("client %p: flushing", client);
 | 
						pw_log_trace("client %p: flushing", client);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	spa_assert(!client->disconnect);
 | 
						spa_assert(!client->disconnect);
 | 
				
			||||||
| 
						 | 
					@ -254,7 +252,7 @@ static int client_try_flush_messages(struct client *client)
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			if (debug_messages && m->channel == SPA_ID_INVALID)
 | 
								if (debug_messages && m->channel == SPA_ID_INVALID)
 | 
				
			||||||
				message_dump(SPA_LOG_LEVEL_INFO, m);
 | 
									message_dump(SPA_LOG_LEVEL_INFO, m);
 | 
				
			||||||
			message_free(impl, m, true, false);
 | 
								message_free(m, true, false);
 | 
				
			||||||
			client->out_index = 0;
 | 
								client->out_index = 0;
 | 
				
			||||||
			continue;
 | 
								continue;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
| 
						 | 
					@ -307,7 +305,7 @@ static bool drop_from_out_queue(struct client *client, struct message *m)
 | 
				
			||||||
	if (m == first && client->out_index > 0)
 | 
						if (m == first && client->out_index > 0)
 | 
				
			||||||
		return false;
 | 
							return false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	message_free(client->impl, m, true, false);
 | 
						message_free(m, true, false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return true;
 | 
						return true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -397,12 +397,12 @@ static int ensure_size(struct message *m, uint32_t size)
 | 
				
			||||||
	diff = alloc - m->allocated;
 | 
						diff = alloc - m->allocated;
 | 
				
			||||||
	if ((data = realloc(m->data, alloc)) == NULL) {
 | 
						if ((data = realloc(m->data, alloc)) == NULL) {
 | 
				
			||||||
		free(m->data);
 | 
							free(m->data);
 | 
				
			||||||
		m->stat->allocated -= m->allocated;
 | 
							m->impl->stat.allocated -= m->allocated;
 | 
				
			||||||
		m->allocated = 0;
 | 
							m->allocated = 0;
 | 
				
			||||||
		return -errno;
 | 
							return -errno;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	m->stat->allocated += diff;
 | 
						m->impl->stat.allocated += diff;
 | 
				
			||||||
	m->stat->accumulated += diff;
 | 
						m->impl->stat.accumulated += diff;
 | 
				
			||||||
	m->data = data;
 | 
						m->data = data;
 | 
				
			||||||
	m->allocated = alloc;
 | 
						m->allocated = alloc;
 | 
				
			||||||
	return size;
 | 
						return size;
 | 
				
			||||||
| 
						 | 
					@ -826,18 +826,20 @@ struct message *message_alloc(struct impl *impl, uint32_t channel, uint32_t size
 | 
				
			||||||
		msg = spa_list_first(&impl->free_messages, struct message, link);
 | 
							msg = spa_list_first(&impl->free_messages, struct message, link);
 | 
				
			||||||
		spa_list_remove(&msg->link);
 | 
							spa_list_remove(&msg->link);
 | 
				
			||||||
		pw_log_trace("using recycled message %p size:%d", msg, size);
 | 
							pw_log_trace("using recycled message %p size:%d", msg, size);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							spa_assert(msg->impl == impl);
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		if ((msg = calloc(1, sizeof(*msg))) == NULL)
 | 
							if ((msg = calloc(1, sizeof(*msg))) == NULL)
 | 
				
			||||||
			return NULL;
 | 
								return NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		pw_log_trace("new message %p size:%d", msg, size);
 | 
							pw_log_trace("new message %p size:%d", msg, size);
 | 
				
			||||||
		msg->stat = &impl->stat;
 | 
							msg->impl = impl;
 | 
				
			||||||
		msg->stat->n_allocated++;
 | 
							msg->impl->stat.n_allocated++;
 | 
				
			||||||
		msg->stat->n_accumulated++;
 | 
							msg->impl->stat.n_accumulated++;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (ensure_size(msg, size) < 0) {
 | 
						if (ensure_size(msg, size) < 0) {
 | 
				
			||||||
		message_free(impl, msg, false, true);
 | 
							message_free(msg, false, true);
 | 
				
			||||||
		return NULL;
 | 
							return NULL;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -849,23 +851,23 @@ struct message *message_alloc(struct impl *impl, uint32_t channel, uint32_t size
 | 
				
			||||||
	return msg;
 | 
						return msg;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void message_free(struct impl *impl, struct message *msg, bool dequeue, bool destroy)
 | 
					void message_free(struct message *msg, bool dequeue, bool destroy)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	if (dequeue)
 | 
						if (dequeue)
 | 
				
			||||||
		spa_list_remove(&msg->link);
 | 
							spa_list_remove(&msg->link);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (msg->stat->allocated > MAX_ALLOCATED || msg->allocated > MAX_SIZE)
 | 
						if (msg->impl->stat.allocated > MAX_ALLOCATED || msg->allocated > MAX_SIZE)
 | 
				
			||||||
		destroy = true;
 | 
							destroy = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (destroy) {
 | 
						if (destroy) {
 | 
				
			||||||
		pw_log_trace("destroy message %p size:%d", msg, msg->allocated);
 | 
							pw_log_trace("destroy message %p size:%d", msg, msg->allocated);
 | 
				
			||||||
		msg->stat->n_allocated--;
 | 
							msg->impl->stat.n_allocated--;
 | 
				
			||||||
		msg->stat->allocated -= msg->allocated;
 | 
							msg->impl->stat.allocated -= msg->allocated;
 | 
				
			||||||
		free(msg->data);
 | 
							free(msg->data);
 | 
				
			||||||
		free(msg);
 | 
							free(msg);
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		pw_log_trace("recycle message %p size:%d/%d", msg, msg->length, msg->allocated);
 | 
							pw_log_trace("recycle message %p size:%d/%d", msg, msg->length, msg->allocated);
 | 
				
			||||||
		spa_list_append(&impl->free_messages, &msg->link);
 | 
							spa_list_append(&msg->impl->free_messages, &msg->link);
 | 
				
			||||||
		msg->length = 0;
 | 
							msg->length = 0;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -32,11 +32,10 @@
 | 
				
			||||||
#include <spa/support/log.h>
 | 
					#include <spa/support/log.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct impl;
 | 
					struct impl;
 | 
				
			||||||
struct stats;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct message {
 | 
					struct message {
 | 
				
			||||||
	struct spa_list link;
 | 
						struct spa_list link;
 | 
				
			||||||
	struct stats *stat;
 | 
						struct impl *impl;
 | 
				
			||||||
	uint32_t extra[4];
 | 
						uint32_t extra[4];
 | 
				
			||||||
	uint32_t channel;
 | 
						uint32_t channel;
 | 
				
			||||||
	uint32_t allocated;
 | 
						uint32_t allocated;
 | 
				
			||||||
| 
						 | 
					@ -68,7 +67,7 @@ enum {
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct message *message_alloc(struct impl *impl, uint32_t channel, uint32_t size);
 | 
					struct message *message_alloc(struct impl *impl, uint32_t channel, uint32_t size);
 | 
				
			||||||
void message_free(struct impl *impl, struct message *msg, bool dequeue, bool destroy);
 | 
					void message_free(struct message *msg, bool dequeue, bool destroy);
 | 
				
			||||||
int message_get(struct message *m, ...);
 | 
					int message_get(struct message *m, ...);
 | 
				
			||||||
int message_put(struct message *m, ...);
 | 
					int message_put(struct message *m, ...);
 | 
				
			||||||
int message_dump(enum spa_log_level level, struct message *m);
 | 
					int message_dump(enum spa_log_level level, struct message *m);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4315,7 +4315,7 @@ error_invalid:
 | 
				
			||||||
	goto error;
 | 
						goto error;
 | 
				
			||||||
error:
 | 
					error:
 | 
				
			||||||
	if (reply)
 | 
						if (reply)
 | 
				
			||||||
		message_free(impl, reply, false, false);
 | 
							message_free(reply, false, false);
 | 
				
			||||||
	return res;
 | 
						return res;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4391,7 +4391,7 @@ static int do_get_sample_info(struct client *client, uint32_t command, uint32_t
 | 
				
			||||||
 | 
					
 | 
				
			||||||
error:
 | 
					error:
 | 
				
			||||||
	if (reply)
 | 
						if (reply)
 | 
				
			||||||
		message_free(impl, reply, false, false);
 | 
							message_free(reply, false, false);
 | 
				
			||||||
	return res;
 | 
						return res;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5355,7 +5355,7 @@ static void impl_clear(struct impl *impl)
 | 
				
			||||||
		client_free(c);
 | 
							client_free(c);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	spa_list_consume(msg, &impl->free_messages, link)
 | 
						spa_list_consume(msg, &impl->free_messages, link)
 | 
				
			||||||
		message_free(impl, msg, true, true);
 | 
							message_free(msg, true, true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	pw_map_for_each(&impl->samples, impl_free_sample, impl);
 | 
						pw_map_for_each(&impl->samples, impl_free_sample, impl);
 | 
				
			||||||
	pw_map_clear(&impl->samples);
 | 
						pw_map_clear(&impl->samples);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -66,7 +66,6 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int handle_packet(struct client *client, struct message *msg)
 | 
					static int handle_packet(struct client *client, struct message *msg)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct impl * const impl = client->impl;
 | 
					 | 
				
			||||||
	uint32_t command, tag;
 | 
						uint32_t command, tag;
 | 
				
			||||||
	int res = 0;
 | 
						int res = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -110,7 +109,7 @@ static int handle_packet(struct client *client, struct message *msg)
 | 
				
			||||||
	res = cmd->run(client, command, tag, msg);
 | 
						res = cmd->run(client, command, tag, msg);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
finish:
 | 
					finish:
 | 
				
			||||||
	message_free(impl, msg, false, false);
 | 
						message_free(msg, false, false);
 | 
				
			||||||
	if (res < 0)
 | 
						if (res < 0)
 | 
				
			||||||
		reply_error(client, command, tag, res);
 | 
							reply_error(client, command, tag, res);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -119,7 +118,6 @@ finish:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int handle_memblock(struct client *client, struct message *msg)
 | 
					static int handle_memblock(struct client *client, struct message *msg)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct impl * const impl = client->impl;
 | 
					 | 
				
			||||||
	struct stream *stream;
 | 
						struct stream *stream;
 | 
				
			||||||
	uint32_t channel, flags, index;
 | 
						uint32_t channel, flags, index;
 | 
				
			||||||
	int64_t offset, diff;
 | 
						int64_t offset, diff;
 | 
				
			||||||
| 
						 | 
					@ -190,7 +188,7 @@ static int handle_memblock(struct client *client, struct message *msg)
 | 
				
			||||||
	stream_send_request(stream);
 | 
						stream_send_request(stream);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
finish:
 | 
					finish:
 | 
				
			||||||
	message_free(impl, msg, false, false);
 | 
						message_free(msg, false, false);
 | 
				
			||||||
	return res;
 | 
						return res;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -264,7 +262,7 @@ static int do_read(struct client *client)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (client->message)
 | 
							if (client->message)
 | 
				
			||||||
			message_free(impl, client->message, false, false);
 | 
								message_free(client->message, false, false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		client->message = message_alloc(impl, channel, length);
 | 
							client->message = message_alloc(impl, channel, length);
 | 
				
			||||||
	} else if (client->message &&
 | 
						} else if (client->message &&
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue