parlib: Add __uth_sync_swap and __uth_sync_is_empty
[akaros.git] / user / parlib / asynccall.c
index e6bb8d8..f9c18bd 100644 (file)
@@ -1,16 +1,17 @@
 #include <stdlib.h>
 
-#include <ros/common.h>
+#include <parlib/common.h>
+#include <parlib/assert.h>
+#include <parlib/stdio.h>
 #include <ros/syscall.h>
 #include <ros/ring_syscall.h>
 #include <ros/sysevent.h>
-#include <arc.h>
+#include <parlib/arc.h>
 #include <errno.h>
-#include <arch/arch.h>
+#include <parlib/arch/arch.h>
 #include <sys/param.h>
-#include <arch/atomic.h>
-
-#include <pthread.h>
+#include <parlib/arch/atomic.h>
+#include <parlib/vcore.h>
 
 syscall_desc_pool_t syscall_desc_pool;
 async_desc_pool_t async_desc_pool;
@@ -127,7 +128,8 @@ int async_syscall(arsc_channel_t* chan, syscall_req_t* req, syscall_desc_t** des
        desc->channel = chan;
        syscall_front_ring_t *fr = &(desc->channel->sysfr);
        //TODO: can do it locklessly using CAS, but could change with local async calls
-       mcs_lock_lock(&(chan->aclock));
+       struct mcs_lock_qnode local_qn = {0};
+       mcs_lock_lock(&(chan->aclock), &local_qn);
        if (RING_FULL(fr)) {
                errno = EBUSY;
                return -1;
@@ -147,7 +149,7 @@ int async_syscall(arsc_channel_t* chan, syscall_req_t* req, syscall_desc_t** des
        // won't process any requests until they are marked REQ_ready (also atomic)
        RING_PUSH_REQUESTS(fr);
        //cprintf("DEBUG: sring->req_prod: %d, sring->rsp_prod: %d\n", 
-       mcs_lock_unlock(&desc->channel->aclock);
+       mcs_lock_unlock(&desc->channel->aclock, &local_qn);
        *desc_ptr2 = desc;
        return 0;
 }
@@ -186,7 +188,7 @@ int waiton_syscall(syscall_desc_t* desc)
 {
        int retval = 0;
        if (desc == NULL || desc->channel == NULL){
-               errno = EFAIL;
+               errno = EFAULT;
                return -1;
        }
        // Make sure we were given a desc with a non-NULL frontring.  This could
@@ -194,14 +196,14 @@ int waiton_syscall(syscall_desc_t* desc)
        syscall_front_ring_t *fr =  &desc->channel->sysfr;
        
        if (!fr){
-               errno = EFAIL;
+               errno = EFAULT;
                return -1;
        }
-       printf ("waiting %d\n", pthread_self()->id);
+       printf("waiting %d\n", vcore_id());
        syscall_rsp_t* rsp = RING_GET_RESPONSE(fr, desc->idx);
 
        // ignoring the ring push response from the kernel side now
-       while (rsp->sc->flags != SC_DONE)
+       while (atomic_read(&rsp->sc->flags) != SC_DONE)
                cpu_relax();
        // memcpy(rsp, rsp_inring, sizeof(*rsp));