Index: arch/ia32/src/smp/smp.c
===================================================================
--- arch/ia32/src/smp/smp.c	(revision 01ebbdf9288f435d62434b6709cc0d6785669473)
+++ arch/ia32/src/smp/smp.c	(revision 116d1ef443ca3edd56636818c5c30d58ad5bf213)
@@ -168,5 +168,5 @@
 			 * supposed to wake us up.
 			 */
-			if (waitq_sleep_timeout(&ap_completion_wq, 1000000, SYNCH_BLOCKING) == ESYNCH_TIMEOUT)
+			if (waitq_sleep_timeout(&ap_completion_wq, 1000000, SYNCH_FLAGS_NONE) == ESYNCH_TIMEOUT)
 				printf("%s: waiting for cpu%d (APIC ID = %d) timed out\n", __FUNCTION__, config.cpu_active > i ? config.cpu_active : i, ops->cpu_apic_id(i));
 		} else
Index: generic/include/ipc/ipc.h
===================================================================
--- generic/include/ipc/ipc.h	(revision 01ebbdf9288f435d62434b6709cc0d6785669473)
+++ generic/include/ipc/ipc.h	(revision 116d1ef443ca3edd56636818c5c30d58ad5bf213)
@@ -210,5 +210,5 @@
 
 extern void ipc_init(void);
-extern call_t * ipc_wait_for_call(answerbox_t *box, __u32 usec, int nonblocking);
+extern call_t * ipc_wait_for_call(answerbox_t *box, __u32 usec, int flags);
 extern void ipc_answer(answerbox_t *box, call_t *request);
 extern int ipc_call(phone_t *phone, call_t *call);
Index: generic/include/proc/thread.h
===================================================================
--- generic/include/proc/thread.h	(revision 01ebbdf9288f435d62434b6709cc0d6785669473)
+++ generic/include/proc/thread.h	(revision 116d1ef443ca3edd56636818c5c30d58ad5bf213)
@@ -88,4 +88,5 @@
 	context_t sleep_interruption_context;
 
+	bool sleep_interruptible;		/**< If true, the thread can be interrupted from sleep. */
 	waitq_t *sleep_queue;			/**< Wait queue in which this thread sleeps. */
 	timeout_t sleep_timeout;		/**< Timeout used for timeoutable sleeping.  */
Index: generic/include/synch/condvar.h
===================================================================
--- generic/include/synch/condvar.h	(revision 01ebbdf9288f435d62434b6709cc0d6785669473)
+++ generic/include/synch/condvar.h	(revision 116d1ef443ca3edd56636818c5c30d58ad5bf213)
@@ -40,12 +40,12 @@
 
 #define condvar_wait(cv,mtx) \
-	_condvar_wait_timeout((cv),(mtx),SYNCH_NO_TIMEOUT)
+	_condvar_wait_timeout((cv),(mtx),SYNCH_NO_TIMEOUT,SYNCH_FLAGS_NONE)
 #define condvar_wait_timeout(cv,mtx,usec) \
-	_condvar_wait_timeout((cv),(mtx),(usec))
+	_condvar_wait_timeout((cv),(mtx),(usec),SYNCH_FLAGS_NONE)
 
 extern void condvar_initialize(condvar_t *cv);
 extern void condvar_signal(condvar_t *cv);
 extern void condvar_broadcast(condvar_t *cv);
-extern int _condvar_wait_timeout(condvar_t *cv, mutex_t *mtx, __u32 usec);
+extern int _condvar_wait_timeout(condvar_t *cv, mutex_t *mtx, __u32 usec, int flags);
 
 #endif
Index: generic/include/synch/futex.h
===================================================================
--- generic/include/synch/futex.h	(revision 01ebbdf9288f435d62434b6709cc0d6785669473)
+++ generic/include/synch/futex.h	(revision 116d1ef443ca3edd56636818c5c30d58ad5bf213)
@@ -45,5 +45,5 @@
 
 extern void futex_init(void);
-extern __native sys_futex_sleep_timeout(__address uaddr, __u32 usec, int trydown);
+extern __native sys_futex_sleep_timeout(__address uaddr, __u32 usec, int flags);
 extern __native sys_futex_wakeup(__address uaddr);
 
