Merge origin/netpush (networking code) (XCC)
[akaros.git] / kern / src / net / udp.c
index 1b9e535..6f1e7ad 100644 (file)
@@ -240,11 +240,6 @@ int udp_attach(struct pbuf *p, struct sock *socket) {
 // TODO: figure out if we even need a PCB? or just socket buff. 
 // TODO: test out looking up pcbs.. since matching function may fail
 
-static void wrap_restart_kthread(struct trapframe *tf, uint32_t srcid,
-                                       long a0, long a1, long a2){
-       restart_kthread((struct kthread*) a0);
-}
-
 int udp_input(struct pbuf *p){
        struct udp_hdr *udphdr;
 
@@ -293,27 +288,22 @@ int udp_input(struct pbuf *p){
                struct socket *sock = pcb->pcbsock;
                attach_pbuf(p, &sock->recv_buff);
                struct kthread *kthread;
+               int8_t irq_state = 0;
                /* First notify any blocking recv calls,
                 * 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 {
+               /* TODO: consider a helper with this and tcp.c */
+               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){
+                       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);
-                               }
+                               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);
                }