if (lockp->flags & OSI_LOCKFLAG_EXCL) {
osi_assertx(lockp->tid[0] != tid, "OSI_RWLOCK_WRITEHELD");
- } else {
+ }
+#ifdef DEBUG
+ else {
for ( i=0; i < lockp->readers && i < OSI_RWLOCK_THREADS; i++ ) {
osi_assertx(lockp->tid[i] != tid, "OSI_RWLOCK_READHELD");
}
}
+#endif
/* here we have the fast lock, so see if we can obtain the real lock */
if (lockp->waiters > 0 || (lockp->flags & OSI_LOCKFLAG_EXCL) ||
if (lockp->flags & OSI_LOCKFLAG_EXCL) {
osi_assertx(lockp->tid[0] != tid, "OSI_RWLOCK_WRITEHELD");
- } else {
+ }
+#ifdef DEBUG
+ else {
for ( i=0; i < lockp->readers && i < OSI_RWLOCK_THREADS; i++ ) {
osi_assertx(lockp->tid[i] != tid, "OSI_RWLOCK_READHELD");
}
}
+#endif
/* here we have the fast lock, so see if we can obtain the real lock */
if (lockp->waiters > 0 || (lockp->flags & OSI_LOCKFLAG_EXCL)) {
osi_assert(!(lockp->flags & OSI_LOCKFLAG_EXCL) && lockp->readers > 0);
} else {
/* if we're here, all clear to set the lock */
- if (++lockp->readers <= OSI_RWLOCK_THREADS)
+ lockp->readers++;
+#ifdef DEBUG
+ if (lockp->readers <= OSI_RWLOCK_THREADS)
lockp->tid[lockp->readers-1] = tid;
+#endif
}
LeaveCriticalSection(csp);
osi_assertx(lockp->readers > 0, "read lock not held");
- for ( i=0; i < lockp->readers; i++) {
+#ifdef DEBUG
+ for ( i=0; i < lockp->readers && i < OSI_RWLOCK_THREADS; i++) {
if ( lockp->tid[i] == tid ) {
- for ( ; i < lockp->readers - 1; i++)
+ for ( ; i < (lockp->readers - 1) && i < (OSI_RWLOCK_THREADS - 1); i++)
lockp->tid[i] = lockp->tid[i+1];
lockp->tid[i] = 0;
break;
}
}
+#endif
lockp->readers--;
osi_assertx(lockp->flags & OSI_LOCKFLAG_EXCL, "write lock not held");
osi_assertx(lockp->tid[0] == thrd_Current(), "write lock not held by current thread");
-
lockp->tid[0] = 0;
lockp->flags &= ~OSI_LOCKFLAG_EXCL;
/* convert write lock to read lock */
lockp->flags &= ~OSI_LOCKFLAG_EXCL;
+ lockp->tid[0] = 0;
lockp->readers++;
osi_assertx(lockp->readers == 1, "read lock not one");
osi_assertx(!(lockp->flags & OSI_LOCKFLAG_EXCL), "write lock held");
osi_assertx(lockp->readers > 0, "read lock not held");
- for ( i=0; i < lockp->readers; i++) {
+#ifdef DEBUG
+ for ( i=0; i < lockp->readers && i < OSI_RWLOCK_THREADS; i++) {
if ( lockp->tid[i] == tid ) {
- for ( ; i < lockp->readers - 1; i++)
+ for ( ; i < (lockp->readers - 1) && i < (OSI_RWLOCK_THREADS - 1); i++)
lockp->tid[i] = lockp->tid[i+1];
lockp->tid[i] = 0;
break;
}
}
+#endif
if (--(lockp->readers) == 0) {
/* convert read lock to write lock */
}
else {
/* if we're here, all clear to set the lock */
- if (++(lockp->readers) < OSI_RWLOCK_THREADS)
+ lockp->readers++;
+#ifdef DEBUG
+ if (lockp->readers < OSI_RWLOCK_THREADS)
lockp->tid[lockp->readers-1] = thrd_Current();
+#endif
i = 1;
}
osi_assertx(lockp->readers > 0, "osi_SleepR: not held");
- for ( i=0; i < lockp->readers; i++) {
+#ifdef DEBUG
+ for ( i=0; i < lockp->readers && i < OSI_RWLOCK_THREADS; i++) {
if ( lockp->tid[i] == tid ) {
- for ( ; i < lockp->readers - 1; i++)
+ for ( ; i < (lockp->readers - 1) && i < (OSI_RWLOCK_THREADS - 1); i++)
lockp->tid[i] = lockp->tid[i+1];
lockp->tid[i] = 0;
break;
}
}
+#endif
/* XXX better to get the list of things to wakeup from TSignalForMLs, and
* then do the wakeup after SleepSpin releases the low-level mutex.