UCQs now use mcs_pdr_locks (XCC)
[akaros.git] / kern / include / ros / syscall.h
index 70a0304..5c3d8e9 100644 (file)
@@ -1,21 +1,24 @@
-#ifndef ROS_INCLUDE_SYSCALL_H
-#define ROS_INCLUDE_SYSCALL_H
+#ifndef ROS_INC_SYSCALL_H
+#define ROS_INC_SYSCALL_H
 
 #include <arch/arch.h>
 #include <ros/bits/syscall.h>
 #include <ros/arch/syscall.h>
 #include <ros/event.h>
+#include <ros/atomic.h>
 
-/* Flags for an individual syscall */
+/* Flags for an individual syscall.
+ * Careful, sparc can't handle flags in byte 3. */
 #define SC_DONE                                        0x0001          /* SC is done */
 #define SC_PROGRESS                            0x0002          /* SC made progress */
 #define SC_UEVENT                              0x0004          /* user has an ev_q */
+#define SC_K_LOCK                              0x0008          /* kernel locked sysc */
 
 struct syscall {
        unsigned int                            num;
-       long                                            retval;
        int                                                     err;                    /* errno */
-       int                                                     flags;
+       long                                            retval;
+       atomic_t                                        flags;
        struct event_queue                      *ev_q;
        void                                            *u_data;
        long                                            arg0;
@@ -28,6 +31,8 @@ struct syscall {
 
 #ifndef ROS_KERNEL
 
+#include <arch/atomic.h>
+
 /* Attempts to block on sysc, returning when it is done or progress has been
  * made. */
 void ros_syscall_blockon(struct syscall *sysc);
@@ -36,7 +41,7 @@ void ros_syscall_blockon(struct syscall *sysc);
  * spin, but in the future we could block the whole process. */
 static inline void __ros_syscall_blockon(struct syscall *sysc)
 {
-       while (!(sysc->flags & (SC_DONE | SC_PROGRESS)))
+       while (!(atomic_read(&sysc->flags) & (SC_DONE | SC_PROGRESS)))
                cpu_relax();
 }
 weak_alias(__ros_syscall_blockon, ros_syscall_blockon);
@@ -60,8 +65,12 @@ static inline long __ros_syscall(unsigned int _num, long _a0, long _a1, long _a2
        sysc.arg5 = _a5;
        num_started = __ros_arch_syscall(&sysc, 1);
        /* Don't proceed til we are done */
-       while (!(sysc.flags & SC_DONE))
+       while (!(atomic_read(&sysc.flags) & SC_DONE))
                ros_syscall_blockon(&sysc);
+       /* Need to wait til it is unlocked.  It's not really done until SC_DONE &
+        * !SC_K_LOCK. */
+       while (atomic_read(&sysc.flags) & SC_K_LOCK)
+               cpu_relax();
        if (errno_loc)
                *errno_loc = sysc.err;
        return sysc.retval;
@@ -83,4 +92,4 @@ static inline long __ros_syscall_errno(unsigned int _num, long _a0, long _a1,
 
 #endif /* ifndef ROS_KERNEL */
 
-#endif /* !ROS_INCLUDE_SYSCALL_H */
+#endif /* ROS_INC_SYSCALL_H */