Index: generic/include/synch/mutex.h
===================================================================
--- generic/include/synch/mutex.h	(revision 01ebbdf9288f435d62434b6709cc0d6785669473)
+++ generic/include/synch/mutex.h	(revision 116d1ef443ca3edd56636818c5c30d58ad5bf213)
@@ -40,14 +40,14 @@
 
 #define mutex_lock(mtx) \
-	_mutex_lock_timeout((mtx),SYNCH_NO_TIMEOUT,SYNCH_BLOCKING)
+	_mutex_lock_timeout((mtx),SYNCH_NO_TIMEOUT,SYNCH_FLAGS_NONE)
 #define mutex_trylock(mtx) \
-	_mutex_lock_timeout((mtx),SYNCH_NO_TIMEOUT,SYNCH_NON_BLOCKING)
+	_mutex_lock_timeout((mtx),SYNCH_NO_TIMEOUT,SYNCH_FLAGS_NON_BLOCKING)
 #define mutex_lock_timeout(mtx,usec) \
-	_mutex_lock_timeout((mtx),(usec),SYNCH_NON_BLOCKING)
+	_mutex_lock_timeout((mtx),(usec),SYNCH_FLAGS_NON_BLOCKING)
 #define mutex_lock_active(mtx) \
 	while (mutex_trylock((mtx)) != ESYNCH_OK_ATOMIC)
 
 extern void mutex_initialize(mutex_t *mtx);
-extern int _mutex_lock_timeout(mutex_t *mtx, __u32 usec, int trylock);
+extern int _mutex_lock_timeout(mutex_t *mtx, __u32 usec, int flags);
 extern void mutex_unlock(mutex_t *mtx);
 
Index: generic/include/synch/rwlock.h
===================================================================
--- generic/include/synch/rwlock.h	(revision 01ebbdf9288f435d62434b6709cc0d6785669473)
+++ generic/include/synch/rwlock.h	(revision 116d1ef443ca3edd56636818c5c30d58ad5bf213)
@@ -49,21 +49,22 @@
 
 #define rwlock_write_lock(rwl) \
-	_rwlock_write_lock_timeout((rwl),SYNCH_NO_TIMEOUT,SYNCH_BLOCKING)
+	_rwlock_write_lock_timeout((rwl),SYNCH_NO_TIMEOUT,SYNCH_FLAGS_NONE)
 #define rwlock_read_lock(rwl) \
-	_rwlock_read_lock_timeout((rwl),SYNCH_NO_TIMEOUT,SYNCH_BLOCKING)
+	_rwlock_read_lock_timeout((rwl),SYNCH_NO_TIMEOUT,SYNCH_FLAGS_NONE)
 #define rwlock_write_trylock(rwl) \
-	_rwlock_write_lock_timeout((rwl),SYNCH_NO_TIMEOUT,SYNCH_NON_BLOCKING)
+	_rwlock_write_lock_timeout((rwl),SYNCH_NO_TIMEOUT,SYNCH_FLAGS_NON_BLOCKING)
 #define rwlock_read_trylock(rwl) \
-	_rwlock_read_lock_timeout((rwl),SYNCH_NO_TIMEOUT,SYNCH_NON_BLOCKING)
+	_rwlock_read_lock_timeout((rwl),SYNCH_NO_TIMEOUT,SYNCH_FLAGS_NON_BLOCKING)
 #define rwlock_write_lock_timeout(rwl,usec) \
-	_rwlock_write_lock_timeout((rwl),(usec),SYNCH_NON_BLOCKING)
+	_rwlock_write_lock_timeout((rwl),(usec),SYNCH_FLAGS_NONE)
 #define rwlock_read_lock_timeout(rwl,usec) \
-	_rwlock_read_lock_timeout((rwl),(usec),SYNCH_NON_BLOCKING)
+	_rwlock_read_lock_timeout((rwl),(usec),SYNCH_FLAGS_NONE)
 
 extern void rwlock_initialize(rwlock_t *rwl);
 extern void rwlock_read_unlock(rwlock_t *rwl);
 extern void rwlock_write_unlock(rwlock_t *rwl);
-extern int _rwlock_read_lock_timeout(rwlock_t *rwl, __u32 usec, int trylock);
-extern int _rwlock_write_lock_timeout(rwlock_t *rwl, __u32 usec, int trylock);
+extern int _rwlock_read_lock_timeout(rwlock_t *rwl, __u32 usec, int flags);
+extern int _rwlock_write_lock_timeout(rwlock_t *rwl, __u32 usec, int flags);
 
 #endif
