xref: /haiku/src/system/kernel/device_manager/IOSchedulerRoster.h (revision 8f88247e04c71e1fe8079fe4a029c0556e88e314)
1 /*
2  * Copyright 2009-2010, Ingo Weinhold, ingo_weinhold@gmx.de.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef IO_SCHEDULER_ROSTER_H
6 #define IO_SCHEDULER_ROSTER_H
7 
8 
9 #include <Notifications.h>
10 
11 #include "IOScheduler.h"
12 
13 
14 // I/O scheduler notifications
15 #define IO_SCHEDULER_MONITOR			'_io_'
16 #define IO_SCHEDULER_ADDED				0x01
17 #define IO_SCHEDULER_REMOVED			0x02
18 #define IO_SCHEDULER_REQUEST_SCHEDULED	0x04
19 #define IO_SCHEDULER_REQUEST_FINISHED	0x08
20 #define IO_SCHEDULER_OPERATION_STARTED	0x10
21 #define IO_SCHEDULER_OPERATION_FINISHED	0x20
22 
23 
24 
25 typedef DoublyLinkedList<IOScheduler> IOSchedulerList;
26 
27 
28 class IOSchedulerRoster final {
29 public:
30 	static	void				Init();
Default()31 	static	IOSchedulerRoster*	Default()	{ return &sDefaultInstance; }
32 
Lock()33 			bool				Lock()	{ return mutex_lock(&fLock) == B_OK; }
Unlock()34 			void				Unlock()	{ mutex_unlock(&fLock); }
35 
SchedulerList()36 			const IOSchedulerList& SchedulerList() const
37 									{ return fSchedulers; }
38 									// caller must keep the roster locked,
39 									// while accessing the list
40 
41 			void				AddScheduler(IOScheduler* scheduler);
42 			void				RemoveScheduler(IOScheduler* scheduler);
43 
44 			void				Notify(uint32 eventCode,
45 									const IOScheduler* scheduler,
46 									IORequest* request = NULL,
47 									IOOperation* operation = NULL);
48 
49 			int32				NextID();
50 
51 			void				Dump() const;
52 
53 private:
54 								IOSchedulerRoster();
55 								~IOSchedulerRoster();
56 
57 private:
58 			mutex				fLock;
59 			int32				fNextID;
60 			IOSchedulerList		fSchedulers;
61 			DefaultNotificationService fNotificationService;
62 			char				fEventBuffer[256];
63 
64 	static	IOSchedulerRoster	sDefaultInstance;
65 };
66 
67 
68 #endif	// IO_SCHEDULER_ROSTER_H
69