xref: /haiku/src/system/kernel/device_manager/IOSchedulerRoster.h (revision 220d04022750f40f8bac8f01fa551211e28d04f2)
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 {
29 public:
30 	static	void				Init();
31 	static	IOSchedulerRoster*	Default()	{ return &sDefaultInstance; }
32 
33 			bool				Lock()	{ return mutex_lock(&fLock) == B_OK; }
34 			void				Unlock()	{ mutex_unlock(&fLock); }
35 
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 private:
52 								IOSchedulerRoster();
53 								~IOSchedulerRoster();
54 
55 private:
56 			mutex				fLock;
57 			int32				fNextID;
58 			IOSchedulerList		fSchedulers;
59 			DefaultNotificationService fNotificationService;
60 			char				fEventBuffer[256];
61 
62 	static	IOSchedulerRoster	sDefaultInstance;
63 };
64 
65 
66 #endif	// IO_SCHEDULER_ROSTER_H
67