Print this page
XXXX semaphores behavior is inconsistent in panicstr case

@@ -22,12 +22,10 @@
 /*
  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
-#pragma ident   "%Z%%M% %I%     %E% SMI"
-
 /*
  * This file contains the semaphore operations.
  */
 
 #include <sys/param.h>

@@ -229,15 +227,15 @@
 
         s = (sema_impl_t *)sp;
         sqlp = &SQHASH(s)->sq_lock;
         disp_lock_enter(sqlp);
         ASSERT(s->s_count >= 0);
-        while (s->s_count == 0) {
                 if (panicstr) {
                         disp_lock_exit(sqlp);
                         return;
                 }
+        while (s->s_count == 0) {
                 thread_lock_high(curthread);
                 SEMA_BLOCK(s, sqlp);
                 thread_unlock_nopreempt(curthread);
                 swtch();
                 disp_lock_enter(sqlp);

@@ -374,10 +372,14 @@
         int     gotit = 0;
 
         s = (sema_impl_t *)sp;
         sqh = SQHASH(s);
         disp_lock_enter(&sqh->sq_lock);
+        if (panicstr) {
+                disp_lock_exit(sqlp);
+                return (1);
+        }
         if (s->s_count > 0) {
                 s->s_count--;
                 gotit = 1;
         }
         disp_lock_exit(&sqh->sq_lock);