Merge origin/netpush (networking code) (XCC)
[akaros.git] / kern / src / net / tcp.c
index 6035661..bc3ce94 100644 (file)
@@ -306,16 +306,12 @@ tcp_recved(struct tcp_pcb *pcb, uint16_t len)
          len, pcb->rcv_wnd, TCP_WND - pcb->rcv_wnd);
 }
 
-static void wrap_restart_kthread(struct trapframe *tf, uint32_t srcid,
-                                       long a0, long a1, long a2){
-       restart_kthread((struct kthread*) a0);
-}
-
 /**
  * Default receive callback that is called if the user didn't register
  * a recv callback for the pcb.
  */
 error_t tcp_recv_null(void *arg, struct tcp_pcb *pcb, struct pbuf *p, error_t err) {
+       int8_t irq_state = 0;
        if (pcb == NULL || pcb->pcbsock == NULL) {
                pbuf_free(p);
                return -1;
@@ -331,23 +327,15 @@ error_t tcp_recv_null(void *arg, struct tcp_pcb *pcb, struct pbuf *p, error_t er
                 * then notify anyone who might be waiting in a select
                 */ 
                // multiple people might be waiting on the socket here..
-               kthread = __up_sem(&(sock->sem), FALSE);
-               if (kthread) {
-                        send_kernel_message(core_id(), (amr_t)wrap_restart_kthread, (long)kthread, 0, 0,
-                                                                                                 KMSG_ROUTINE);
-               } else {
+               if (!sem_up_irqsave(&sock->sem, &irq_state)) {
                        // wake up all waiters
                        struct semaphore_entry *sentry, *sentry_tmp;
                        spin_lock(&sock->waiter_lock);
-                 LIST_FOREACH_SAFE(sentry, &(sock->waiters), link, sentry_tmp){
-                               //should only wake up one waiter
-                               kthread = __up_sem(&sentry->sem, true);
-                               if (kthread){
-                               send_kernel_message(core_id(), (amr_t)wrap_restart_kthread, (long)kthread, 0, 0,
-                                                                                                 KMSG_ROUTINE);
-                               }
+                       LIST_FOREACH_SAFE(sentry, &sock->waiters, link, sentry_tmp) {
+                               sem_up_irqsave(&sentry->sem, &irq_state);
                                LIST_REMOVE(sentry, link);
-                               /* do not need to free since all the sentry are stack-based vars */
+                               /* do not need to free since all the sentry are stack-based vars
+                                * */
                        }
                        spin_unlock(&sock->waiter_lock);
                }