Index: trunk/xcache.c
===================================================================
--- trunk/xcache.c	(revision 129)
+++ trunk/xcache.c	(revision 130)
@@ -43,16 +43,26 @@
 #define LOCK(x) xc_lock(x->lck)
 #define UNLOCK(x) xc_unlock(x->lck)
-#define ENTER_LOCK(x) do { \
-	int catched = 0; \
+
+#define ENTER_LOCK_EX(x) \
 	xc_lock(x->lck); \
 	zend_try { \
 		do
-#define LEAVE_LOCK(x) \
+#define LEAVE_LOCK_EX(x) \
 		while (0); \
 	} zend_catch { \
 		catched = 1; \
 	} zend_end_try(); \
-	xc_unlock(x->lck); \
+	xc_unlock(x->lck)
+
+#define ENTER_LOCK(x) do { \
+	int catched = 0; \
+	ENTER_LOCK_EX(x)
+#define LEAVE_LOCK(x) \
+	LEAVE_LOCK_EX(x); \
+	if (catched) { \
+		zend_bailout(); \
+	} \
 } while(0)
+
 /* }}} */
 
@@ -763,5 +773,5 @@
 	stored_xce = NULL;
 	op_array = NULL;
-	ENTER_LOCK(cache) {
+	ENTER_LOCK_EX(cache) {
 		/* clogged */
 		if (cache->compiling) {
@@ -785,5 +795,10 @@
 		cache->compiling = XG(request_time);
 		cache->misses ++;
-	} LEAVE_LOCK(cache);
+	} LEAVE_LOCK_EX(cache);
+
+	if (catched) {
+		cache->compiling = 0;
+		zend_bailout();
+	}
 
 	/* found */
@@ -899,7 +914,7 @@
 	}
 	/* }}} */
-	ENTER_LOCK(cache) { /* {{{ store/add entry */
+	ENTER_LOCK_EX(cache) { /* {{{ store/add entry */
 		stored_xce = xc_entry_store_dmz(&xce TSRMLS_CC);
-	} LEAVE_LOCK(cache);
+	} LEAVE_LOCK_EX(cache);
 	/* }}} */
 #ifdef DEBUG
