mirror of
				https://gitlab.freedesktop.org/wayland/wayland.git
				synced 2025-11-03 09:01:42 -05:00 
			
		
		
		
	Change filedescriptor API to be thread safe
The update callback for the file descriptors was always a bit awkward and un-intuitive. The idea was that whenever the protocol code needed to write data to the fd it would call the 'update' function. This function would adjust the mainloop so that it polls for POLLOUT on the fd so we can eventually flush the data to the socket. The problem is that in multi-threaded applications, any thread can issue a request, which writes data to the output buffer and thus triggers the update callback. Thus, we'll be calling out with the display mutex held and may call from any thread. The solution is to eliminate the udpate callback and just require that the application or server flushes all connection buffers before blocking. This turns out to be a simpler API, although we now require clients to deal with EAGAIN and non-blocking writes. It also saves a few syscalls, since the socket will be writable most of the time and most writes will complete, so we avoid changing epoll to poll for POLLOUT, then write and then change it back for each write.
This commit is contained in:
		
							parent
							
								
									0371668dcc
								
							
						
					
					
						commit
						53d24713a3
					
				
					 9 changed files with 150 additions and 251 deletions
				
			
		| 
						 | 
				
			
			@ -34,7 +34,9 @@ extern "C" {
 | 
			
		|||
 | 
			
		||||
enum {
 | 
			
		||||
	WL_EVENT_READABLE = 0x01,
 | 
			
		||||
	WL_EVENT_WRITABLE = 0x02
 | 
			
		||||
	WL_EVENT_WRITABLE = 0x02,
 | 
			
		||||
	WL_EVENT_HANGUP   = 0x04,
 | 
			
		||||
	WL_EVENT_ERROR    = 0x08
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct wl_event_loop;
 | 
			
		||||
| 
						 | 
				
			
			@ -88,6 +90,7 @@ struct wl_event_loop *wl_display_get_event_loop(struct wl_display *display);
 | 
			
		|||
int wl_display_add_socket(struct wl_display *display, const char *name);
 | 
			
		||||
void wl_display_terminate(struct wl_display *display);
 | 
			
		||||
void wl_display_run(struct wl_display *display);
 | 
			
		||||
void wl_display_flush_clients(struct wl_display *display);
 | 
			
		||||
 | 
			
		||||
typedef void (*wl_global_bind_func_t)(struct wl_client *client, void *data,
 | 
			
		||||
				      uint32_t version, uint32_t id);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue