vfs: check userland buffers before reading them.
[haiku.git] / src / system / kernel / device_manager / IOSchedulerRoster.cpp
blob5724aa17b65c98773ae5b02b4af01b6cdc79b8aa
1 /*
2 * Copyright 2009-2010, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
7 #include "IOSchedulerRoster.h"
9 #include <util/AutoLock.h>
12 /*static*/ IOSchedulerRoster IOSchedulerRoster::sDefaultInstance;
15 /*static*/ void
16 IOSchedulerRoster::Init()
18 new(&sDefaultInstance) IOSchedulerRoster;
22 void
23 IOSchedulerRoster::AddScheduler(IOScheduler* scheduler)
25 AutoLocker<IOSchedulerRoster> locker(this);
26 fSchedulers.Add(scheduler);
27 locker.Unlock();
29 Notify(IO_SCHEDULER_ADDED, scheduler);
33 void
34 IOSchedulerRoster::RemoveScheduler(IOScheduler* scheduler)
36 AutoLocker<IOSchedulerRoster> locker(this);
37 fSchedulers.Remove(scheduler);
38 locker.Unlock();
40 Notify(IO_SCHEDULER_REMOVED, scheduler);
44 void
45 IOSchedulerRoster::Notify(uint32 eventCode, const IOScheduler* scheduler,
46 IORequest* request, IOOperation* operation)
48 AutoLocker<DefaultNotificationService> locker(fNotificationService);
50 if (!fNotificationService.HasListeners())
51 return;
53 KMessage event;
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);
67 int32
68 IOSchedulerRoster::NextID()
70 AutoLocker<IOSchedulerRoster> locker(this);
71 return fNextID++;
75 IOSchedulerRoster::IOSchedulerRoster()
77 fNextID(1),
78 fNotificationService("I/O")
80 mutex_init(&fLock, "IOSchedulerRoster");
81 fNotificationService.Register();
85 IOSchedulerRoster::~IOSchedulerRoster()
87 mutex_destroy(&fLock);
88 fNotificationService.Unregister();