I have this kernel code where I disable the interrupt to make this lock acquire operation atomic, but if u see the last else condition i.e. when lock is not available thread goes to sleep and interrupts are enable only after thread comes back from sleep. My question is so interrupts are disabled for whole OS until this thread comes out of sleep?
void Lock::Acquire() { IntStatus oldLevel = interrupt->SetLevel(IntOff); // Disabling the interrups to make the following statements atomic if(lockOwnerThread == currentThread) //Checking if the requesting thread already owns lock { //printf("SM:error:%s already owns the lock\n",currentThread->getName()); DEBUG('z', "SM:error:%s already owns the lock\n",currentThread->getName()); (void) interrupt->SetLevel(oldLevel); return; } if(lockOwnerThread==NULL) { lockOwnerThread = currentThread; // Lock owner ship is given to current thread DEBUG('z', "SM:The ownership of the lock %s is given to %s \n",name,currentThread->getName()); } else { DEBUG('z', "SM:Adding thread %s to request queue and putting it to sleep\n",currentThread->getName()); queueForLock->Append((void *)currentThread); // Lock is busy so add the thread to queue; currentThread->Sleep(); // And go to sleep } (void) interrupt->SetLevel(oldLevel); // Enable the interrupts }