Moved IOSchedulerRoster into its own header/source files.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36491 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -27,7 +27,7 @@
|
||||
|
||||
#include <arch/debug.h>
|
||||
|
||||
#include "IOScheduler.h"
|
||||
#include "IOSchedulerRoster.h"
|
||||
|
||||
|
||||
// This is the kernel-side implementation of the system profiling support.
|
||||
|
||||
@@ -14,14 +14,14 @@
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <KernelExport.h>
|
||||
|
||||
#include <khash.h>
|
||||
#include <lock.h>
|
||||
#include <thread_types.h>
|
||||
#include <thread.h>
|
||||
#include <util/AutoLock.h>
|
||||
|
||||
#include "IOSchedulerRoster.h"
|
||||
|
||||
|
||||
//#define TRACE_IO_SCHEDULER
|
||||
#ifdef TRACE_IO_SCHEDULER
|
||||
@@ -853,84 +853,3 @@ IOScheduler::_GetRequestOwner(team_id team, thread_id thread, bool allocate)
|
||||
fUnusedRequestOwners.MoveFrom(&existingOwners);
|
||||
return owner;
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark - IOSchedulerNotificationService
|
||||
|
||||
|
||||
/*static*/ IOSchedulerRoster IOSchedulerRoster::sDefaultInstance;
|
||||
|
||||
|
||||
/*static*/ void
|
||||
IOSchedulerRoster::Init()
|
||||
{
|
||||
new(&sDefaultInstance) IOSchedulerRoster;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
IOSchedulerRoster::AddScheduler(IOScheduler* scheduler)
|
||||
{
|
||||
AutoLocker<IOSchedulerRoster> locker(this);
|
||||
fSchedulers.Add(scheduler);
|
||||
locker.Unlock();
|
||||
|
||||
Notify(IO_SCHEDULER_ADDED, scheduler);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
IOSchedulerRoster::RemoveScheduler(IOScheduler* scheduler)
|
||||
{
|
||||
AutoLocker<IOSchedulerRoster> locker(this);
|
||||
fSchedulers.Remove(scheduler);
|
||||
locker.Unlock();
|
||||
|
||||
Notify(IO_SCHEDULER_REMOVED, scheduler);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
IOSchedulerRoster::Notify(uint32 eventCode, const IOScheduler* scheduler,
|
||||
IORequest* request, IOOperation* operation)
|
||||
{
|
||||
AutoLocker<DefaultNotificationService> locker(fNotificationService);
|
||||
|
||||
if (!fNotificationService.HasListeners())
|
||||
return;
|
||||
|
||||
KMessage event;
|
||||
event.SetTo(fEventBuffer, sizeof(fEventBuffer), IO_SCHEDULER_MONITOR);
|
||||
event.AddInt32("event", eventCode);
|
||||
event.AddPointer("scheduler", scheduler);
|
||||
if (request != NULL) {
|
||||
event.AddPointer("request", request);
|
||||
if (operation != NULL)
|
||||
event.AddPointer("operation", operation);
|
||||
}
|
||||
|
||||
fNotificationService.NotifyLocked(event, eventCode);
|
||||
}
|
||||
|
||||
|
||||
int32
|
||||
IOSchedulerRoster::NextID()
|
||||
{
|
||||
AutoLocker<IOSchedulerRoster> locker(this);
|
||||
return fNextID++;
|
||||
}
|
||||
|
||||
|
||||
IOSchedulerRoster::IOSchedulerRoster()
|
||||
:
|
||||
fNextID(1),
|
||||
fNotificationService("I/O")
|
||||
{
|
||||
mutex_init(&fLock, "IOSchedulerRoster");
|
||||
}
|
||||
|
||||
|
||||
IOSchedulerRoster::~IOSchedulerRoster()
|
||||
{
|
||||
mutex_destroy(&fLock);
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
|
||||
#include <condition_variable.h>
|
||||
#include <lock.h>
|
||||
#include <Notifications.h>
|
||||
#include <util/DoublyLinkedList.h>
|
||||
#include <util/OpenHashTable.h>
|
||||
|
||||
@@ -20,16 +19,6 @@
|
||||
#include "IORequest.h"
|
||||
|
||||
|
||||
// I/O scheduler notifications
|
||||
#define IO_SCHEDULER_MONITOR '_io_'
|
||||
#define IO_SCHEDULER_ADDED 0x01
|
||||
#define IO_SCHEDULER_REMOVED 0x02
|
||||
#define IO_SCHEDULER_REQUEST_SCHEDULED 0x04
|
||||
#define IO_SCHEDULER_REQUEST_FINISHED 0x08
|
||||
#define IO_SCHEDULER_OPERATION_STARTED 0x10
|
||||
#define IO_SCHEDULER_OPERATION_FINISHED 0x20
|
||||
|
||||
|
||||
struct IORequestOwner : DoublyLinkedListLinkImpl<IORequestOwner> {
|
||||
team_id team;
|
||||
thread_id thread;
|
||||
@@ -136,45 +125,5 @@ private:
|
||||
volatile bool fTerminating;
|
||||
};
|
||||
|
||||
typedef DoublyLinkedList<IOScheduler> IOSchedulerList;
|
||||
|
||||
|
||||
class IOSchedulerRoster {
|
||||
public:
|
||||
static void Init();
|
||||
static IOSchedulerRoster* Default() { return &sDefaultInstance; }
|
||||
|
||||
bool Lock() { return mutex_lock(&fLock) == B_OK; }
|
||||
void Unlock() { mutex_unlock(&fLock); }
|
||||
|
||||
const IOSchedulerList& SchedulerList() const
|
||||
{ return fSchedulers; }
|
||||
// caller must keep the roster locked,
|
||||
// while accessing the list
|
||||
|
||||
void AddScheduler(IOScheduler* scheduler);
|
||||
void RemoveScheduler(IOScheduler* scheduler);
|
||||
|
||||
void Notify(uint32 eventCode,
|
||||
const IOScheduler* scheduler,
|
||||
IORequest* request = NULL,
|
||||
IOOperation* operation = NULL);
|
||||
|
||||
int32 NextID();
|
||||
|
||||
private:
|
||||
IOSchedulerRoster();
|
||||
~IOSchedulerRoster();
|
||||
|
||||
private:
|
||||
mutex fLock;
|
||||
int32 fNextID;
|
||||
IOSchedulerList fSchedulers;
|
||||
DefaultNotificationService fNotificationService;
|
||||
char fEventBuffer[256];
|
||||
|
||||
static IOSchedulerRoster sDefaultInstance;
|
||||
};
|
||||
|
||||
|
||||
#endif // IO_SCHEDULER_H
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright 2009-2010, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
#include "IOSchedulerRoster.h"
|
||||
|
||||
#include <util/AutoLock.h>
|
||||
|
||||
|
||||
/*static*/ IOSchedulerRoster IOSchedulerRoster::sDefaultInstance;
|
||||
|
||||
|
||||
/*static*/ void
|
||||
IOSchedulerRoster::Init()
|
||||
{
|
||||
new(&sDefaultInstance) IOSchedulerRoster;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
IOSchedulerRoster::AddScheduler(IOScheduler* scheduler)
|
||||
{
|
||||
AutoLocker<IOSchedulerRoster> locker(this);
|
||||
fSchedulers.Add(scheduler);
|
||||
locker.Unlock();
|
||||
|
||||
Notify(IO_SCHEDULER_ADDED, scheduler);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
IOSchedulerRoster::RemoveScheduler(IOScheduler* scheduler)
|
||||
{
|
||||
AutoLocker<IOSchedulerRoster> locker(this);
|
||||
fSchedulers.Remove(scheduler);
|
||||
locker.Unlock();
|
||||
|
||||
Notify(IO_SCHEDULER_REMOVED, scheduler);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
IOSchedulerRoster::Notify(uint32 eventCode, const IOScheduler* scheduler,
|
||||
IORequest* request, IOOperation* operation)
|
||||
{
|
||||
AutoLocker<DefaultNotificationService> locker(fNotificationService);
|
||||
|
||||
if (!fNotificationService.HasListeners())
|
||||
return;
|
||||
|
||||
KMessage event;
|
||||
event.SetTo(fEventBuffer, sizeof(fEventBuffer), IO_SCHEDULER_MONITOR);
|
||||
event.AddInt32("event", eventCode);
|
||||
event.AddPointer("scheduler", scheduler);
|
||||
if (request != NULL) {
|
||||
event.AddPointer("request", request);
|
||||
if (operation != NULL)
|
||||
event.AddPointer("operation", operation);
|
||||
}
|
||||
|
||||
fNotificationService.NotifyLocked(event, eventCode);
|
||||
}
|
||||
|
||||
|
||||
int32
|
||||
IOSchedulerRoster::NextID()
|
||||
{
|
||||
AutoLocker<IOSchedulerRoster> locker(this);
|
||||
return fNextID++;
|
||||
}
|
||||
|
||||
|
||||
IOSchedulerRoster::IOSchedulerRoster()
|
||||
:
|
||||
fNextID(1),
|
||||
fNotificationService("I/O")
|
||||
{
|
||||
mutex_init(&fLock, "IOSchedulerRoster");
|
||||
}
|
||||
|
||||
|
||||
IOSchedulerRoster::~IOSchedulerRoster()
|
||||
{
|
||||
mutex_destroy(&fLock);
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright 2009-2010, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef IO_SCHEDULER_ROSTER_H
|
||||
#define IO_SCHEDULER_ROSTER_H
|
||||
|
||||
|
||||
#include <Notifications.h>
|
||||
|
||||
#include "IOScheduler.h"
|
||||
|
||||
|
||||
// I/O scheduler notifications
|
||||
#define IO_SCHEDULER_MONITOR '_io_'
|
||||
#define IO_SCHEDULER_ADDED 0x01
|
||||
#define IO_SCHEDULER_REMOVED 0x02
|
||||
#define IO_SCHEDULER_REQUEST_SCHEDULED 0x04
|
||||
#define IO_SCHEDULER_REQUEST_FINISHED 0x08
|
||||
#define IO_SCHEDULER_OPERATION_STARTED 0x10
|
||||
#define IO_SCHEDULER_OPERATION_FINISHED 0x20
|
||||
|
||||
|
||||
|
||||
typedef DoublyLinkedList<IOScheduler> IOSchedulerList;
|
||||
|
||||
|
||||
class IOSchedulerRoster {
|
||||
public:
|
||||
static void Init();
|
||||
static IOSchedulerRoster* Default() { return &sDefaultInstance; }
|
||||
|
||||
bool Lock() { return mutex_lock(&fLock) == B_OK; }
|
||||
void Unlock() { mutex_unlock(&fLock); }
|
||||
|
||||
const IOSchedulerList& SchedulerList() const
|
||||
{ return fSchedulers; }
|
||||
// caller must keep the roster locked,
|
||||
// while accessing the list
|
||||
|
||||
void AddScheduler(IOScheduler* scheduler);
|
||||
void RemoveScheduler(IOScheduler* scheduler);
|
||||
|
||||
void Notify(uint32 eventCode,
|
||||
const IOScheduler* scheduler,
|
||||
IORequest* request = NULL,
|
||||
IOOperation* operation = NULL);
|
||||
|
||||
int32 NextID();
|
||||
|
||||
private:
|
||||
IOSchedulerRoster();
|
||||
~IOSchedulerRoster();
|
||||
|
||||
private:
|
||||
mutex fLock;
|
||||
int32 fNextID;
|
||||
IOSchedulerList fSchedulers;
|
||||
DefaultNotificationService fNotificationService;
|
||||
char fEventBuffer[256];
|
||||
|
||||
static IOSchedulerRoster sDefaultInstance;
|
||||
};
|
||||
|
||||
|
||||
#endif // IO_SCHEDULER_ROSTER_H
|
||||
@@ -19,6 +19,7 @@ KernelMergeObject kernel_device_manager.o :
|
||||
IOCallback.cpp
|
||||
IORequest.cpp
|
||||
IOScheduler.cpp
|
||||
IOSchedulerRoster.cpp
|
||||
:
|
||||
$(TARGET_KERNEL_PIC_CCFLAGS)
|
||||
;
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
#include "id_generator.h"
|
||||
#include "IORequest.h"
|
||||
#include "io_resources.h"
|
||||
#include "IOScheduler.h"
|
||||
#include "IOSchedulerRoster.h"
|
||||
|
||||
|
||||
//#define TRACE_DEVICE_MANAGER
|
||||
|
||||
Reference in New Issue
Block a user