-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSleepQueue.py
More file actions
22 lines (16 loc) · 746 Bytes
/
SleepQueue.py
File metadata and controls
22 lines (16 loc) · 746 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#This class defines the SleepQueue,which maintains the record of sleeping processes.
#We have implemented this as dictionary where buffer is the key and pid is the value.
import time
import os
class SleepQueue(object):
def __init__(self):
self.sleepQueue={}
def add(self,buffer,pid):
self.sleepQueue.setdefault(buffer,[])
self.sleepQueue[buffer].append(pid)
#-2 is returned if buffer not present otherwise list of waiting processes are returned
def getPidsWaitingForBuffer(self,buffer):
return self.sleepQueue.pop(buffer,-2)
#Processes waiting for any buffer has stored theor pids at index "-1"
def getPidsWaitingForAnyBuffer(self):
return self.sleepQueue.pop(-1,-2)