Avoid an extra function call on the error frame handling.
authorDavide Libenzi <dlibenzi@google.com>
Wed, 7 Oct 2015 19:19:41 +0000 (12:19 -0700)
committerBarret Rhoden <brho@cs.berkeley.edu>
Wed, 14 Oct 2015 18:51:21 +0000 (14:51 -0400)
[Removed extra line at EOF in err.h]

Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
kern/include/err.h
kern/src/err.c

index ddfbd22..84cb8a7 100644 (file)
@@ -9,9 +9,8 @@
 
 #define ERRSTACK(x) struct errbuf *prev_errbuf; struct errbuf errstack[(x)];   \
                     int curindex = 0;
-#define waserror() (errpush(errstack, ARRAY_SIZE(errstack), &curindex,         \
-                            &prev_errbuf) ||                                   \
-                    setjmp(&(get_cur_errbuf()->jmpbuf)))
+#define waserror() setjmp(&(errpush(errstack, ARRAY_SIZE(errstack), &curindex, \
+                                                                       &prev_errbuf)->jmpbuf))
 #define error(e, x, ...)                                               \
        do {                                                                            \
                if (x != NULL)                                                                                                  \
                set_errno(e);                                                                                                   \
                longjmp(&get_cur_errbuf()->jmpbuf, 1);                                                  \
        } while(0)
-#define nexterror() \
-       do {                                                                                                                            \
-               errpop(errstack, ARRAY_SIZE(errstack), &curindex,                               \
-                          prev_errbuf);                                                                                        \
-               longjmp(&(get_cur_errbuf())->jmpbuf, 1);                                                \
-       } while (0)
+#define nexterror() longjmp(&(errpop(errstack, ARRAY_SIZE(errstack), &curindex, \
+                                                                        prev_errbuf)->jmpbuf), 1)
 #define poperror() errpop(errstack, ARRAY_SIZE(errstack), &curindex,   \
                                                  prev_errbuf)
 
-int errpush(struct errbuf *errstack, int stacksize, int *curindex,
-            struct errbuf **prev_errbuf);
-void errpop(struct errbuf *errstack, int stacksize, int *curindex,
-            struct errbuf *prev_errbuf);
+struct errbuf *errpush(struct errbuf *errstack, int stacksize, int *curindex,
+                                               struct errbuf **prev_errbuf);
+struct errbuf *errpop(struct errbuf *errstack, int stacksize, int *curindex,
+                                         struct errbuf *prev_errbuf);
 
 #endif /* ROS_KERN_ERR_H */
index 1d9aaca..a7a1848 100644 (file)
  * When we enter, curindex points to the slot we should use.  First time, it is
  * 0, and we'll set cur_eb to slot 0.  When we leave, curindex is set to the
  * next free slot. */
-int errpush(struct errbuf *errstack, int stacksize, int *curindex,
-            struct errbuf **prev_errbuf)
+struct errbuf *errpush(struct errbuf *errstack, int stacksize, int *curindex,
+                                          struct errbuf **prev_errbuf)
 {
+       struct errbuf *cbuf;
+
        printd("pushe %p %d %dp\n", errstack, stacksize, *curindex);
        if (*curindex == 0)
                *prev_errbuf = get_cur_errbuf();
 
        if (*curindex >= stacksize)
                panic("Error stack overflow");
-       set_cur_errbuf(&errstack[*curindex]);
-       *curindex = *curindex + 1;
-       return 0;
+
+       cbuf = &errstack[*curindex];
+       set_cur_errbuf(cbuf);
+       (*curindex)++;
+
+       return cbuf;
 }
 
 /* Undo the work of errpush, and advertise the new errbuf used by error() calls.
@@ -50,9 +55,11 @@ int errpush(struct errbuf *errstack, int stacksize, int *curindex,
  * push into if we were pushing.  When we leave, it will be decreased by one,
  * and will still point to the next free errstack (the one we are popping).
  * */
-void errpop(struct errbuf *errstack, int stacksize, int *curindex,
-            struct errbuf *prev_errbuf)
+struct errbuf *errpop(struct errbuf *errstack, int stacksize, int *curindex,
+                                         struct errbuf *prev_errbuf)
 {
+       struct errbuf *cbuf;
+
        printd("pope %p %d %d\n", errstack, stacksize, *curindex);
        /* curindex now points to the slot we are popping*/
        *curindex = *curindex - 1;
@@ -62,8 +69,8 @@ void errpop(struct errbuf *errstack, int stacksize, int *curindex,
        if (*curindex < 0)
                panic("Error stack underflow");
 
-       if (*curindex == 0)
-               set_cur_errbuf(prev_errbuf);
-       else
-               set_cur_errbuf(&errstack[*curindex - 1]);       /* use the prior slot */
+       cbuf = (*curindex == 0) ? prev_errbuf: &errstack[*curindex - 1];
+       set_cur_errbuf(cbuf);
+
+       return cbuf;
 }