Index: /trunk/src/VBox/Devices/Network/slirp/slirp.c
===================================================================
--- /trunk/src/VBox/Devices/Network/slirp/slirp.c	(revision 13726)
+++ /trunk/src/VBox/Devices/Network/slirp/slirp.c	(revision 13727)
@@ -203,7 +203,4 @@
 {
     int fNATfailed = 0;
-#ifdef VBOX_WITH_SYNC_SLIRP
-    int rc = 0;
-#endif
     PNATState pData = malloc(sizeof(NATState));
     *ppData = pData;
@@ -230,18 +227,10 @@
 #endif
 
-#ifdef VBOX_WITH_SYNC_SLIRP
-    rc = RTSemMutexCreate(&pData->tcb_mutex);
-    AssertReleaseRC(rc);
-    rc = RTSemMutexCreate(&pData->tcp_last_so_mutex);
-    AssertReleaseRC(rc);
-    rc = RTSemMutexCreate(&pData->udb_mutex);
-    AssertReleaseRC(rc);
-    rc = RTSemMutexCreate(&pData->udp_last_so_mutex);
-    AssertReleaseRC(rc);
-    rc = RTSemMutexCreate(&pData->if_queued_mutex);
-    AssertReleaseRC(rc);
-    rc = RTSemMutexCreate(&pData->next_m_mutex);
-    AssertReleaseRC(rc);
-#endif
+    VBOX_SLIRP_LOCK_CREATE(&pData->tcb_mutex);
+    VBOX_SLIRP_LOCK_CREATE(&pData->tcp_last_so_mutex);
+    VBOX_SLIRP_LOCK_CREATE(&pData->udb_mutex);
+    VBOX_SLIRP_LOCK_CREATE(&pData->udp_last_so_mutex);
+    VBOX_SLIRP_LOCK_CREATE(&pData->if_queued_mutex);
+    VBOX_SLIRP_LOCK_CREATE(&pData->next_m_mutex);
 
     Assert(sizeof(struct ip) == 20);
@@ -379,24 +368,21 @@
 		 * in the fragment queue, or there are TCP connections active
 		 */
-#ifndef VBOX_WITH_SYNC_SLIRP
+                VBOX_SLIRP_LOCK(pData->tcb_mutex);
 		do_slowtimo = ((tcb.so_next != &tcb) ||
 			       ((struct ipasfrag *)&ipq != u32_to_ptr(pData, ipq.next, struct ipasfrag *)));
 
+                so = tcb.so_next;
+#ifndef VBOX_WITH_SYNC_SLIRP
 		for (so = tcb.so_next; so != &tcb; so = so_next) {
-			so_next = so->so_next;
 #else
-                RTSemMutexRequest(pData->tcb_mutex, RT_INDEFINITE_WAIT);
-                so = tcb.so_next;
-		do_slowtimo = ((so != &tcb) ||
-			       ((struct ipasfrag *)&ipq != u32_to_ptr(pData, ipq.next, struct ipasfrag *)));
                 while (1) {
                     if (so == &tcb) {
-                        RTSemMutexRelease(pData->tcb_mutex);
+                        VBOX_SLIRP_UNLOCK(pData->tcb_mutex);
                         break;
                     }
+#endif
                     so_next = so->so_next;
-                    RTSemMutexRequest(so->so_mutex, RT_INDEFINITE_WAIT);
-                    RTSemMutexRelease(pData->tcb_mutex);
-#endif
+                    VBOX_SLIRP_LOCK(so->so_mutex);
+                    VBOX_SLIRP_UNLOCK(pData->tcb_mutex);
 
 			/*
@@ -411,9 +397,5 @@
 	 		 */
 			if (so->so_state & SS_NOFDREF || so->s == -1)
-#ifndef VBOX_WITH_SYNC_SLIRP
-				continue;
-#else
                                 goto before_loop_ends;
-#endif
 
 			/*
@@ -423,9 +405,5 @@
                                 FD_SET(so->s, readfds);
 				UPD_NFDS(so->s);
-#ifndef VBOX_WITH_SYNC_SLIRP
-				continue;
-#else
                                 goto before_loop_ends;
-#endif
 			}
 
@@ -436,9 +414,5 @@
 				FD_SET(so->s, writefds);
 				UPD_NFDS(so->s);
-#ifndef VBOX_WITH_SYNC_SLIRP
-				continue;
-#else
                                 goto before_loop_ends;
-#endif
 			}
 
@@ -461,9 +435,9 @@
 				UPD_NFDS(so->s);
 			}
-#ifdef VBOX_WITH_SYNC_SLIRP
                 before_loop_ends:
                         /*Release of global tcb mutex happens in the head of loop*/
-                        RTSemMutexRelease(so->so_mutex);
-                        RTSemMutexRequest(pData->tcb_mutex, RT_INDEFINITE_WAIT);
+                        VBOX_SLIRP_UNLOCK(so->so_mutex);
+                        VBOX_SLIRP_LOCK(pData->tcb_mutex);
+#ifdef VBOX_WITH_SYNC_SLIRP
                         so = so_next;
 #endif
@@ -473,19 +447,18 @@
 		 * UDP sockets
 		 */
+                VBOX_SLIRP_LOCK(pData->udb_mutex);
+                so = udb.so_next;
 #ifndef VBOX_WITH_SYNC_SLIRP
 		for (so = udb.so_next; so != &udb; so = so_next) {
-			so_next = so->so_next;
 #else
-                RTSemMutexRequest(pData->udb_mutex, RT_INDEFINITE_WAIT);
-                so = udb.so_next;
                 while(1) {
                     if (so == &udb) {
-                        RTSemMutexRelease(pData->udb_mutex);
+                        VBOX_SLIRP_UNLOCK(pData->udb_mutex);
                         break;
                     }
-                so_next = so->so_next;
-                RTSemMutexRequest(so->so_mutex, RT_INDEFINITE_WAIT);
-                RTSemMutexRelease(pData->udb_mutex);
-#endif
+#endif
+                    so_next = so->so_next;
+                    VBOX_SLIRP_LOCK(so->so_mutex);
+                    VBOX_SLIRP_UNLOCK(pData->udb_mutex);
 
 			/*
@@ -495,9 +468,5 @@
 				if (so->so_expire <= curtime) {
 					udp_detach(pData, so);
-#ifndef VBOX_WITH_SYNC_SLIRP
-					continue;
-#else
                                         goto before_udp_loop_end;
-#endif
 				} else
 					do_slowtimo = 1; /* Let socket expire */
@@ -518,8 +487,8 @@
 				UPD_NFDS(so->s);
 			}
+                        before_udp_loop_end:
+                        VBOX_SLIRP_UNLOCK(so->so_mutex);
+                        VBOX_SLIRP_LOCK(pData->udb_mutex);
 #ifdef VBOX_WITH_SYNC_SLIRP
-                        before_udp_loop_end:
-                        RTSemMutexRelease(so->so_mutex);
-                        RTSemMutexRequest(pData->udb_mutex, RT_INDEFINITE_WAIT);
                         so = so_next;
 #endif
@@ -593,19 +562,18 @@
 		 * Check TCP sockets
 		 */
+                VBOX_SLIRP_LOCK(pData->tcb_mutex);
+                so = tcb.so_next;
 #ifndef VBOX_WITH_SYNC_SLIRP
 		for (so = tcb.so_next; so != &tcb; so = so_next) {
-			so_next = 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);
-#endif
+#endif
+                    so_next = so->so_next;
+                    VBOX_SLIRP_LOCK(so->so_mutex);
+                    VBOX_SLIRP_UNLOCK(pData->tcb_mutex);
 
 			/*
@@ -614,9 +582,5 @@
 			 */
 			if (so->so_state & SS_NOFDREF || so->s == -1)
-#ifndef VBOX_WITH_SYNC_SLIRP
-				continue;
-#else
                                 goto before_loop_ends;
-#endif
 
 			/*
@@ -636,9 +600,5 @@
 				if (so->so_state & SS_FACCEPTCONN) {
 					tcp_connect(pData, so);
-#ifndef VBOX_WITH_SYNC_SLIRP
-				        continue;
-#else
                                         goto before_loop_ends;
-#endif
 				} /* else */
 				ret = soread(pData, so);
@@ -672,9 +632,5 @@
 			      if (errno == EAGAIN || errno == EWOULDBLOCK ||
 				  errno == EINPROGRESS || errno == ENOTCONN)
-#ifndef VBOX_WITH_SYNC_SLIRP
-				        continue;
-#else
                                         goto before_loop_ends;
-#endif
 
 			      /* else failed */
@@ -711,9 +667,5 @@
 			    if (errno == EAGAIN || errno == EWOULDBLOCK ||
 				errno == EINPROGRESS || errno == ENOTCONN)
-#ifndef VBOX_WITH_SYNC_SLIRP
-				        continue;/* Still connecting, continue */
-#else
-                                        goto before_loop_ends;
-#endif
+                                        goto before_loop_ends;/* Still connecting, continue */
 
 			    /* else failed */
@@ -727,9 +679,5 @@
 			      if (errno == EAGAIN || errno == EWOULDBLOCK ||
 				  errno == EINPROGRESS || errno == ENOTCONN)
-#ifndef VBOX_WITH_SYNC_SLIRP
-				        continue;
-#else
                                         goto before_loop_ends;
-#endif
 			      /* else failed */
 			      so->so_state = SS_NOFDREF;
@@ -741,8 +689,8 @@
 			} /* SS_ISFCONNECTING */
 #endif
+                    before_loop_ends:
+                    VBOX_SLIRP_UNLOCK(so->so_mutex);
+                    VBOX_SLIRP_LOCK(pData->tcb_mutex);
 #ifdef VBOX_WITH_SYNC_SLIRP
-                    before_loop_ends:
-                    RTSemMutexRelease(so->so_mutex);
-                    RTSemMutexRequest(pData->tcb_mutex, RT_INDEFINITE_WAIT);
                     so = so_next;
 #endif
@@ -754,26 +702,25 @@
 		 * Incoming UDP data isn't buffered either.
 		 */
+                VBOX_SLIRP_LOCK(pData->udb_mutex);
+                so = udb.so_next;
 #ifndef VBOX_WITH_SYNC_SLIRP
 		for (so = udb.so_next; so != &udb; so = so_next) {
-			so_next = so->so_next;
 #else
-                RTSemMutexRequest(pData->udb_mutex, RT_INDEFINITE_WAIT);
-                so = udb.so_next;
                 while(1) {
                     if (so == &udb) {
-                        RTSemMutexRelease(pData->udb_mutex);
+                        VBOX_SLIRP_UNLOCK(pData->udb_mutex);
                         break;
                     }
+#endif
 		    so_next = so->so_next;
-                    RTSemMutexRequest(so->so_mutex, RT_INDEFINITE_WAIT);
-                    RTSemMutexRelease(pData->udb_mutex);
-#endif
+                    VBOX_SLIRP_LOCK(so->so_mutex);
+                    VBOX_SLIRP_UNLOCK(pData->udb_mutex);
 
 			if (so->s != -1 && FD_ISSET(so->s, readfds)) {
                             sorecvfrom(pData, so);
                         }
+                    VBOX_SLIRP_UNLOCK(so->so_mutex);
+                    VBOX_SLIRP_LOCK(pData->udb_mutex);
 #ifdef VBOX_WITH_SYNC_SLIRP
-                    RTSemMutexRelease(so->so_mutex);
-                    RTSemMutexRequest(pData->udb_mutex, RT_INDEFINITE_WAIT);
                     so = so_next;
 #endif
@@ -790,11 +737,11 @@
 #if 0
         if (link_up) {
-            RTSemMutexRequest(pData->if_queued_mutex, RT_INDEFINITE_WAIT);
+            VBOX_SLIRP_LOCK(pData->if_queued_mutex);
             if (if_queued > 0){
-                RTSemMutexRelease(pData->if_queued_mutex);
+VBOX_SLIRP_UNLOCK(pData->if_queued_mutex);
 	        if_start(pData);
             }
             else {
-                RTSemMutexRelease(pData->if_queued_mutex);
+VBOX_SLIRP_UNLOCK(pData->if_queued_mutex);
             }
         }
@@ -891,7 +838,4 @@
     struct mbuf *m;
     int proto;
-#ifdef VBOX_WITH_SYNC_SLIRP
-    int rc;
-#endif
 
     if (pkt_len < ETH_HLEN)
@@ -909,12 +853,7 @@
 
         m = m_get(pData);
-#ifdef VBOX_WITH_SYNC_SLIRP
-        if (m != NULL) {
-            rc = RTSemMutexRequest(m->m_mutex, RT_INDEFINITE_WAIT);
-            AssertReleaseRC(rc);
-        }
-#endif
         if (!m)
             return;
+        VBOX_SLIRP_LOCK(m->m_mutex);
         /* Note: we add to align the IP header */
         if (M_FREEROOM(m) < pkt_len + 2) {
@@ -928,8 +867,5 @@
 
         ip_input(pData, m);
-#ifdef VBOX_WITH_SYNC_SLIRP
-        rc = RTSemMutexRelease(m->m_mutex);
-        AssertReleaseRC(rc);
-#endif
+        VBOX_SLIRP_UNLOCK(m->m_mutex);
         break;
     default:
Index: /trunk/src/VBox/Devices/Network/slirp/socket.c
===================================================================
--- /trunk/src/VBox/Devices/Network/slirp/socket.c	(revision 13726)
+++ /trunk/src/VBox/Devices/Network/slirp/socket.c	(revision 13727)
@@ -126,5 +126,4 @@
     }
     /* socket's mutex could be released because socket none accessible via queue anymore*/
-    VBOX_SLIRP_UNLOCK(so->so_mutex);
 
     m_free(pData, so->so_m);
@@ -265,6 +264,7 @@
 sorecvoob(PNATState pData, struct socket *so)
 {
-	struct tcpcb *tp = sototcpcb(so);
+	struct tcpcb *tp;
         VBOX_SLIRP_LOCK(so->so_mutex);
+        tp = sototcpcb(so);
 
 	DEBUG_CALL("sorecvoob");
Index: /trunk/src/VBox/Devices/Network/slirp/tcp_timer.c
===================================================================
--- /trunk/src/VBox/Devices/Network/slirp/tcp_timer.c	(revision 13726)
+++ /trunk/src/VBox/Devices/Network/slirp/tcp_timer.c	(revision 13727)
@@ -74,6 +74,6 @@
 			(void) tcp_output(pData, tp);
 		}
+                VBOX_SLIRP_UNLOCK(so->so_mutex);
                 VBOX_SLIRP_LOCK(pData->tcb_mutex);
-                VBOX_SLIRP_UNLOCK(so->so_mutex);
 #ifdef VBOX_WITH_SYNC_SLIRP
                 so = so_next;
@@ -137,6 +137,6 @@
 		;
 before_loop_ends:
+                VBOX_SLIRP_UNLOCK(ip->so_mutex);
                 VBOX_SLIRP_LOCK(pData->tcb_mutex);
-                VBOX_SLIRP_UNLOCK(ip->so_mutex);
 #ifdef VBOX_WITH_SYNC_SLIRP
                 ip=ipnxt;
