2 * Copyright 2009-2010, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
7 #include "IOSchedulerRoster.h"
9 #include <util/AutoLock.h>
12 /*static*/ IOSchedulerRoster
IOSchedulerRoster::sDefaultInstance
;
16 IOSchedulerRoster::Init()
18 new(&sDefaultInstance
) IOSchedulerRoster
;
23 IOSchedulerRoster::AddScheduler(IOScheduler
* scheduler
)
25 AutoLocker
<IOSchedulerRoster
> locker(this);
26 fSchedulers
.Add(scheduler
);
29 Notify(IO_SCHEDULER_ADDED
, scheduler
);
34 IOSchedulerRoster::RemoveScheduler(IOScheduler
* scheduler
)
36 AutoLocker
<IOSchedulerRoster
> locker(this);
37 fSchedulers
.Remove(scheduler
);
40 Notify(IO_SCHEDULER_REMOVED
, scheduler
);
45 IOSchedulerRoster::Notify(uint32 eventCode
, const IOScheduler
* scheduler
,
46 IORequest
* request
, IOOperation
* operation
)
48 AutoLocker
<DefaultNotificationService
> locker(fNotificationService
);
50 if (!fNotificationService
.HasListeners())
54 event
.SetTo(fEventBuffer
, sizeof(fEventBuffer
), IO_SCHEDULER_MONITOR
);
55 event
.AddInt32("event", eventCode
);
56 event
.AddPointer("scheduler", scheduler
);
57 if (request
!= NULL
) {
58 event
.AddPointer("request", request
);
59 if (operation
!= NULL
)
60 event
.AddPointer("operation", operation
);
63 fNotificationService
.NotifyLocked(event
, eventCode
);
68 IOSchedulerRoster::NextID()
70 AutoLocker
<IOSchedulerRoster
> locker(this);
75 IOSchedulerRoster::IOSchedulerRoster()
78 fNotificationService("I/O")
80 mutex_init(&fLock
, "IOSchedulerRoster");
81 fNotificationService
.Register();
85 IOSchedulerRoster::~IOSchedulerRoster()
87 mutex_destroy(&fLock
);
88 fNotificationService
.Unregister();