if (scp->fileType == CM_SCACHETYPE_MOUNTPOINT &&
scp->mpDataVersion == scp->dataVersion)
cep->states |= 8;
- if (scp->flags & CM_SCACHEFLAG_WAITING)
+ if (!osi_QIsEmpty(&scp->waitQueueH))
cep->states |= 0x40;
code = 0;
if (scp->fileType == CM_SCACHETYPE_MOUNTPOINT &&
scp->mpDataVersion == scp->dataVersion)
cep->states |= 8;
- if (scp->flags & CM_SCACHEFLAG_WAITING)
+ if (!osi_QIsEmpty(&scp->waitQueueH))
cep->states |= 0x40;
code = 0;
scp, &base, &fetched);
/* wakeup anyone who is waiting */
- if (scp->flags & CM_SCACHEFLAG_WAITING) {
+ if (!osi_QIsEmpty(&scp->waitQueueH)) {
osi_Log1(afsd_logp, "CM BkgPrefetch Waking scp 0x%p", scp);
osi_Wakeup((LONG_PTR) &scp->flags);
}
*/
_InterlockedOr(&tbufp->cmFlags, CM_BUF_CMFULLYFETCHED);
lock_ObtainWrite(&scp->rw);
- if (scp->flags & CM_SCACHEFLAG_WAITING) {
+ if (!osi_QIsEmpty(&scp->waitQueueH)) {
osi_Log1(afsd_logp, "CM GetBuffer Waking scp 0x%p", scp);
osi_Wakeup((LONG_PTR) &scp->flags);
}
*/
_InterlockedOr(&tbufp->cmFlags, CM_BUF_CMFULLYFETCHED);
lock_ObtainWrite(&scp->rw);
- if (scp->flags & CM_SCACHEFLAG_WAITING) {
+ if (!osi_QIsEmpty(&scp->waitQueueH)) {
osi_Log1(afsd_logp, "CM GetBuffer Waking scp 0x%p", scp);
osi_Wakeup((LONG_PTR) &scp->flags);
}
afs_uint32 sleep_buf_cmflags = 0;
afs_uint32 sleep_scp_bufs = 0;
int wakeupCycle;
+ afs_int32 waitCount;
+ afs_int32 waitRequests;
lock_AssertWrite(&scp->rw);
/* wait here, then try again */
osi_Log1(afsd_logp, "CM SyncOp sleeping scp 0x%p", scp);
- if ( scp->flags & CM_SCACHEFLAG_WAITING ) {
- scp->waitCount++;
- scp->waitRequests++;
+
+ waitCount = InterlockedIncrement(&scp->waitCount);
+ waitRequests = InterlockedIncrement(&scp->waitRequests);
+ if (waitCount > 1) {
osi_Log3(afsd_logp, "CM SyncOp CM_SCACHEFLAG_WAITING already set for 0x%p; %d threads; %d requests",
- scp, scp->waitCount, scp->waitRequests);
+ scp, waitCount, waitRequests);
} else {
osi_Log1(afsd_logp, "CM SyncOp CM_SCACHEFLAG_WAITING set for 0x%p", scp);
_InterlockedOr(&scp->flags, CM_SCACHEFLAG_WAITING);
- scp->waitCount = scp->waitRequests = 1;
}
cm_SyncOpAddToWaitQueue(scp, flags, bufp);
cm_UpdateServerPriority();
- scp->waitCount--;
+ waitCount = InterlockedDecrement(&scp->waitCount);
osi_Log3(afsd_logp, "CM SyncOp woke! scp 0x%p; still waiting %d threads of %d requests",
- scp, scp->waitCount, scp->waitRequests);
- if (scp->waitCount == 0) {
+ scp, waitCount, scp->waitRequests);
+ if (waitCount == 0) {
osi_Log1(afsd_logp, "CM SyncOp CM_SCACHEFLAG_WAITING reset for 0x%p", scp);
_InterlockedAnd(&scp->flags, ~CM_SCACHEFLAG_WAITING);
scp->waitRequests = 0;
}
/* and wakeup anyone who is waiting */
- if (scp->flags & CM_SCACHEFLAG_WAITING) {
+ if ((scp->flags & CM_SCACHEFLAG_WAITING) ||
+ !osi_QIsEmpty(&scp->waitQueueH)) {
osi_Log3(afsd_logp, "CM SyncOpDone 0x%x Waking scp 0x%p bufp 0x%p", flags, scp, bufp);
osi_Wakeup((LONG_PTR) &scp->flags);
}