xref: /haiku/src/system/kernel/device_manager/IOSchedulerRoster.h (revision 8f88247e04c71e1fe8079fe4a029c0556e88e314)
17aba4e40SIngo Weinhold /*
27aba4e40SIngo Weinhold  * Copyright 2009-2010, Ingo Weinhold, ingo_weinhold@gmx.de.
37aba4e40SIngo Weinhold  * Distributed under the terms of the MIT License.
47aba4e40SIngo Weinhold  */
57aba4e40SIngo Weinhold #ifndef IO_SCHEDULER_ROSTER_H
67aba4e40SIngo Weinhold #define IO_SCHEDULER_ROSTER_H
77aba4e40SIngo Weinhold 
87aba4e40SIngo Weinhold 
97aba4e40SIngo Weinhold #include <Notifications.h>
107aba4e40SIngo Weinhold 
117aba4e40SIngo Weinhold #include "IOScheduler.h"
127aba4e40SIngo Weinhold 
137aba4e40SIngo Weinhold 
147aba4e40SIngo Weinhold // I/O scheduler notifications
157aba4e40SIngo Weinhold #define IO_SCHEDULER_MONITOR			'_io_'
167aba4e40SIngo Weinhold #define IO_SCHEDULER_ADDED				0x01
177aba4e40SIngo Weinhold #define IO_SCHEDULER_REMOVED			0x02
187aba4e40SIngo Weinhold #define IO_SCHEDULER_REQUEST_SCHEDULED	0x04
197aba4e40SIngo Weinhold #define IO_SCHEDULER_REQUEST_FINISHED	0x08
207aba4e40SIngo Weinhold #define IO_SCHEDULER_OPERATION_STARTED	0x10
217aba4e40SIngo Weinhold #define IO_SCHEDULER_OPERATION_FINISHED	0x20
227aba4e40SIngo Weinhold 
237aba4e40SIngo Weinhold 
247aba4e40SIngo Weinhold 
257aba4e40SIngo Weinhold typedef DoublyLinkedList<IOScheduler> IOSchedulerList;
267aba4e40SIngo Weinhold 
277aba4e40SIngo Weinhold 
28*8f88247eSAugustin Cavalier class IOSchedulerRoster final {
297aba4e40SIngo Weinhold public:
307aba4e40SIngo Weinhold 	static	void				Init();
Default()317aba4e40SIngo Weinhold 	static	IOSchedulerRoster*	Default()	{ return &sDefaultInstance; }
327aba4e40SIngo Weinhold 
Lock()337aba4e40SIngo Weinhold 			bool				Lock()	{ return mutex_lock(&fLock) == B_OK; }
Unlock()347aba4e40SIngo Weinhold 			void				Unlock()	{ mutex_unlock(&fLock); }
357aba4e40SIngo Weinhold 
SchedulerList()367aba4e40SIngo Weinhold 			const IOSchedulerList& SchedulerList() const
377aba4e40SIngo Weinhold 									{ return fSchedulers; }
387aba4e40SIngo Weinhold 									// caller must keep the roster locked,
397aba4e40SIngo Weinhold 									// while accessing the list
407aba4e40SIngo Weinhold 
417aba4e40SIngo Weinhold 			void				AddScheduler(IOScheduler* scheduler);
427aba4e40SIngo Weinhold 			void				RemoveScheduler(IOScheduler* scheduler);
437aba4e40SIngo Weinhold 
447aba4e40SIngo Weinhold 			void				Notify(uint32 eventCode,
457aba4e40SIngo Weinhold 									const IOScheduler* scheduler,
467aba4e40SIngo Weinhold 									IORequest* request = NULL,
477aba4e40SIngo Weinhold 									IOOperation* operation = NULL);
487aba4e40SIngo Weinhold 
497aba4e40SIngo Weinhold 			int32				NextID();
507aba4e40SIngo Weinhold 
51*8f88247eSAugustin Cavalier 			void				Dump() const;
52*8f88247eSAugustin Cavalier 
537aba4e40SIngo Weinhold private:
547aba4e40SIngo Weinhold 								IOSchedulerRoster();
557aba4e40SIngo Weinhold 								~IOSchedulerRoster();
567aba4e40SIngo Weinhold 
577aba4e40SIngo Weinhold private:
587aba4e40SIngo Weinhold 			mutex				fLock;
597aba4e40SIngo Weinhold 			int32				fNextID;
607aba4e40SIngo Weinhold 			IOSchedulerList		fSchedulers;
617aba4e40SIngo Weinhold 			DefaultNotificationService fNotificationService;
627aba4e40SIngo Weinhold 			char				fEventBuffer[256];
637aba4e40SIngo Weinhold 
647aba4e40SIngo Weinhold 	static	IOSchedulerRoster	sDefaultInstance;
657aba4e40SIngo Weinhold };
667aba4e40SIngo Weinhold 
677aba4e40SIngo Weinhold 
687aba4e40SIngo Weinhold #endif	// IO_SCHEDULER_ROSTER_H
69