+
Index: generic/include/synch/semaphore.h
===================================================================
--- generic/include/synch/semaphore.h	(revision 01ebbdf9288f435d62434b6709cc0d6785669473)
+++ generic/include/synch/semaphore.h	(revision 116d1ef443ca3edd56636818c5c30d58ad5bf213)
@@ -41,13 +41,14 @@
 
 #define semaphore_down(s) \
-	_semaphore_down_timeout((s),SYNCH_NO_TIMEOUT,SYNCH_BLOCKING)
+	_semaphore_down_timeout((s),SYNCH_NO_TIMEOUT,SYNCH_FLAGS_NONE)
 #define semaphore_trydown(s) \
-	_semaphore_down_timeout((s),SYNCH_NO_TIMEOUT,SYNCH_NON_BLOCKING)	
+	_semaphore_down_timeout((s),SYNCH_NO_TIMEOUT,SYNCH_FLAGS_NON_BLOCKING)	
 #define semaphore_down_timeout(s,usec) \
-	_semaphore_down_timeout((s),(usec),SYNCH_NON_BLOCKING)
+	_semaphore_down_timeout((s),(usec),SYNCH_FLAGS_NONE)
 
 extern void semaphore_initialize(semaphore_t *s, int val);
-extern int _semaphore_down_timeout(semaphore_t *s, __u32 usec, int trydown);
+extern int _semaphore_down_timeout(semaphore_t *s, __u32 usec, int flags);
 extern void semaphore_up(semaphore_t *s);
 
 #endif
+
Index: generic/include/synch/synch.h
===================================================================
--- generic/include/synch/synch.h	(revision 01ebbdf9288f435d62434b6709cc0d6785669473)
+++ generic/include/synch/synch.h	(revision 116d1ef443ca3edd56636818c5c30d58ad5bf213)
@@ -31,6 +31,8 @@
 
 #define SYNCH_NO_TIMEOUT	0	/**< Request with no timeout. */
-#define SYNCH_BLOCKING		0	/**< Blocking operation request. */
-#define SYNCH_NON_BLOCKING	1	/**< Non-blocking operation request. */
+
+#define SYNCH_FLAGS_NONE		0	/**< No flags specified. */
+#define SYNCH_FLAGS_NON_BLOCKING	(1<<0)	/**< Non-blocking operation request. */
+#define SYNCH_FLAGS_INTERRUPTIBLE	(1<<1)	/**< Interruptible operation. */
 
 #define ESYNCH_WOULD_BLOCK	1	/**< Could not satisfy the request without going to sleep. */
Index: generic/include/synch/waitq.h
===================================================================
--- generic/include/synch/waitq.h	(revision 01ebbdf9288f435d62434b6709cc0d6785669473)
+++ generic/include/synch/waitq.h	(revision 116d1ef443ca3edd56636818c5c30d58ad5bf213)
@@ -53,10 +53,10 @@
 
 #define waitq_sleep(wq) \
-	waitq_sleep_timeout((wq),SYNCH_NO_TIMEOUT,SYNCH_BLOCKING)
+	waitq_sleep_timeout((wq),SYNCH_NO_TIMEOUT,SYNCH_FLAGS_NONE)
 
 extern void waitq_initialize(waitq_t *wq);
-extern int waitq_sleep_timeout(waitq_t *wq, __u32 usec, int nonblocking);
+extern int waitq_sleep_timeout(waitq_t *wq, __u32 usec, int flags);
 extern ipl_t waitq_sleep_prepare(waitq_t *wq);
-extern int waitq_sleep_timeout_unsafe(waitq_t *wq, __u32 usec, int nonblocking);
+extern int waitq_sleep_timeout_unsafe(waitq_t *wq, __u32 usec, int flags);
 extern void waitq_sleep_finish(waitq_t *wq, int rc, ipl_t ipl);
 extern void waitq_wakeup(waitq_t *wq, bool all);
Index: generic/src/ipc/ipc.c
===================================================================
--- generic/src/ipc/ipc.c	(revision 01ebbdf9288f435d62434b6709cc0d6785669473)
+++ generic/src/ipc/ipc.c	(revision 116d1ef443ca3edd56636818c5c30d58ad5bf213)
@@ -143,5 +143,5 @@
 
 	ipc_call(phone, request);
