Index: uspace/srv/console/console.c
===================================================================
--- uspace/srv/console/console.c	(revision 0ed2e0e07159e63bbe76debb88533c9b15580498)
+++ uspace/srv/console/console.c	(revision a624cbfd618eb08343016b682ae85fb46ada815b)
@@ -52,4 +52,6 @@
 #include <event.h>
 #include <devmap.h>
+#include <assert.h>
+#include <fibril_sync.h>
 
 #include "console.h"
@@ -112,12 +114,18 @@
 LIST_INITIALIZE(pending_input);
 
+static FIBRIL_MUTEX_INITIALIZE(input_mutex);
+static FIBRIL_CONDVAR_INITIALIZE(input_cv);
+static input_flag = false;
+
 /** Process pending input requests */
 static void process_pending_input(void)
 {
-	async_serialize_start();
-	
 	link_t *cur;
 	
 loop:
+	fibril_mutex_lock(&input_mutex);
+	while (!input_flag)
+		fibril_condvar_wait(&input_cv, &input_mutex);
+rescan:
 	for (cur = pending_input.next; cur != &pending_input; cur = cur->next) {
 		pending_input_t *pr = list_get_instance(cur, pending_input_t, link);
@@ -133,9 +141,7 @@
 			} else {
 				ipc_answer_4(pr->rid, EOK, ev.type, ev.key, ev.mods, ev.c);
-				
 				list_remove(cur);
 				free(pr);
-				
-				goto loop;
+				goto rescan;
 			}
 		}
@@ -144,14 +150,14 @@
 			(void) ipc_data_read_finalize(pr->callid, pr->data, pr->size);
 			ipc_answer_1(pr->rid, EOK, pr->size);
-			
+
 			free(pr->data);
 			list_remove(cur);
 			free(pr);
-			
-			goto loop;
-		}
-	}
-	
-	async_serialize_end();
+			goto rescan;
+		}
+	}
+	input_flag = false;
+	fibril_mutex_unlock(&input_mutex);
+	goto loop;
 }
 
@@ -454,5 +460,9 @@
 			}
 			
+			fibril_mutex_lock(&input_mutex);
 			keybuffer_push(&active_console->keybuffer, &ev);
+			input_flag = true;
+			fibril_condvar_signal(&input_cv);
+			fibril_mutex_unlock(&input_mutex);
 			break;
 		default:
@@ -515,8 +525,7 @@
 	}
 	
-	async_serialize_start();
-	
 	size_t pos = 0;
 	console_event_t ev;
+	fibril_mutex_lock(&input_mutex);
 	while ((keybuffer_pop(&cons->keybuffer, &ev)) && (pos < size)) {
 		if (ev.type == KEY_PRESS) {
@@ -533,8 +542,8 @@
 		pending_input_t *pr = (pending_input_t *) malloc(sizeof(pending_input_t));
 		if (!pr) {
+			fibril_mutex_unlock(&input_mutex);
 			ipc_answer_0(callid, ENOMEM);
 			ipc_answer_0(rid, ENOMEM);
 			free(buf);
-			async_serialize_end();
 			return;
 		}
@@ -548,13 +557,12 @@
 		list_append(&pr->link, &pending_input);
 	}
-	
-	async_serialize_end();
+	fibril_mutex_unlock(&input_mutex);
 }
 
 static void cons_get_event(console_t *cons, ipc_callid_t rid, ipc_call_t *request)
 {
-	async_serialize_start();
-	
 	console_event_t ev;
+
+	fibril_mutex_lock(&input_mutex);
 	if (keybuffer_pop(&cons->keybuffer, &ev)) {
 		ipc_answer_4(rid, EOK, ev.type, ev.key, ev.mods, ev.c);
@@ -562,6 +570,6 @@
 		pending_input_t *pr = (pending_input_t *) malloc(sizeof(pending_input_t));
 		if (!pr) {
+			fibril_mutex_unlock(&input_mutex);
 			ipc_answer_0(rid, ENOMEM);
-			async_serialize_end();
 			return;
 		}
@@ -573,6 +581,5 @@
 		list_append(&pr->link, &pending_input);
 	}
-	
-	async_serialize_end();
+	fibril_mutex_unlock(&input_mutex);
 }
 
@@ -716,11 +723,8 @@
 static bool console_init(void)
 {
-	async_serialize_start();
-	
 	/* Connect to keyboard driver */
 	kbd_phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_KEYBOARD, 0, 0);
 	if (kbd_phone < 0) {
 		printf(NAME ": Failed to connect to keyboard service\n");
-		async_serialize_end();
 		return false;
 	}
@@ -729,10 +733,16 @@
 	if (ipc_connect_to_me(kbd_phone, SERVICE_CONSOLE, 0, 0, &phonehash) != 0) {
 		printf(NAME ": Failed to create callback from keyboard service\n");
-		async_serialize_end();
 		return false;
 	}
 	
-	async_set_pending(process_pending_input);
 	async_new_connection(phonehash, 0, NULL, keyboard_events);
+
+	fid_t fid = fibril_create(process_pending_input, NULL);
+	if (!fid) {
+		printf(NAME ": Failed to create fibril for handling pending "
+		    "input\n");
+		return -1;
+	}
+	fibril_add_ready(fid);
 	
 	/* Connect to framebuffer driver */
@@ -740,5 +750,4 @@
 	if (fb_info.phone < 0) {
 		printf(NAME ": Failed to connect to video service\n");
-		async_serialize_end();
 		return -1;
 	}
@@ -748,5 +757,4 @@
 	if (rc < 0) {
 		printf(NAME ": Unable to register driver (%d)\n", rc);
-		async_serialize_end();
 		return false;
 	}
@@ -784,5 +792,4 @@
 			    fb_info.cols, fb_info.rows) == NULL) {
 				printf(NAME ": Unable to allocate screen buffer %u\n", i);
-				async_serialize_end();
 				return false;
 			}
@@ -798,5 +805,4 @@
 				devmap_hangup_phone(DEVMAP_DRIVER);
 				printf(NAME ": Unable to register device %s\n", vc);
-				async_serialize_end();
 				return false;
 			}
@@ -808,4 +814,5 @@
 	
 	/* Initialize the screen */
+	async_serialize_start();
 	gcons_redraw_console();
 	set_rgb_color(DEFAULT_FOREGROUND, DEFAULT_BACKGROUND);
@@ -813,4 +820,5 @@
 	curs_goto(0, 0);
 	curs_visibility(active_console->scr.is_cursor_visible);
+	async_serialize_end();
 	
 	/* Receive kernel notifications */
@@ -820,5 +828,4 @@
 	async_set_interrupt_received(interrupt_received);
 	
-	async_serialize_end();
 	return true;
 }
