mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	pipewire: impl-module: add method for deferred destroy
Add `pw_impl_module_schedule_destroy()` which will schedule a call to `pw_impl_module_destroy()` on the module's context's work queue. For now, do not add it to the public impl-module.h header, only private.h.
This commit is contained in:
		
							parent
							
								
									4d4c6f20df
								
							
						
					
					
						commit
						a13e7ef091
					
				
					 2 changed files with 25 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -44,6 +44,7 @@ PW_LOG_TOPIC_EXTERN(log_module);
 | 
			
		|||
struct impl {
 | 
			
		||||
	struct pw_impl_module this;
 | 
			
		||||
	void *hnd;
 | 
			
		||||
	uint32_t destroy_work_id;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#define pw_module_resource_info(r,...)	pw_resource_call(r,struct pw_module_events,info,0,__VA_ARGS__)
 | 
			
		||||
| 
						 | 
				
			
			@ -220,6 +221,7 @@ pw_context_load_module(struct pw_context *context,
 | 
			
		|||
		goto error_no_mem;
 | 
			
		||||
 | 
			
		||||
	impl->hnd = hnd;
 | 
			
		||||
	impl->destroy_work_id = SPA_ID_INVALID;
 | 
			
		||||
	hnd = NULL;
 | 
			
		||||
 | 
			
		||||
	this = &impl->this;
 | 
			
		||||
| 
						 | 
				
			
			@ -336,6 +338,10 @@ void pw_impl_module_destroy(struct pw_impl_module *module)
 | 
			
		|||
 | 
			
		||||
	spa_hook_list_clean(&module->listener_list);
 | 
			
		||||
 | 
			
		||||
	if (impl->destroy_work_id != SPA_ID_INVALID)
 | 
			
		||||
		pw_work_queue_cancel(pw_context_get_work_queue(module->context),
 | 
			
		||||
				     module, SPA_ID_INVALID);
 | 
			
		||||
 | 
			
		||||
	if (!pw_in_valgrind() && dlclose(impl->hnd) != 0)
 | 
			
		||||
		pw_log_warn("%p: dlclose failed: %s", module, dlerror());
 | 
			
		||||
	free(impl);
 | 
			
		||||
| 
						 | 
				
			
			@ -398,3 +404,20 @@ void pw_impl_module_add_listener(struct pw_impl_module *module,
 | 
			
		|||
{
 | 
			
		||||
	spa_hook_list_append(&module->listener_list, listener, events, data);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void do_destroy_module(void *obj, void *data, int res, uint32_t id)
 | 
			
		||||
{
 | 
			
		||||
	pw_impl_module_destroy(obj);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
SPA_EXPORT
 | 
			
		||||
void pw_impl_module_schedule_destroy(struct pw_impl_module *module)
 | 
			
		||||
{
 | 
			
		||||
	struct impl *impl = SPA_CONTAINER_OF(module, struct impl, this);
 | 
			
		||||
 | 
			
		||||
	if (impl->destroy_work_id != SPA_ID_INVALID)
 | 
			
		||||
		return;
 | 
			
		||||
 | 
			
		||||
	impl->destroy_work_id = pw_work_queue_add(pw_context_get_work_queue(module->context),
 | 
			
		||||
						  module, 0, do_destroy_module, NULL);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1279,6 +1279,8 @@ void pw_settings_init(struct pw_context *context);
 | 
			
		|||
int pw_settings_expose(struct pw_context *context);
 | 
			
		||||
void pw_settings_clean(struct pw_context *context);
 | 
			
		||||
 | 
			
		||||
void pw_impl_module_schedule_destroy(struct pw_impl_module *module);
 | 
			
		||||
 | 
			
		||||
/** \endcond */
 | 
			
		||||
 | 
			
		||||
#ifdef __cplusplus
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue