Index: /trunk/src/VBox/Devices/Network/slirp/ip_input.c
===================================================================
--- /trunk/src/VBox/Devices/Network/slirp/ip_input.c	(revision 13709)
+++ /trunk/src/VBox/Devices/Network/slirp/ip_input.c	(revision 13710)
@@ -69,4 +69,7 @@
 	register struct ip *ip;
 	int hlen;
+#ifdef VBOX_WITH_SYNC_SLIRP
+        int rc;
+#endif
 
 	DEBUG_CALL("ip_input");
@@ -74,9 +77,5 @@
 	DEBUG_ARG("m_len = %d", m->m_len);
 
-#ifdef VBOX_WITH_SYNC_SLIRP
-        int rc;
-        rc = RTSemMutexRequest(m->m_mutex, RT_INDEFINITE_WAIT);
-        AssertReleaseRC(rc);
-#endif
+        VBOX_SLIRP_LOCK(m->m_mutex);
 
 	ipstat.ips_total++;
@@ -84,8 +83,5 @@
 	if (m->m_len < sizeof (struct ip)) {
 		ipstat.ips_toosmall++;
-#ifdef VBOX_WITH_SYNC_SLIRP
-                rc = RTSemMutexRelease(m->m_mutex);
-                AssertReleaseRC(rc);
-#endif
+                VBOX_SLIRP_UNLOCK(m->m_mutex);
 		return;
 	}
@@ -200,24 +196,12 @@
 			ipstat.ips_fragments++;
 			ip = ip_reass(pData, (struct ipasfrag *)ip, fp);
-			if (ip == 0)
-#ifndef VBOX_WITH_SYNC_SLIRP
-				return;
-#else
-                        {
-                            rc = RTSemMutexRelease(m->m_mutex);
-                            AssertReleaseRC(rc);
+			if (ip == 0) {
+                            VBOX_SLIRP_UNLOCK(m->m_mutex);
                             return;
                         }
-#endif
 			ipstat.ips_reassembled++;
-#ifndef VBOX_WITH_SYNC_SLIRP
+                        VBOX_SLIRP_UNLOCK(m->m_mutex);
 			m = dtom(pData, ip);
-#else
-                        rc = RTSemMutexRelease(m->m_mutex);
-                        AssertReleaseRC(rc);
-			m = dtom(pData, ip);
-                        rc = RTSemMutexRequest(m->m_mutex, RT_INDEFINITE_WAIT);
-                        AssertReleaseRC(rc);
-#endif
+                        VBOX_SLIRP_LOCK(m->m_mutex);
 		} else
 			if (fp)
@@ -234,42 +218,24 @@
 	 case IPPROTO_TCP:
 		tcp_input(pData, m, hlen, (struct socket *)NULL);
-#ifdef VBOX_WITH_SYNC_SLIRP
-                rc = RTSemMutexRelease(m->m_mutex);
-                AssertReleaseRC(rc);
-#endif
 		break;
 	 case IPPROTO_UDP:
 		udp_input(pData, m, hlen);
-#ifdef VBOX_WITH_SYNC_SLIRP
-                rc = RTSemMutexRelease(m->m_mutex);
-                AssertReleaseRC(rc);
-#endif
 		break;
 	 case IPPROTO_ICMP:
 		icmp_input(pData, m, hlen);
-#ifdef VBOX_WITH_SYNC_SLIRP
-                rc = RTSemMutexRelease(m->m_mutex);
-                AssertReleaseRC(rc);
-#endif
 		break;
 	 default:
 		ipstat.ips_noproto++;
 		m_free(pData, m);
-#ifdef VBOX_WITH_SYNC_SLIRP
-                if (m != NULL) {
-                        rc = RTSemMutexRelease(m->m_mutex);
-                        AssertReleaseRC(rc);
-                }
-#endif
-	}
+	}
+        if (m != NULL) {
+                VBOX_SLIRP_UNLOCK(m->m_mutex);
+        }
 	return;
 bad:
 	m_freem(pData, m);
-#ifdef VBOX_WITH_SYNC_SLIRP
         if (m != NULL) {
-                rc = RTSemMutexRelease(m->m_mutex);
-                AssertReleaseRC(rc);
+                VBOX_SLIRP_UNLOCK(m->m_mutex);
         }
-#endif
 	return;
 }
Index: /trunk/src/VBox/Devices/Network/slirp/mbuf.c
===================================================================
--- /trunk/src/VBox/Devices/Network/slirp/mbuf.c	(revision 13709)
+++ /trunk/src/VBox/Devices/Network/slirp/mbuf.c	(revision 13710)
@@ -25,9 +25,9 @@
 	m_usedlist.m_next = m_usedlist.m_prev = &m_usedlist;
         mbuf_alloced = 0;
-#ifdef VBOX_WITH_SYNC_SLIRP
-        RTSemMutexCreate(&pData->m_usedlist_mutex);
-        RTSemMutexCreate(&pData->m_freelist_mutex);
-        RTSemMutexCreate(&pData->mbuf_alloced_mutex);
-#endif
+
+        VBOX_SLIRP_LOCK_CREATE(&pData->m_usedlist_mutex);
+        VBOX_SLIRP_LOCK_CREATE(&pData->m_freelist_mutex);
+        VBOX_SLIRP_LOCK_CREATE(&pData->mbuf_alloced_mutex);
+
 	msize_init(pData);
 }
@@ -63,19 +63,16 @@
 	DEBUG_CALL("m_get");
 
-#ifdef VBOX_WITH_SYNC_SLIRP
-        RTSemMutexRequest(pData->m_freelist_mutex, RT_INDEFINITE_WAIT);
-#endif
+        VBOX_SLIRP_LOCK(pData->m_freelist_mutex);
+
 	if (m_freelist.m_next == &m_freelist) {
 		m = (struct mbuf *)malloc(msize);
 		if (m == NULL) {
-#ifdef VBOX_WITH_SYNC_SLIRP
-                    RTSemMutexRelease(pData->m_freelist_mutex);
-#endif
+                    VBOX_SLIRP_UNLOCK(pData->m_freelist_mutex);
                     goto end_error;
                 }
-#ifdef VBOX_WITH_SYNC_SLIRP
-                RTSemMutexCreate(&m->m_mutex);
-                RTSemMutexRequest(pData->mbuf_alloced_mutex, RT_INDEFINITE_WAIT);
-#endif
+
+                VBOX_SLIRP_LOCK_CREATE(&m->m_mutex);
+                VBOX_SLIRP_LOCK(pData->mbuf_alloced_mutex);
+
 		mbuf_alloced++;
 		if (mbuf_alloced > mbuf_thresh)
@@ -83,22 +80,18 @@
 		if (mbuf_alloced > mbuf_max)
 			mbuf_max = mbuf_alloced;
-#ifdef VBOX_WITH_SYNC_SLIRP
-                RTSemMutexRelease(pData->mbuf_alloced_mutex);
-#endif
+                VBOX_SLIRP_UNLOCK(pData->mbuf_alloced_mutex);
 	} else {
 		m = m_freelist.m_next;
 		remque(pData, m);
 	}
-#ifdef VBOX_WITH_SYNC_SLIRP
-        RTSemMutexRequest(m->m_mutex, RT_INDEFINITE_WAIT);
-        RTSemMutexRelease(pData->m_freelist_mutex);
-        RTSemMutexRequest(pData->m_usedlist_mutex, RT_INDEFINITE_WAIT);
-#endif
-
+
+        VBOX_SLIRP_LOCK(m->m_mutex);
+        VBOX_SLIRP_UNLOCK(pData->m_freelist_mutex);
+
+        VBOX_SLIRP_LOCK(pData->m_usedlist_mutex);
 	/* Insert it in the used list */
 	insque(pData, m,&m_usedlist);
-#ifdef VBOX_WITH_SYNC_SLIRP
-        RTSemMutexRelease(pData->m_usedlist_mutex);
-#endif
+        VBOX_SLIRP_UNLOCK(pData->m_usedlist_mutex);
+
 	m->m_flags = (flags | M_USEDLIST);
 
@@ -109,7 +102,6 @@
 	m->m_nextpkt = 0;
 	m->m_prevpkt = 0;
-#ifdef VBOX_WITH_SYNC_SLIRP
-        RTSemMutexRelease(m->m_mutex);
-#endif
+
+        VBOX_SLIRP_UNLOCK(m->m_mutex);
 end_error:
 	DEBUG_ARG("m = %lx", (long )m);
@@ -126,15 +118,9 @@
   if(m) {
 	/* Remove from m_usedlist */
-#ifdef VBOX_WITH_SYNC_SLIRP
-        RTSemMutexRequest(m->m_mutex, RT_INDEFINITE_WAIT);
-#endif
+        VBOX_SLIRP_LOCK(m->m_mutex);
 	if (m->m_flags & M_USEDLIST) {
-#ifdef VBOX_WITH_SYNC_SLIRP
-           RTSemMutexRequest(pData->m_usedlist_mutex, RT_INDEFINITE_WAIT);
-#endif
+           VBOX_SLIRP_LOCK(pData->m_usedlist_mutex);
 	   remque(pData, m);
-#ifdef VBOX_WITH_SYNC_SLIRP
-           RTSemMutexRelease(pData->m_usedlist_mutex);
-#endif
+           VBOX_SLIRP_UNLOCK(pData->m_usedlist_mutex);
         }
 
@@ -148,30 +134,20 @@
 	if (m->m_flags & M_DOFREE) {
 		u32ptr_done(pData, ptr_to_u32(pData, m), m);
-#ifdef VBOX_WITH_SYNC_SLIRP
-                RTSemMutexRelease(m->m_mutex);
-                RTSemMutexDestroy(m->m_mutex);
-#endif
+                VBOX_SLIRP_UNLOCK(m->m_mutex);
+                VBOX_SLIRP_LOCK_DESTROY(m->m_mutex);
 		free(m);
 #ifdef VBOX_WITH_SYNC_SLIRP
                 m = NULL;
-                RTSemMutexRequest(pData->mbuf_alloced_mutex, RT_INDEFINITE_WAIT);
+#endif
+                VBOX_SLIRP_LOCK(pData->mbuf_alloced_mutex);
 		mbuf_alloced--;
-                RTSemMutexRelease(pData->mbuf_alloced_mutex);
-#else
-		mbuf_alloced--;
-#endif
+                VBOX_SLIRP_UNLOCK(pData->mbuf_alloced_mutex);
 	} else if ((m->m_flags & M_FREELIST) == 0) {
-#ifdef VBOX_WITH_SYNC_SLIRP
-                RTSemMutexRequest(pData->m_freelist_mutex, RT_INDEFINITE_WAIT);
-#endif
+                VBOX_SLIRP_LOCK(pData->m_freelist_mutex);
 		insque(pData, m,&m_freelist);
 		m->m_flags = M_FREELIST; /* Clobber other flags */
-#ifdef VBOX_WITH_SYNC_SLIRP
-                RTSemMutexRelease(pData->m_freelist_mutex);
-#endif
+                VBOX_SLIRP_UNLOCK(pData->m_freelist_mutex);
 	}
-#ifdef VBOX_WITH_SYNC_SLIRP
-        if (m != NULL) RTSemMutexRelease(m->m_mutex);
-#endif
+        if (m != NULL) VBOX_SLIRP_UNLOCK(m->m_mutex);
   } /* if(m) */
 }
@@ -188,8 +164,7 @@
 	 * If there's no room, realloc
 	 */
-#ifdef VBOX_WITH_SYNC_SLIRP
-        RTSemMutexRequest(m->m_mutex, RT_INDEFINITE_WAIT);
-        RTSemMutexRequest(n->m_mutex, RT_INDEFINITE_WAIT);
-#endif
+        VBOX_SLIRP_LOCK(m->m_mutex);
+        VBOX_SLIRP_LOCK(n->m_mutex);
+
 	if (M_FREEROOM(m) < n->m_len)
 		m_inc(m,m->m_size+MINCSIZE);
@@ -199,8 +174,7 @@
 
 	m_free(pData, n);
-#ifdef VBOX_WITH_SYNC_SLIRP
-        RTSemMutexRelease(m->m_mutex);
-        if (n != NULL) RTSemMutexRelease(n->m_mutex);
-#endif
+
+        VBOX_SLIRP_UNLOCK(m->m_mutex);
+        if (n != NULL) VBOX_SLIRP_UNLOCK(n->m_mutex);
 }
 
@@ -215,11 +189,7 @@
 
 	/* some compiles throw up on gotos.  This one we can fake. */
-#ifdef VBOX_WITH_SYNC_SLIRP
-        RTSemMutexRequest(m->m_mutex, RT_INDEFINITE_WAIT);
-#endif
+        VBOX_SLIRP_LOCK(m->m_mutex);
         if(m->m_size>size) {
-#ifdef VBOX_WITH_SYNC_SLIRP
-            RTSemMutexRelease(m->m_mutex);
-#endif
+            VBOX_SLIRP_UNLOCK(m->m_mutex);
             return;
         }
@@ -247,7 +217,5 @@
 
         m->m_size = size;
-#ifdef VBOX_WITH_SYNC_SLIRP
-        RTSemMutexRelease(m->m_mutex);
-#endif
+        VBOX_SLIRP_UNLOCK(m->m_mutex);
 }
 
@@ -261,7 +229,5 @@
 	if (m == NULL)
 		return;
-#ifdef VBOX_WITH_SYNC_SLIRP
-        RTSemMutexRequest(m->m_mutex, RT_INDEFINITE_WAIT);
-#endif
+        VBOX_SLIRP_LOCK(m->m_mutex);
 	if (len >= 0) {
 		/* Trim from head */
@@ -273,7 +239,5 @@
 		m->m_len -= len;
 	}
-#ifdef VBOX_WITH_SYNC_SLIRP
-        RTSemMutexRelease(m->m_mutex);
-#endif
+        VBOX_SLIRP_UNLOCK(m->m_mutex);
 }
 
@@ -287,13 +251,9 @@
 	int off, len;
 {
-#ifdef VBOX_WITH_SYNC_SLIRP
-        RTSemMutexRequest(m->m_mutex, RT_INDEFINITE_WAIT);
-        RTSemMutexRequest(n->m_mutex, RT_INDEFINITE_WAIT);
-#endif
+        VBOX_SLIRP_LOCK(m->m_mutex);
+        VBOX_SLIRP_LOCK(n->m_mutex);
 	if (len > M_FREEROOM(n)) {
-#ifdef VBOX_WITH_SYNC_SLIRP
-                RTSemMutexRelease(n->m_mutex);
-                RTSemMutexRelease(m->m_mutex);
-#endif
+                VBOX_SLIRP_UNLOCK(n->m_mutex);
+                VBOX_SLIRP_UNLOCK(m->m_mutex);
 		return -1;
         }
@@ -301,8 +261,6 @@
 	memcpy((n->m_data + n->m_len), (m->m_data + off), len);
 	n->m_len += len;
-#ifdef VBOX_WITH_SYNC_SLIRP
-        RTSemMutexRelease(n->m_mutex);
-        RTSemMutexRelease(m->m_mutex);
-#endif
+        VBOX_SLIRP_UNLOCK(n->m_mutex);
+        VBOX_SLIRP_UNLOCK(m->m_mutex);
 	return 0;
 }
@@ -327,29 +285,25 @@
 #else
 	struct mbuf *mnext;
-        RTSemMutexRequest(pData->m_usedlist_mutex, RT_INDEFINITE_WAIT);
+        VBOX_SLIRP_LOCK(pData->m_usedlist_mutex);
         m = m_usedlist.m_next;
         while(1) {
-            RTSemMutexRequest(m->m_mutex, RT_INDEFINITE_WAIT);
+            VBOX_SLIRP_LOCK(m->m_mutex);
             mnext = m->m_next;
-            RTSemMutexRelease(pData->m_usedlist_mutex);
+            VBOX_SLIRP_UNLOCK(pData->m_usedlist_mutex);
 #endif
 	  if (m->m_flags & M_EXT) {
 	    if( (char *)dat>=m->m_ext && (char *)dat<(m->m_ext + m->m_size) ) {
-#ifdef VBOX_WITH_SYNC_SLIRP
-              RTSemMutexRelease(m->m_mutex);
-#endif
+              VBOX_SLIRP_UNLOCK(m->m_mutex);
 	      return m;
             }
 	  } else {
 	    if( (char *)dat >= m->m_dat && (char *)dat<(m->m_dat + m->m_size) ) {
-#ifdef VBOX_WITH_SYNC_SLIRP
-              RTSemMutexRelease(m->m_mutex);
-#endif
+              VBOX_SLIRP_UNLOCK(m->m_mutex);
 	      return m;
             }
 	  }
+          VBOX_SLIRP_UNLOCK(m->m_mutex);
+          VBOX_SLIRP_LOCK(pData->m_usedlist_mutex);
 #ifdef VBOX_WITH_SYNC_SLIRP
-          RTSemMutexRelease(m->m_mutex);
-          RTSemMutexRequest(pData->m_usedlist_mutex, RT_INDEFINITE_WAIT);
           m = mnext;
 #endif
Index: /trunk/src/VBox/Devices/Network/slirp/slirp.h
===================================================================
--- /trunk/src/VBox/Devices/Network/slirp/slirp.h	(revision 13709)
+++ /trunk/src/VBox/Devices/Network/slirp/slirp.h	(revision 13710)
@@ -384,3 +384,40 @@
 #endif
 
-#endif
+#ifdef VBOX_WITH_SYNC_SLIRP
+#define VBOX_SLIRP_LOCK_SUFFIX _mutex
+
+#define VBOX_SLIRP_LOCK(x)                                                  \
+do{                                                                         \
+    int rc;                                                                 \
+    rc = RTSemMutexRequest((x), RT_INDEFINITE_WAIT);                        \
+    AssertReleaseRC(rc);                                                    \
+}while (0)
+
+#define VBOX_SLIRP_UNLOCK(x)                                                \
+do{                                                                         \
+    int rc;                                                                 \
+    rc = RTSemMutexRelease((x));                                            \
+    AssertReleaseRC(rc);                                                    \
+}while (0)
+
+#define VBOX_SLIRP_LOCK_CREATE(x)                                           \
+do{                                                                         \
+    int rc;                                                                 \
+    rc = RTSemMutexCreate((x));                                             \
+    AssertReleaseRC(rc);                                                    \
+}while (0)
+
+#define VBOX_SLIRP_LOCK_DESTROY(x)                                          \
+do{                                                                         \
+    int rc;                                                                 \
+    rc = RTSemMutexDestroy((x));                                            \
+    AssertReleaseRC(rc);                                                    \
+}while (0)
+#else
+#define VBOX_SLIRP_LOCK(x) /* ignore */
+#define VBOX_SLIRP_UNLOCK(x) /* ignore */
+#define VBOX_SLIRP_LOCK_DESTROY(x) /* ignore */
+#define VBOX_SLIRP_LOCK_CREATE(x) /* ignore */
+#endif
+
+#endif
Index: /trunk/src/VBox/Devices/Network/slirp/socket.c
===================================================================
--- /trunk/src/VBox/Devices/Network/slirp/socket.c	(revision 13709)
+++ /trunk/src/VBox/Devices/Network/slirp/socket.c	(revision 13710)
@@ -64,7 +64,5 @@
     so->so_state = SS_NOFDREF;
     so->s = -1;
-#ifdef VBOX_WITH_SYNC_SLIRP
-    RTSemMutexCreate(&so->so_mutex);
-#endif
+    VBOX_SLIRP_LOCK_CREATE(&so->so_mutex);
   }
   return(so);
@@ -94,5 +92,5 @@
     /*Take global mutexes of udb and tcb, because we dont know which is mutex */
     /*XXX: don't forget to set correct so_type in corresponded attach operation */
-    RTSemMutexRequest(so->so_mutex, RT_INDEFINITE_WAIT);
+    VBOX_SLIRP_LOCK(so->so_mutex);
     if (so->so_emu==EMU_RSH && so->extra) {
           sofree(pData, so->extra);
@@ -101,8 +99,8 @@
 
     if (so->so_type == IPPROTO_UDP) {
-        RTSemMutexRequest(pData->udp_last_so_mutex, RT_INDEFINITE_WAIT);
+        VBOX_SLIRP_LOCK(pData->udp_last_so_mutex);
     }
     else if (so->so_type == IPPROTO_TCP) {
-        RTSemMutexRequest(pData->tcp_last_so_mutex, RT_INDEFINITE_WAIT);
+        VBOX_SLIRP_LOCK(pData->tcp_last_so_mutex);
     }
     else {
@@ -119,8 +117,8 @@
 
     if (so->so_type == IPPROTO_UDP) {
-        RTSemMutexRelease(pData->udp_last_so_mutex);
+        VBOX_SLIRP_UNLOCK(pData->udp_last_so_mutex);
     }
     else if (so->so_type == IPPROTO_TCP) {
-        RTSemMutexRelease(pData->tcp_last_so_mutex);
+        VBOX_SLIRP_UNLOCK(pData->tcp_last_so_mutex);
     }
     else {
@@ -128,10 +126,10 @@
     }
     /* socket's mutex could be released because socket none accessible via queue anymore*/
-    RTSemMutexRelease(so->so_mutex);
+    VBOX_SLIRP_UNLOCK(so->so_mutex);
 
     m_free(pData, so->so_m);
 
 
-    RTSemMutexDestroy(so->so_mutex);
+    VBOX_SLIRP_UNLOCK(so->so_mutex);
 #endif
 
@@ -156,7 +154,5 @@
 	int mss = so->so_tcpcb->t_maxseg;
 
-#ifdef VBOX_WITH_SYNC_SLIRP
-        RTSemMutexRequest(so->so_mutex, RT_INDEFINITE_WAIT);
-#endif
+        VBOX_SLIRP_LOCK(so->so_mutex);
 	DEBUG_CALL("soread");
 	DEBUG_ARG("so = %lx", (long )so);
@@ -218,7 +214,5 @@
 	if (nn <= 0) {
 		if (nn < 0 && (errno == EINTR || errno == EAGAIN)) {
-#ifdef VBOX_WITH_SYNC_SLIRP
-                        RTSemMutexRelease(so->so_mutex);
-#endif
+                        VBOX_SLIRP_UNLOCK(so->so_mutex);
 			return 0;
                 }
@@ -227,7 +221,5 @@
 			sofcantrcvmore(so);
 			tcp_sockclosed(pData, sototcpcb(so));
-#ifdef VBOX_WITH_SYNC_SLIRP
-                        RTSemMutexRelease(so->so_mutex);
-#endif
+                        VBOX_SLIRP_UNLOCK(so->so_mutex);
 			return -1;
 		}
@@ -259,7 +251,5 @@
 	if (sb->sb_wptr >= (sb->sb_data + sb->sb_datalen))
 		sb->sb_wptr -= sb->sb_datalen;
-#ifdef VBOX_WITH_SYNC_SLIRP
-        RTSemMutexRelease(so->so_mutex);
-#endif
+        VBOX_SLIRP_UNLOCK(so->so_mutex);
 	return nn;
 }
@@ -275,7 +265,5 @@
 sorecvoob(PNATState pData, struct socket *so)
 {
-#ifdef VBOX_WITH_SYNC_SLIRP
-        RTSemMutexRequest(so->so_mutex, RT_INDEFINITE_WAIT);
-#endif
+        VBOX_SLIRP_LOCK(so->so_mutex);
 	struct tcpcb *tp = sototcpcb(so);
 
@@ -293,10 +281,8 @@
 	soread(pData, so);
 	tp->snd_up = tp->snd_una + so->so_snd.sb_cc;
+        VBOX_SLIRP_UNLOCK(so->so_mutex);
 	tp->t_force = 1;
 	tcp_output(pData, tp);
 	tp->t_force = 0;
-#ifdef VBOX_WITH_SYNC_SLIRP
-        RTSemMutexRelease(so->so_mutex);
-#endif
 }
 
@@ -314,5 +300,5 @@
 	int n, len;
 #ifdef VBOX_WITH_SYNC_SLIRP
-        RTSemMutexRequest(so->so_mutex, RT_INDEFINITE_WAIT);
+        VBOX_SLIRP_LOCK(so->so_mutex);
 #endif
 
@@ -361,5 +347,5 @@
 
 #ifdef VBOX_WITH_SYNC_SLIRP
-        RTSemMutexRelease(so->so_mutex);
+        VBOX_SLIRP_UNLOCK(so->so_mutex);
 #endif
 	return n;
@@ -378,5 +364,5 @@
 	struct iovec iov[2];
 #ifdef VBOX_WITH_SYNC_SLIRP
-        RTSemMutexRequest(so->so_mutex, RT_INDEFINITE_WAIT);
+        VBOX_SLIRP_LOCK(so->so_mutex);
 #endif
 
@@ -388,5 +374,5 @@
 		if (sb->sb_cc == 0)
 #ifdef VBOX_WITH_SYNC_SLIRP
-       RTSemMutexRelease(so->so_mutex);
+       VBOX_SLIRP_UNLOCK(so->so_mutex);
 #endif
 			return 0;
@@ -432,5 +418,5 @@
 	if (nn < 0 && (errno == EAGAIN || errno == EINTR)) {
 #ifdef VBOX_WITH_SYNC_SLIRP
-                RTSemMutexRelease(so->so_mutex);
+                VBOX_SLIRP_UNLOCK(so->so_mutex);
 #endif
 		return 0;
@@ -443,5 +429,5 @@
 		tcp_sockclosed(pData, sototcpcb(so));
 #ifdef VBOX_WITH_SYNC_SLIRP
-                RTSemMutexRelease(so->so_mutex);
+                VBOX_SLIRP_UNLOCK(so->so_mutex);
 #endif
 		return -1;
@@ -472,5 +458,5 @@
 
 #ifdef VBOX_WITH_SYNC_SLIRP
-        RTSemMutexRelease(so->so_mutex);
+        VBOX_SLIRP_UNLOCK(so->so_mutex);
 #endif
 	return nn;
@@ -490,5 +476,5 @@
 
 #ifdef VBOX_WITH_SYNC_SLIRP
-        RTSemMutexRequest(so->so_mutex, RT_INDEFINITE_WAIT);
+        VBOX_SLIRP_LOCK(so->so_mutex);
 #endif
 
@@ -579,5 +565,5 @@
 	} /* if ping packet */
 #ifdef VBOX_WITH_SYNC_SLIRP
-        RTSemMutexRelease(so->so_mutex);
+        VBOX_SLIRP_UNLOCK(so->so_mutex);
 #endif
 }