-	ipc_wait_for_call(&sync_box, SYNCH_NO_TIMEOUT, SYNCH_BLOCKING);
+	ipc_wait_for_call(&sync_box, SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE);
 }
 
@@ -306,10 +306,10 @@
  * @param usec Timeout in microseconds. See documentation for waitq_sleep_timeout() for
  *	       decription of its special meaning.
- * @param nonblocking Blocking vs. non-blocking operation mode switch. See documentation
- *		      for waitq_sleep_timeout() for description of its special meaning.
+ * @param flags Select mode of sleep operation. See documentation for waitq_sleep_timeout()i
+ * 		for description of its special meaning.
  * @return Recived message address
  * - to distinguish between call and answer, look at call->flags
  */
-call_t * ipc_wait_for_call(answerbox_t *box, __u32 usec, int nonblocking)
+call_t * ipc_wait_for_call(answerbox_t *box, __u32 usec, int flags)
 {
 	call_t *request;
@@ -318,5 +318,5 @@
 
 restart:
-	rc = waitq_sleep_timeout(&box->wq, usec, nonblocking);
+	rc = waitq_sleep_timeout(&box->wq, usec, flags);
 	if (SYNCH_FAILED(rc))
 		return NULL;
@@ -413,5 +413,5 @@
 	/* Wait for all async answers to arrive */
 	while (atomic_get(&task->active_calls)) {
-		call = ipc_wait_for_call(&task->answerbox, SYNCH_NO_TIMEOUT, SYNCH_BLOCKING);
+		call = ipc_wait_for_call(&task->answerbox, SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE);
 		ASSERT((call->flags & IPC_CALL_ANSWERED) || (call->flags & IPC_CALL_NOTIF));
 		ASSERT(! (call->flags & IPC_CALL_STATIC_ALLOC));
Index: generic/src/ipc/sysipc.c
===================================================================
--- generic/src/ipc/sysipc.c	(revision 01ebbdf9288f435d62434b6709cc0d6785669473)
+++ generic/src/ipc/sysipc.c	(revision 116d1ef443ca3edd56636818c5c30d58ad5bf213)
@@ -503,14 +503,14 @@
  * @param calldata Pointer to buffer where the call/answer data is stored 
  * @param usec Timeout. See waitq_sleep_timeout() for explanation.
- * @param nonblocking See waitq_sleep_timeout() for explanation.
+ * @param flags Select mode of sleep operation. See waitq_sleep_timeout() for explanation.
  *
  * @return Callid, if callid & 1, then the call is answer
  */
-__native sys_ipc_wait_for_call(ipc_data_t *calldata, __u32 usec, int nonblocking)
+__native sys_ipc_wait_for_call(ipc_data_t *calldata, __u32 usec, int flags)
 {
 	call_t *call;
 
 restart:	
-	call = ipc_wait_for_call(&TASK->answerbox, usec, nonblocking);
+	call = ipc_wait_for_call(&TASK->answerbox, usec, flags | SYNCH_FLAGS_INTERRUPTIBLE);
 	if (!call)
 		return 0;
Index: generic/src/proc/thread.c
===================================================================
--- generic/src/proc/thread.c	(revision 01ebbdf9288f435d62434b6709cc0d6785669473)
+++ generic/src/proc/thread.c	(revision 116d1ef443ca3edd56636818c5c30d58ad5bf213)
@@ -304,4 +304,5 @@
 	
 	timeout_initialize(&t->sleep_timeout);
+	t->sleep_interruptible = false;
 	t->sleep_queue = NULL;
 	t->timeout_pending = 0;
@@ -386,5 +387,5 @@
 	waitq_initialize(&wq);
 
-	(void) waitq_sleep_timeout(&wq, usec, SYNCH_NON_BLOCKING);
+	(void) waitq_sleep_timeout(&wq, usec, SYNCH_FLAGS_NON_BLOCKING);
 }
 
Index: generic/src/synch/condvar.c
===================================================================
--- generic/src/synch/condvar.c	(revision 01ebbdf9288f435d62434b6709cc0d6785669473)
+++ generic/src/synch/condvar.c	(revision 116d1ef443ca3edd56636818c5c30d58ad5bf213)
@@ -75,11 +75,14 @@
  * @param mtx Mutex.
  * @param usec Timeout value in microseconds.
+ * @param flags Select mode of operation.
  *
- * For exact description of meaning of possible values of usec,
- * see comment for waitq_sleep_timeout().
+ * For exact description of meaning of possible combinations
+ * of usec and flags, see comment for waitq_sleep_timeout().
+ * Note that when SYNCH_FLAGS_NON_BLOCKING is specified here,
+ * ESYNCH_WOULD_BLOCK is always returned.
  *
  * @return See comment for waitq_sleep_timeout().
  */
-int _condvar_wait_timeout(condvar_t *cv, mutex_t *mtx, __u32 usec)
+int _condvar_wait_timeout(condvar_t *cv, mutex_t *mtx, __u32 usec, int flags)
 {
 	int rc;
@@ -90,5 +93,5 @@
 
 	cv->wq.missed_wakeups = 0;	/* Enforce blocking. */
-	rc = waitq_sleep_timeout_unsafe(&cv->wq, usec, SYNCH_BLOCKING);
+	rc = waitq_sleep_timeout_unsafe(&cv->wq, usec, flags);
 
 	mutex_lock(mtx);
Index: generic/src/synch/futex.c
===================================================================
--- generic/src/synch/futex.c	(revision 01ebbdf9288f435d62434b6709cc0d6785669473)
+++ generic/src/synch/futex.c	(revision 116d1ef443ca3edd56636818c5c30d58ad5bf213)
@@ -100,10 +100,10 @@
  * @param uaddr Userspace address of the futex counter.
  * @param usec If non-zero, number of microseconds this thread is willing to sleep.
- * @param trydown If usec is zero and trydown is non-zero, conditional operation will be attempted.
+ * @param flags Select mode of operation.
  *
  * @return One of ESYNCH_TIMEOUT, ESYNCH_OK_ATOMIC and ESYNCH_OK_BLOCKED. See synch.h.
  *	   If there is no physical mapping for uaddr ENOENT is returned.
  */
-__native sys_futex_sleep_timeout(__address uaddr, __u32 usec, int trydown)
+__native sys_futex_sleep_timeout(__address uaddr, __u32 usec, int flags)
 {
 	futex_t *futex;
@@ -131,5 +131,5 @@
 	futex = futex_find(paddr);
 	
-	return (__native) waitq_sleep_timeout(&futex->wq, usec, trydown);
+	return (__native) waitq_sleep_timeout(&futex->wq, usec, flags | SYNCH_FLAGS_INTERRUPTIBLE);
 }
 
Index: generic/src/synch/mutex.c
===================================================================
--- generic/src/synch/mutex.c	(revision 01ebbdf9288f435d62434b6709cc0d6785669473)
+++ generic/src/synch/mutex.c	(revision 116d1ef443ca3edd56636818c5c30d58ad5bf213)
@@ -54,14 +54,14 @@
  * @param mtx Mutex.
  * @param usec Timeout in microseconds.
- * @param trylock Switches between blocking and non-blocking mode.
+ * @param flags Specify mode of operation.
  *
  * For exact description of possible combinations of
- * usec and trylock, see comment for waitq_sleep_timeout().
+ * usec and flags, see comment for waitq_sleep_timeout().
  *
  * @return See comment for waitq_sleep_timeout().
  */
-int _mutex_lock_timeout(mutex_t *mtx, __u32 usec, int trylock)
+int _mutex_lock_timeout(mutex_t *mtx, __u32 usec, int flags)
 {
-	return _semaphore_down_timeout(&mtx->sem, usec, trylock);
+	return _semaphore_down_timeout(&mtx->sem, usec, flags);
 }
 
@@ -76,2 +76,3 @@
 	semaphore_up(&mtx->sem);
 }
+
Index: generic/src/synch/rwlock.c
===================================================================
--- generic/src/synch/rwlock.c	(revision 01ebbdf9288f435d62434b6709cc0d6785669473)
+++ generic/src/synch/rwlock.c	(revision 116d1ef443ca3edd56636818c5c30d58ad5bf213)
@@ -90,12 +90,12 @@
  * @param rwl Reader/Writer lock.
  * @param usec Timeout in microseconds.
- * @param trylock Switches between blocking and non-blocking mode.
+ * @param flags Specify mode of operation.
  *
  * For exact description of possible combinations of
- * @usec and @trylock, see comment for waitq_sleep_timeout().
+ * usec and flags, see comment for waitq_sleep_timeout().
  *
  * @return See comment for waitq_sleep_timeout().
  */
-int _rwlock_write_lock_timeout(rwlock_t *rwl, __u32 usec, int trylock)
+int _rwlock_write_lock_timeout(rwlock_t *rwl, __u32 usec, int flags)
 {
 	ipl_t ipl;
@@ -112,9 +112,9 @@
 	 * They just need to acquire the exclusive mutex.
 	 */
-	rc = _mutex_lock_timeout(&rwl->exclusive, usec, trylock);
+	rc = _mutex_lock_timeout(&rwl->exclusive, usec, flags);
 	if (SYNCH_FAILED(rc)) {
 
 		/*
-		 * Lock operation timed out.
+		 * Lock operation timed out or was interrupted.
 		 * The state of rwl is UNKNOWN at this point.
 		 * No claims about its holder can be made.
@@ -144,12 +144,12 @@
  * @param rwl Reader/Writer lock.
  * @param usec Timeout in microseconds.
- * @param trylock Switches between blocking and non-blocking mode.
+ * @param flags Select mode of operation.
  *
  * For exact description of possible combinations of
- * usec and trylock, see comment for waitq_sleep_timeout().
+ * usec and flags, see comment for waitq_sleep_timeout().
  *
  * @return See comment for waitq_sleep_timeout().
  */
-int _rwlock_read_lock_timeout(rwlock_t *rwl, __u32 usec, int trylock)
+int _rwlock_read_lock_timeout(rwlock_t *rwl, __u32 usec, int flags)
 {
 	int rc;
@@ -200,5 +200,5 @@
 		#endif
 				 
-		rc = _mutex_lock_timeout(&rwl->exclusive, usec, trylock);
+		rc = _mutex_lock_timeout(&rwl->exclusive, usec, flags);
 		switch (rc) {
 			case ESYNCH_WOULD_BLOCK:
@@ -209,6 +209,7 @@
 				spinlock_unlock(&rwl->lock);
 			case ESYNCH_TIMEOUT:
+			case ESYNCH_INTERRUPTED:
 				/*
-				 * The sleep timeouted.
+				 * The sleep timed out.
 				 * We just restore interrupt priority level.
 				 */
Index: generic/src/synch/semaphore.c
===================================================================
--- generic/src/synch/semaphore.c	(revision 01ebbdf9288f435d62434b6709cc0d6785669473)
+++ generic/src/synch/semaphore.c	(revision 116d1ef443ca3edd56636818c5c30d58ad5bf213)
@@ -68,14 +68,14 @@
  * @param s Semaphore.
  * @param usec Timeout in microseconds.
- * @param trydown Switches between blocking and non-blocking mode.
+ * @param flags Select mode of operation.
  *
  * For exact description of possible combinations of
- * usec and trydown, see comment for waitq_sleep_timeout().
+ * usec and flags, see comment for waitq_sleep_timeout().
  *
  * @return See comment for waitq_sleep_timeout().
  */
-int _semaphore_down_timeout(semaphore_t *s, __u32 usec, int trydown)
+int _semaphore_down_timeout(semaphore_t *s, __u32 usec, int flags)
 {
-	return waitq_sleep_timeout(&s->wq, usec, trydown); 
+	return waitq_sleep_timeout(&s->wq, usec, flags); 
 }
 
Index: generic/src/synch/waitq.c
===================================================================
--- generic/src/synch/waitq.c	(revision 01ebbdf9288f435d62434b6709cc0d6785669473)
+++ generic/src/synch/waitq.c	(revision 116d1ef443ca3edd56636818c5c30d58ad5bf213)
@@ -136,4 +136,12 @@
 	spinlock_lock(&t->lock);
 	if ((wq = t->sleep_queue)) {		/* assignment */
+		if (!(t->sleep_interruptible)) {
+			/*
+			 * The sleep cannot be interrupted.
+			 */
+			spinlock_unlock(&t->lock);
+			goto out;
+		}
+			
 		if (!spinlock_trylock(&wq->lock)) {
 			spinlock_unlock(&t->lock);
@@ -160,5 +168,5 @@
 /** Sleep until either wakeup, timeout or interruption occurs
  *
- * This is a sleep implementation which allows itself to be
+ * This is a sleep implementation which allows itself to time out or to be
  * interrupted from the sleep, restoring a failover context.
  *
@@ -170,16 +178,20 @@
  * @param wq Pointer to wait queue.
  * @param usec Timeout in microseconds.
- * @param nonblocking Blocking vs. non-blocking operation mode switch.
- *
- * If usec is greater than zero, regardless of the value of nonblocking,
- * the call will not return until either timeout or wakeup comes.
- *
- * If usec is zero and @nonblocking is zero (false), the call
- * will not return until wakeup comes.
- *
- * If usec is zero and nonblocking is non-zero (true), the call will
+ * @param flags Specify mode of the sleep.
+ *
+ * The sleep can be interrupted only if the
+ * SYNCH_FLAGS_INTERRUPTIBLE bit is specified in flags.
+ 
+ * If usec is greater than zero, regardless of the value of the
+ * SYNCH_FLAGS_NON_BLOCKING bit in flags, the call will not return until either timeout,
+ * interruption or wakeup comes. 
+ *
+ * If usec is zero and the SYNCH_FLAGS_NON_BLOCKING bit is not set in flags, the call
+ * will not return until wakeup or interruption comes.
+ *
+ * If usec is zero and the SYNCH_FLAGS_NON_BLOCKING bit is set in flags, the call will
  * immediately return, reporting either success or failure.
  *
- * @return 	Returns one of: ESYNCH_WOULD_BLOCK, ESYNCH_TIMEOUT,
+ * @return 	Returns one of: ESYNCH_WOULD_BLOCK, ESYNCH_TIMEOUT, ESYNCH_INTERRUPTED,
  *      	ESYNCH_OK_ATOMIC, ESYNCH_OK_BLOCKED.
  *
@@ -198,5 +210,5 @@
  * attempted.
  */
-int waitq_sleep_timeout(waitq_t *wq, __u32 usec, int nonblocking)
+int waitq_sleep_timeout(waitq_t *wq, __u32 usec, int flags)
 {
 	ipl_t ipl;
@@ -204,5 +216,5 @@
 	
 	ipl = waitq_sleep_prepare(wq);
-	rc = waitq_sleep_timeout_unsafe(wq, usec, nonblocking);
+	rc = waitq_sleep_timeout_unsafe(wq, usec, flags);
 	waitq_sleep_finish(wq, rc, ipl);
 	return rc;
@@ -277,9 +289,9 @@
  * @param wq See waitq_sleep_timeout().
  * @param usec See waitq_sleep_timeout().
- * @param nonblocking See waitq_sleep_timeout().
+ * @param flags See waitq_sleep_timeout().
  *
  * @return See waitq_sleep_timeout().
  */
-int waitq_sleep_timeout_unsafe(waitq_t *wq, __u32 usec, int nonblocking)
+int waitq_sleep_timeout_unsafe(waitq_t *wq, __u32 usec, int flags)
 {
 	/* checks whether to go to sleep at all */
@@ -289,5 +301,5 @@
 	}
 	else {
-		if (nonblocking && (usec == 0)) {
+		if ((flags & SYNCH_FLAGS_NON_BLOCKING) && (usec == 0)) {
 			/* return immediatelly instead of going to sleep */
 			return ESYNCH_WOULD_BLOCK;
@@ -300,12 +312,17 @@
 	spinlock_lock(&THREAD->lock);
 
-	/*
-	 * Set context that will be restored if the sleep
-	 * of this thread is ever interrupted.
-	 */
-	if (!context_save(&THREAD->sleep_interruption_context)) {
-		/* Short emulation of scheduler() return code. */
-		spinlock_unlock(&THREAD->lock);
-		return ESYNCH_INTERRUPTED;
+	if (flags & SYNCH_FLAGS_INTERRUPTIBLE) {
+		/*
+		 * Set context that will be restored if the sleep
+		 * of this thread is ever interrupted.
+		 */
+		THREAD->sleep_interruptible = true;
+		if (!context_save(&THREAD->sleep_interruption_context)) {
+			/* Short emulation of scheduler() return code. */
+			spinlock_unlock(&THREAD->lock);
+			return ESYNCH_INTERRUPTED;
+		}
+	} else {
+		THREAD->sleep_interruptible = false;
 	}
 