@@ -595,5 +581,5 @@
 #endif
 #ifdef VBOX_WITH_SYNC_SLIRP
-        RTSemMutexRequest(so->so_mutex, RT_INDEFINITE_WAIT);
+        VBOX_SLIRP_LOCK(so->so_mutex);
 #endif
 
@@ -650,5 +636,5 @@
 	if (ret < 0) {
 #ifdef VBOX_WITH_SYNC_SLIRP
-                RTSemMutexRelease(so->so_mutex);
+                VBOX_SLIRP_UNLOCK(so->so_mutex);
 #endif
 		return -1;
@@ -663,5 +649,5 @@
 	so->so_state = SS_ISFCONNECTED; /* So that it gets select()ed */
 #ifdef VBOX_WITH_SYNC_SLIRP
-                RTSemMutexRelease(so->so_mutex);
+                VBOX_SLIRP_UNLOCK(so->so_mutex);
 #endif
 	return 0;
@@ -698,9 +684,9 @@
 	insque(pData, so,&tcb);
 #else
-        RTSemMutexRequest(so->so_mutex, RT_INDEFINITE_WAIT);
+        VBOX_SLIRP_LOCK(so->so_mutex);
         /*after adding to global queue probably we should keep lock*/
-        RTSemMutexRequest(pData->tcb_mutex, RT_INDEFINITE_WAIT);
+        VBOX_SLIRP_LOCK(pData->tcb_mutex);
 	insque(pData, so,&tcb);
-        RTSemMutexRelease(pData->tcb_mutex);
+        VBOX_SLIRP_UNLOCK(pData->tcb_mutex);
 #endif
 
@@ -749,5 +735,5 @@
 	so->s = s;
 #ifdef VBOX_WITH_SYNC_SLIRP
-        RTSemMutexRelease(so->so_mutex);
+        VBOX_SLIRP_UNLOCK(so->so_mutex);
 #endif
 	return so;
@@ -790,5 +776,5 @@
 {
 #ifdef VBOX_WITH_SYNC_SLIRP
-    RTSemMutexRequest(so->so_mutex, RT_INDEFINITE_WAIT);
+    VBOX_SLIRP_LOCK(so->so_mutex);
 #endif
 	so->so_state &= ~(SS_NOFDREF|SS_ISFCONNECTED|SS_FCANTRCVMORE|
@@ -796,5 +782,5 @@
 	so->so_state |= SS_ISFCONNECTING; /* Clobber other states */
 #ifdef VBOX_WITH_SYNC_SLIRP
-    RTSemMutexRelease(so->so_mutex);
+    VBOX_SLIRP_UNLOCK(so->so_mutex);
 #endif
 }
@@ -805,10 +791,10 @@
 {
 #ifdef VBOX_WITH_SYNC_SLIRP
-    RTSemMutexRequest(so->so_mutex, RT_INDEFINITE_WAIT);
+    VBOX_SLIRP_LOCK(so->so_mutex);
 #endif
 	so->so_state &= ~(SS_ISFCONNECTING|SS_FWDRAIN|SS_NOFDREF);
 	so->so_state |= SS_ISFCONNECTED; /* Clobber other states */
 #ifdef VBOX_WITH_SYNC_SLIRP
-    RTSemMutexRelease(so->so_mutex);
+    VBOX_SLIRP_UNLOCK(so->so_mutex);
 #endif
 }
@@ -819,5 +805,5 @@
 {
 #ifdef VBOX_WITH_SYNC_SLIRP
-    RTSemMutexRequest(so->so_mutex, RT_INDEFINITE_WAIT);
+    VBOX_SLIRP_LOCK(so->so_mutex);
 #endif
 	if ((so->so_state & SS_NOFDREF) == 0) {
@@ -830,5 +816,5 @@
 	   so->so_state |= SS_FCANTRCVMORE;
 #ifdef VBOX_WITH_SYNC_SLIRP
-    RTSemMutexRelease(so->so_mutex);
+    VBOX_SLIRP_UNLOCK(so->so_mutex);
 #endif
 }
@@ -839,5 +825,5 @@
 {
 #ifdef VBOX_WITH_SYNC_SLIRP
-    RTSemMutexRequest(so->so_mutex, RT_INDEFINITE_WAIT);
+    VBOX_SLIRP_LOCK(so->so_mutex);
 #endif
 	if ((so->so_state & SS_NOFDREF) == 0) {
@@ -850,5 +836,5 @@
 	   so->so_state |= SS_FCANTSENDMORE;
 #ifdef VBOX_WITH_SYNC_SLIRP
-    RTSemMutexRelease(so->so_mutex);
+    VBOX_SLIRP_UNLOCK(so->so_mutex);
 #endif
 }
@@ -875,5 +861,5 @@
 {
 #ifdef VBOX_WITH_SYNC_SLIRP
-    RTSemMutexRequest(so->so_mutex, RT_INDEFINITE_WAIT);
+    VBOX_SLIRP_LOCK(so->so_mutex);
 #endif
 	if (so->so_rcv.sb_cc)
@@ -882,6 +868,6 @@
 		sofcantsendmore(so);
 #ifdef VBOX_WITH_SYNC_SLIRP
-    RTSemMutexRelease(so->so_mutex);
-#endif
-}
-
+    VBOX_SLIRP_UNLOCK(so->so_mutex);
+#endif
+}
+
Index: /trunk/src/VBox/Devices/Network/slirp/tcp_input.c
===================================================================
--- /trunk/src/VBox/Devices/Network/slirp/tcp_input.c	(revision 13709)
+++ /trunk/src/VBox/Devices/Network/slirp/tcp_input.c	(revision 13710)
@@ -254,11 +254,9 @@
 }while(0)
 #endif
-
-        int rc;
+#endif
+
         if (inso != NULL) {
-            rc = RTSemMutexRequest(inso->so_mutex, RT_INDEFINITE_WAIT);
-            AssertReleaseRC(rc);
+            VBOX_SLIRP_LOCK(inso->so_mutex);
         }
-#endif
 
 	/*
@@ -271,8 +269,5 @@
 		tp = sototcpcb(so);
 		m = so->so_m;
-#ifdef VBOX_WITH_SYNC_SLIRP
-                rc = RTSemMutexRequest(m->m_mutex, RT_INDEFINITE_WAIT);
-                AssertReleaseRC(rc);
-#endif
+                VBOX_SLIRP_LOCK(m->m_mutex);
 		so->so_m = 0;
 		ti = so->so_ti;
@@ -282,8 +277,8 @@
 		goto cont_conn;
 	}
-#ifdef VBOX_WITH_SYNC_SLIRP
-        rc = RTSemMutexRequest(m->m_mutex, RT_INDEFINITE_WAIT);
-        AssertReleaseRC(rc);
-#endif
+        if (inso != NULL) {
+            VBOX_SLIRP_UNLOCK(inso->so_mutex);
+        }
+        VBOX_SLIRP_LOCK(m->m_mutex);
 
 
@@ -379,45 +374,31 @@
 	 */
 findso:
-#ifdef VBOX_WITH_SYNC_SLIRP
-        rc = RTSemMutexRequest(pData->tcp_last_so_mutex, RT_INDEFINITE_WAIT);
-        AssertReleaseRC(rc);
-#endif
+        if (so != NULL) {
+            VBOX_SLIRP_UNLOCK(so->so_mutex);
+        }
+        VBOX_SLIRP_LOCK(pData->tcp_last_so_mutex);
 	so = tcp_last_so;
-#ifdef VBOX_WITH_SYNC_SLIRP
         /* this checking for making sure that we're not trying to hold mutex on head list*/
         if (tcp_last_so != &tcb) {
-            rc = RTSemMutexRequest(so->so_mutex, RT_INDEFINITE_WAIT);
-            AssertReleaseRC(rc);
+            VBOX_SLIRP_LOCK(so->so_mutex);
         }
-        rc = RTSemMutexRelease(pData->tcp_last_so_mutex);
-        AssertReleaseRC(rc);
-#endif
+        VBOX_SLIRP_UNLOCK(pData->tcp_last_so_mutex);
+
 	if (so->so_fport != ti->ti_dport ||
 	    so->so_lport != ti->ti_sport ||
 	    so->so_laddr.s_addr != ti->ti_src.s_addr ||
 	    so->so_faddr.s_addr != ti->ti_dst.s_addr) {
-#ifndef VBOX_WITH_SYNC_SLIRP
-		so = solookup(&tcb, ti->ti_src, ti->ti_sport,
-			       ti->ti_dst, ti->ti_dport);
-		if (so)
-			tcp_last_so = so;
-#else
                 /*To make sure that we don't try to release mutex on head of the socket queue*/
                 if (so != &tcb) {
-                    rc = RTSemMutexRelease(so->so_mutex);
-                    AssertReleaseRC(rc);
+                    VBOX_SLIRP_UNLOCK(so->so_mutex);
                 }
 		so = solookup(&tcb, ti->ti_src, ti->ti_sport,
 			       ti->ti_dst, ti->ti_dport);
 		if (so) {
-                        rc = RTSemMutexRequest(so->so_mutex, RT_INDEFINITE_WAIT);
-                        AssertReleaseRC(rc);
-                        rc = RTSemMutexRequest(pData->tcp_last_so_mutex, RT_INDEFINITE_WAIT);
-                        AssertReleaseRC(rc);
+                        VBOX_SLIRP_LOCK(so->so_mutex);
+                        VBOX_SLIRP_LOCK(pData->tcp_last_so_mutex);
 			tcp_last_so = so;
-                        rc = RTSemMutexRelease(pData->tcp_last_so_mutex);
-                        AssertReleaseRC(rc);
+                        VBOX_SLIRP_UNLOCK(pData->tcp_last_so_mutex);
                 }
-#endif
 		++tcpstat.tcps_socachemiss;
 	}
@@ -442,15 +423,9 @@
 	  if ((so = socreate()) == NULL)
 	    goto dropwithreset;
-#ifdef VBOX_WITH_SYNC_SLIRP
-          rc = RTSemMutexRequest(so->so_mutex, RT_INDEFINITE_WAIT);
-          AssertReleaseRC(rc);
-#endif
+
+          VBOX_SLIRP_LOCK(so->so_mutex);
 	  if (tcp_attach(pData, so) < 0) {
-#ifdef VBOX_WITH_SYNC_SLIRP
-            rc = RTSemMutexRelease(so->so_mutex);
-            AssertReleaseRC(rc);
-            rc = RTSemMutexDestroy(so->so_mutex);
-            AssertReleaseRC(rc);
-#endif
+            VBOX_SLIRP_UNLOCK(so->so_mutex);
+            VBOX_SLIRP_LOCK_DESTROY(so->so_mutex);
 	    free(so); /* Not sofree (if it failed, it's not insqued) */
 #ifdef VBOX_WITH_SYNC_SLIRP
@@ -574,10 +549,7 @@
 				tp->snd_una = ti->ti_ack;
 				m_freem(pData, m);
-#ifdef VBOX_WITH_SYNC_SLIRP
                                 if (m != NULL) {
-                                    rc = RTSemMutexRelease(m->m_mutex);
-                                    AssertReleaseRC(rc);
+                                    VBOX_SLIRP_UNLOCK(m->m_mutex);
                                 }
-#endif
 
 				/*
@@ -609,8 +581,5 @@
 				if (so->so_snd.sb_cc)
 					(void) tcp_output(pData, tp);
-#ifdef VBOX_WITH_SYNC_SLIRP
-                                rc = RTSemMutexRelease(so->so_mutex);
-                                AssertReleaseRC(rc);
-#endif
+                                VBOX_SLIRP_UNLOCK(so->so_mutex);
 				return;
 			}
@@ -652,12 +621,8 @@
 			tp->t_flags |= TF_ACKNOW;
 			tcp_output(pData, tp);
-#ifdef VBOX_WITH_SYNC_SLIRP
-                                rc = RTSemMutexRelease(so->so_mutex);
-                                AssertReleaseRC(rc);
-                                if (m != NULL) {
-                                    rc = RTSemMutexRelease(m->m_mutex);
-                                    AssertReleaseRC(rc);
-                                }
-#endif
+                        VBOX_SLIRP_UNLOCK(so->so_mutex);
+                        if (m != NULL) {
+                           VBOX_SLIRP_UNLOCK(m->m_mutex);
+                        }
 			return;
 		}
@@ -760,10 +725,7 @@
 	    tp = tcp_close(pData, tp);
 	    m_free(pData, m);
-#ifdef VBOX_WITH_SYNC_SLIRP
             if (m != NULL) {
-                rc = RTSemMutexRelease(m->m_mutex);
-                AssertReleaseRC(rc);
+                VBOX_SLIRP_UNLOCK(m->m_mutex);
             }
-#endif
 	  } else {
 	    /*
@@ -778,12 +740,8 @@
 	    tp->t_state = TCPS_SYN_RECEIVED;
 	  }
-#ifdef VBOX_WITH_SYNC_SLIRP
-          rc = RTSemMutexRelease(so->so_mutex);
-          AssertReleaseRC(rc);
+          VBOX_SLIRP_UNLOCK(so->so_mutex);
           if (m != NULL) {
-            rc = RTSemMutexRelease(m->m_mutex);
-            AssertReleaseRC(rc);
+            VBOX_SLIRP_UNLOCK(m->m_mutex);
           }
-#endif
 	  return;
 
@@ -1543,13 +1501,9 @@
 		(void) tcp_output(pData, tp);
 	}
-#ifdef VBOX_WITH_SYNC_SLIRP
-          rc = RTSemMutexRelease(so->so_mutex);
-          AssertReleaseRC(rc);
-
+
+          VBOX_SLIRP_UNLOCK(so->so_mutex);
           if (m != NULL) {
-            rc = RTSemMutexRelease(m->m_mutex);
-            AssertReleaseRC(rc);
+            VBOX_SLIRP_UNLOCK(m->m_mutex);
           }
-#endif
 	return;
 
@@ -1564,12 +1518,8 @@
 	tp->t_flags |= TF_ACKNOW;
 	(void) tcp_output(pData, tp);
-#ifdef VBOX_WITH_SYNC_SLIRP
-          rc = RTSemMutexRelease(so->so_mutex);
-          AssertReleaseRC(rc);
-          if (m != NULL) {
-            rc = RTSemMutexRelease(m->m_mutex);
-            AssertReleaseRC(rc);
-          }
-#endif
+        VBOX_SLIRP_UNLOCK(so->so_mutex);
+        if (m != NULL) {
+          VBOX_SLIRP_UNLOCK(m->m_mutex);
+        }
 	return;
 
@@ -1584,12 +1534,6 @@
 	}
 
-#ifdef VBOX_WITH_SYNC_SLIRP
-          rc = RTSemMutexRelease(so->so_mutex);
-          AssertReleaseRC(rc);
-          if (m != NULL) {
-            rc = RTSemMutexRelease(m->m_mutex);
-            AssertReleaseRC(rc);
-          }
-#endif
+        if (so != NULL) VBOX_SLIRP_UNLOCK(so->so_mutex);
+        if (m != NULL) VBOX_SLIRP_UNLOCK(m->m_mutex);
 	return;
 
@@ -1599,12 +1543,8 @@
 	 */
 	m_free(pData, m);
-#ifdef VBOX_WITH_SYNC_SLIRP
-          rc = RTSemMutexRelease(so->so_mutex);
-          AssertReleaseRC(rc);
-          if (m != NULL) {
-            rc = RTSemMutexRelease(m->m_mutex);
-            AssertReleaseRC(rc);
-          }
-#endif
+        VBOX_SLIRP_UNLOCK(so->so_mutex);
+        if (m != NULL) {
+          VBOX_SLIRP_UNLOCK(m->m_mutex);
+        }
 
 	return;
Index: /trunk/src/VBox/Devices/Network/slirp/tcp_timer.c
===================================================================
--- /trunk/src/VBox/Devices/Network/slirp/tcp_timer.c	(revision 13709)
+++ /trunk/src/VBox/Devices/Network/slirp/tcp_timer.c	(revision 13710)
@@ -52,19 +52,18 @@
 	DEBUG_CALL("tcp_fasttimo");
 
+        VBOX_SLIRP_LOCK(pData->tcb_mutex);
+	so = tcb.so_next;
 #ifndef VBOX_WITH_SYNC_SLIRP
-	so = tcb.so_next;
 	if (so)
-	for (; so != &tcb; so = so->so_next)
+	for (; so != &tcb; so = so->so_next) {
 #else
-        RTSemMutexRequest(pData->tcb_mutex, RT_INDEFINITE_WAIT);
-        so = tcb.so_next;
         while(1) {
             if ( so == &tcb) {
-                RTSemMutexRelease(pData->tcb_mutex);
+                VBOX_SLIRP_UNLOCK(pData->tcb_mutex);
                 break;
             }
             so_next = so->so_next;
-            RTSemMutexRequest(so->so_mutex, RT_INDEFINITE_WAIT);
-            RTSemMutexRelease(pData->tcb_mutex);
+            VBOX_SLIRP_LOCK(so->so_mutex);
+            VBOX_SLIRP_UNLOCK(pData->tcb_mutex);
 #endif
 		if ((tp = (struct tcpcb *)so->so_tcpcb) &&
@@ -75,10 +74,10 @@
 			(void) tcp_output(pData, tp);
 		}
+                VBOX_SLIRP_LOCK(pData->tcb_mutex);
+                VBOX_SLIRP_UNLOCK(so->so_mutex);
 #ifdef VBOX_WITH_SYNC_SLIRP
-                RTSemMutexRequest(pData->tcb_mutex, RT_INDEFINITE_WAIT);
-                RTSemMutexRelease(so->so_mutex);
                 so = so_next;
+#endif
         }
-#endif
 
 }
@@ -101,33 +100,28 @@
 	 * Search through tcb's and update active timers.
 	 */
+        VBOX_SLIRP_LOCK(pData->tcb_mutex);
+	ip = tcb.so_next;
 #ifndef VBOX_WITH_SYNC_SLIRP
-	ip = tcb.so_next;
 	if (ip == 0)
 	   return;
 	for (; ip != &tcb; ip = ipnxt) {
 #else
-        RTSemMutexRequest(pData->tcb_mutex, RT_INDEFINITE_WAIT);
-        ip = tcb.so_next;
         if (ip == NULL) {
-            RTSemMutexRelease(pData->tcb_mutex);
+            VBOX_SLIRP_UNLOCK(pData->tcb_mutex);
             return;
         }
         while (1) {
                 if (ip == &tcb) {
-                    RTSemMutexRelease(pData->tcb_mutex);
+                    VBOX_SLIRP_UNLOCK(pData->tcb_mutex);
                     break;
                 }
                 ipnxt = ip->so_next;
-                RTSemMutexRequest(ip->so_mutex, RT_INDEFINITE_WAIT);
-                RTSemMutexRelease(pData->tcb_mutex);
+                VBOX_SLIRP_LOCK(ip->so_mutex);
+                VBOX_SLIRP_UNLOCK(pData->tcb_mutex);
 #endif
 		ipnxt = ip->so_next;
 		tp = sototcpcb(ip);
 		if (tp == 0)
-#ifndef VBOX_WITH_SYNC_SLIRP
-			continue;
-#else
-                        goto before_loop_ends;
-#endif
+                        goto before_loop_ends; /*vvl:the same as continue in original code*/
 		for (i = 0; i < TCPT_NTIMERS; i++) {
 			if (tp->t_timer[i] && --tp->t_timer[i] == 0) {
@@ -142,8 +136,8 @@
 tpgone:
 		;
+before_loop_ends:
+                VBOX_SLIRP_LOCK(pData->tcb_mutex);
+                VBOX_SLIRP_UNLOCK(ip->so_mutex);
 #ifdef VBOX_WITH_SYNC_SLIRP
-before_loop_ends:
-                RTSemMutexRequest(pData->tcb_mutex, RT_INDEFINITE_WAIT);
-                RTSemMutexRelease(ip->so_mutex);
                 ip=ipnxt;
 #endif
Index: /trunk/src/VBox/Devices/Network/slirp/udp.c
===================================================================
--- /trunk/src/VBox/Devices/Network/slirp/udp.c	(revision 13709)
+++ /trunk/src/VBox/Devices/Network/slirp/udp.c	(revision 13710)
@@ -77,9 +77,6 @@
 	DEBUG_ARG("m = %lx", (long)m);
 	DEBUG_ARG("iphlen = %d", iphlen);
-#ifdef VBOX_WITH_SYNC_SLIRP
-        int rc;
-        rc = RTSemMutexRequest(m->m_mutex, RT_INDEFINITE_WAIT);
-        AssertReleaseRC(rc);
-#endif
+
+        VBOX_SLIRP_LOCK(m->m_mutex);
 
 	udpstat.udps_ipackets++;
@@ -161,47 +158,35 @@
 	 * Locate pcb for datagram.
 	 */
-#ifndef VBOX_WITH_SYNC_SLIRP
-	so = udp_last_so;
+        VBOX_SLIRP_LOCK(pData->udp_last_so_mutex);
+        so = udp_last_so;
+        if (so != &udb) {
+            VBOX_SLIRP_LOCK(so->so_mutex);
+        }
+
+        VBOX_SLIRP_UNLOCK(pData->udp_last_so_mutex);
+
 	if (so->so_lport != uh->uh_sport ||
 	    so->so_laddr.s_addr != ip->ip_src.s_addr) {
 		struct socket *tmp;
+                if (so != &udb) {
+                    /*we don't interesting in this socket any more*/
+                    VBOX_SLIRP_UNLOCK(so->so_mutex);
+                }
+#ifndef VBOX_WITH_SYNC_SLIRP
 		for (tmp = udb.so_next; tmp != &udb; tmp = tmp->so_next) {
 #else
-        rc = RTSemMutexRequest(pData->udp_last_so_mutex, RT_INDEFINITE_WAIT);
-        AssertReleaseRC(rc);
-
-        so = udp_last_so;
-        if (so != &udb) {
-            rc = RTSemMutexRequest(so->so_mutex, RT_INDEFINITE_WAIT);
-            AssertReleaseRC(rc);
-        }
-
-        rc = RTSemMutexRelease(pData->udp_last_so_mutex);
-        AssertReleaseRC(rc);
-
-	if (so->so_lport != uh->uh_sport ||
-	    so->so_laddr.s_addr != ip->ip_src.s_addr) {
-		struct socket *tmp;
+
 		struct socket *tmp_next;
-            if (so != &udb) {
-                /*we don't interesting in this socket any more*/
-                rc = RTSemMutexRelease(so->so_mutex);
-                AssertReleaseRC(rc);
-            }
-            rc = RTSemMutexRequest(pData->udb_mutex, RT_INDEFINITE_WAIT);
-            AssertReleaseRC(rc);
-            tmp = udb.so_next;
-
-            while (1) {
-                if (tmp == &udb) {
-                    rc = RTSemMutexRelease(pData->udb_mutex);
-                    AssertReleaseRC(rc);
-                    break;
-                }
-                tmp_next = tmp->so_next;
-                rc = RTSemMutexRequest(tmp->so_mutex, RT_INDEFINITE_WAIT);
-                AssertReleaseRC(rc);
-                rc = RTSemMutexRelease(pData->udb_mutex);
-                AssertReleaseRC(rc);
+                VBOX_SLIRP_LOCK(pData->udb_mutex);
+                tmp = udb.so_next;
+
+                while (1) {
+                    if (tmp == &udb) {
+                        VBOX_SLIRP_UNLOCK(pData->udb_mutex);
+                        break; /* end of loop*/
+                    }
+                    VBOX_SLIRP_LOCK(tmp->so_mutex);
+                    VBOX_SLIRP_UNLOCK(pData->udb_mutex);
+                    tmp_next = tmp->so_next;
 #endif
 			if (tmp->so_lport == uh->uh_sport &&
@@ -210,9 +195,7 @@
 				break;
 			}
+                        VBOX_SLIRP_UNLOCK(tmp->so_mutex);
+                        VBOX_SLIRP_LOCK(pData->udb_mutex);
 #ifdef VBOX_WITH_SYNC_SLIRP
-                        rc = RTSemMutexRelease(tmp->so_mutex);
-                        AssertReleaseRC(rc);
-                        rc = RTSemMutexRequest(pData->udb_mutex, RT_INDEFINITE_WAIT);
-                        AssertReleaseRC(rc);
                         tmp = tmp_next;
 #endif
@@ -221,14 +204,8 @@
 		  so = NULL;
 		} else {
-#ifdef VBOX_WITH_SYNC_SLIRP
-                  rc = RTSemMutexRequest(pData->udp_last_so_mutex, RT_INDEFINITE_WAIT);
-                  AssertReleaseRC(rc);
-#endif
 		  udpstat.udpps_pcbcachemiss++;
+                  VBOX_SLIRP_LOCK(pData->udp_last_so_mutex);
 		  udp_last_so = so;
-#ifdef VBOX_WITH_SYNC_SLIRP
-                  rc = RTSemMutexRelease(pData->udp_last_so_mutex);
-                  AssertReleaseRC(rc);
-#endif
+                  VBOX_SLIRP_UNLOCK(pData->udp_last_so_mutex);
 		}
 	}
@@ -244,8 +221,5 @@
 	   */
 	  if ((so = socreate()) == NULL) goto bad;
-#ifdef VBOX_WITH_SYNC_SLIRP
-          rc = RTSemMutexRequest(so->so_mutex, RT_INDEFINITE_WAIT);
-          AssertReleaseRC(rc);
-#endif
+          VBOX_SLIRP_LOCK(so->so_mutex);
 	  if(udp_attach(pData, so) == -1) {
 	    DEBUG_MISC((dfd," udp_attach errno = %d-%s\n",
@@ -300,20 +274,13 @@
 	so->so_m=m;         /* ICMP backup */
 
-#ifdef VBOX_WITH_SYNC_SLIRP
-        rc = RTSemMutexRelease(so->so_mutex);
-        AssertReleaseRC(rc);
-        rc = RTSemMutexRelease(m->m_mutex);
-        AssertReleaseRC(rc);
-#endif
+        VBOX_SLIRP_UNLOCK(so->so_mutex);
+        VBOX_SLIRP_UNLOCK(m->m_mutex);
 	return;
 bad:
 	m_freem(pData, m);
 	/* if (opts) m_freem(opts); */
-#ifdef VBOX_WITH_SYNC_SLIRP
         if (m != NULL) {
-            rc = RTSemMutexRelease(m->m_mutex);
-            AssertReleaseRC(rc);
+            VBOX_SLIRP_UNLOCK(m->m_mutex);
         }
-#endif
 	return;
 }
@@ -325,13 +292,8 @@
 	register struct udpiphdr *ui;
 	int error = 0;
-#ifdef VBOX_WITH_SYNC_SLIRP
-        int rc;
         if(so != NULL) {
-            rc = RTSemMutexRequest(so->so_mutex, RT_INDEFINITE_WAIT);
-            AssertReleaseRC(rc);
+            VBOX_SLIRP_LOCK(so->so_mutex);
         }
-        rc = RTSemMutexRequest(m->m_mutex, RT_INDEFINITE_WAIT);
-        AssertReleaseRC(rc);
-#endif
+        VBOX_SLIRP_LOCK(m->m_mutex);
 
 	DEBUG_CALL("udp_output");
@@ -379,8 +341,6 @@
 
 	error = ip_output(pData, so, m);
-#ifdef VBOX_WITH_SYNC_SLIRP
-        if (so != NULL) rc = RTSemMutexRelease(so->so_mutex);
-        rc = RTSemMutexRelease(m->m_mutex);
-#endif
+        if (so != NULL) VBOX_SLIRP_UNLOCK(so->so_mutex);
+        VBOX_SLIRP_UNLOCK(m->m_mutex);
 	return (error);
 }
@@ -390,10 +350,6 @@
 {
     struct sockaddr_in saddr, daddr;
-#ifdef VBOX_WITH_SYNC_SLIRP
     int status;
-    int rc;
-    rc = RTSemMutexRequest(so->so_mutex, RT_INDEFINITE_WAIT);
-    AssertReleaseRC(rc);
-#endif
+    VBOX_SLIRP_LOCK(so->so_mutex);
 
     saddr = *addr;
@@ -412,12 +368,7 @@
     daddr.sin_port = so->so_lport;
 
-#ifdef VBOX_WITH_SYNC_SLIRP
     status = udp_output2(pData, so, m, &saddr, &daddr, so->so_iptos);
-    rc = RTSemMutexRelease(so->so_mutex);
-    AssertReleaseRC(rc);
+    VBOX_SLIRP_UNLOCK(so->so_mutex);
     return status;
-#else
-    return udp_output2(pData, so, m, &saddr, &daddr, so->so_iptos);
-#endif
 }
 
@@ -426,9 +377,5 @@
 {
   struct sockaddr_in addr;
-#ifdef VBOX_WITH_SYNC_SLIRP
-    int rc;
-    rc = RTSemMutexRequest(so->so_mutex, RT_INDEFINITE_WAIT);
-    AssertReleaseRC(rc);
-#endif
+    VBOX_SLIRP_LOCK(so->so_mutex);
 
   if((so->s = socket(AF_INET,SOCK_DGRAM,0)) != -1) {
@@ -445,7 +392,4 @@
       closesocket(so->s);
       so->s=-1;
-#ifdef VBOX_WITH_SYNC_SLIRP
-     AssertRelease(so->s != -1);
-#endif
 #ifdef _WIN32
       WSASetLastError(lasterrno);
@@ -459,20 +403,13 @@
       /* enable broadcast for later use */
       setsockopt(so->s, SOL_SOCKET, SO_BROADCAST, (const char *)&opt, sizeof(opt));
-#ifdef VBOX_WITH_SYNC_SLIRP
-     rc = RTSemMutexRequest(pData->udb_mutex, RT_INDEFINITE_WAIT);
-     AssertReleaseRC(rc);
-#endif
+      VBOX_SLIRP_LOCK(pData->udb_mutex);
       insque(pData, so,&udb);
-#ifdef VBOX_WITH_SYNC_SLIRP
-     rc = RTSemMutexRelease(pData->udb_mutex);
-     AssertReleaseRC(rc);
-#endif
+      VBOX_SLIRP_UNLOCK(pData->udb_mutex);
     }
   }
 #ifdef VBOX_WITH_SYNC_SLIRP
   so->so_type = IPPROTO_UDP;
-  rc = RTSemMutexRelease(so->so_mutex);
-  AssertReleaseRC(rc);
-#endif
+#endif
+  VBOX_SLIRP_UNLOCK(so->so_mutex);
   return(so->s);
 }
@@ -482,26 +419,16 @@
 {
 	/* Correctly update list if detaching last socket in list. */
-#ifdef VBOX_WITH_SYNC_SLIRP
-        int rc;
-        rc = RTSemMutexRequest(so->so_mutex, RT_INDEFINITE_WAIT);
-        AssertReleaseRC(rc);
-        rc = RTSemMutexRequest(pData->udp_last_so_mutex, RT_INDEFINITE_WAIT);
-        AssertReleaseRC(rc);
-#endif
+        VBOX_SLIRP_LOCK(so->so_mutex);
+        VBOX_SLIRP_LOCK(pData->udp_last_so_mutex);
 	if (so == udp_last_so) udp_last_so = &udb;
-#ifdef VBOX_WITH_SYNC_SLIRP
-        rc = RTSemMutexRelease(pData->udp_last_so_mutex);
-        AssertReleaseRC(rc);
-#endif
+        VBOX_SLIRP_UNLOCK(pData->udp_last_so_mutex);
 	closesocket(so->s);
 	/* if (so->so_m) m_free(so->so_m);    done by sofree */
 
 	sofree(pData, so);
-#ifdef VBOX_WITH_SYNC_SLIRP
+
         if (so != NULL) {
-            rc = RTSemMutexRelease(so->so_mutex);
-            AssertReleaseRC(rc);
+            VBOX_SLIRP_UNLOCK(so->so_mutex);
         }
-#endif
 }
 
@@ -519,20 +446,11 @@
 {
 	int i = 0;
-#ifdef VBOX_WITH_SYNC_SLIRP
-        int rc;
-#endif
 
 	while(udptos[i].tos) {
 		if ((udptos[i].fport && ntohs(so->so_fport) == udptos[i].fport) ||
 		    (udptos[i].lport && ntohs(so->so_lport) == udptos[i].lport)) {
-#ifdef VBOX_WITH_SYNC_SLIRP
-                        rc = RTSemMutexRequest(so->so_mutex, RT_INDEFINITE_WAIT);
-                        AssertReleaseRC(rc);
-#endif
+                        VBOX_SLIRP_LOCK(so->so_mutex);
 		    	so->so_emu = udptos[i].emu;
-#ifdef VBOX_WITH_SYNC_SLIRP
-                        rc = RTSemMutexRelease(so->so_mutex);
-                        AssertReleaseRC(rc);
-#endif
+                        VBOX_SLIRP_UNLOCK(so->so_mutex);
 			return udptos[i].tos;
 		}
@@ -555,7 +473,4 @@
 	struct sockaddr_in addr;
         socklen_t addrlen = sizeof(addr);
-#ifdef VBOX_WITH_SYNC_SLIRP
-        int rc;
-#endif
 #ifdef EMULATE_TALK
 	CTL_MSG_OLD *omsg;
@@ -587,12 +502,9 @@
 } *cu_head;
 
+        VBOX_SLIRP_LOCK(so->so_mutex);
 #ifdef VBOX_WITH_SYNC_SLIRP
-        rc = RTSemMutexRequest(so->so_mutex, RT_INDEFINITE_WAIT);
-        AssertReleaseRC(rc);
 #define return \
                 do {                                        \
-                    int rc;                                 \
-                    rc = RTSemMutexRelease(so->so_mutex);   \
-                    AssertReleaseRC(rc);                    \
+                    VBOX_SLIRP_UNLOCK(so->so_mutex);        \
                     return;                                 \
                 }while(0)
@@ -789,4 +701,5 @@
 		return;
 	}
+/*see macro definition in the begining of method*/
 #ifdef VBOX_WITH_SYNC_SLIRP
     return;
@@ -802,7 +715,4 @@
 	socklen_t addrlen = sizeof(struct sockaddr_in);
         int opt = 1;
-#ifdef VBOX_WITH_SYNC_SLIRP
-        int rc;
-#endif
 
 	if ((so = socreate()) == NULL) {
@@ -812,15 +722,8 @@
 	so->s = socket(AF_INET,SOCK_DGRAM,0);
 	so->so_expire = curtime + SO_EXPIRE;
-#ifdef VBOX_WITH_SYNC_SLIRP
-        rc = RTSemMutexRequest(so->so_mutex, RT_INDEFINITE_WAIT);
-        AssertReleaseRC(rc);
-        rc = RTSemMutexRequest(pData->udb_mutex, RT_INDEFINITE_WAIT);
-        AssertReleaseRC(rc);
-#endif
+        VBOX_SLIRP_LOCK(so->so_mutex);
+        VBOX_SLIRP_LOCK(pData->udb_mutex);
 	insque(pData, so,&udb);
-#ifdef VBOX_WITH_SYNC_SLIRP
-        rc = RTSemMutexRelease(pData->udb_mutex);
-        AssertReleaseRC(rc);
-#endif
+        VBOX_SLIRP_UNLOCK(pData->udb_mutex);
 
 	addr.sin_family = AF_INET;
@@ -830,8 +733,5 @@
 	if (bind(so->s,(struct sockaddr *)&addr, addrlen) < 0) {
 		udp_detach(pData, so);
-#ifdef VBOX_WITH_SYNC_SLIRP
-                rc = RTSemMutexRelease(so->so_mutex);
-                AssertReleaseRC(rc);
-#endif
+                VBOX_SLIRP_UNLOCK(so->so_mutex);
 		return NULL;
 	}
@@ -855,8 +755,5 @@
 
 	so->so_state = SS_ISFCONNECTED;
-#ifdef VBOX_WITH_SYNC_SLIRP
-        rc = RTSemMutexRelease(so->so_mutex);
-        AssertReleaseRC(rc);
-#endif
+        VBOX_SLIRP_UNLOCK(so->so_mutex);
 
 	return so;
