* Adjusted thread priorities of several system services based on a mail from

Mikhail Panasyuk: since worker threads often end up with B_NORMAL_PRIORITY,
  it might be a good idea to give system threads a higher priority.
* Minor cleanup (mostly automatic whitespace).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33961 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2009-11-09 15:25:48 +00:00
parent 66570f5d3b
commit a0439d88df
8 changed files with 208 additions and 203 deletions
+4 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2008, Haiku, Inc. All Rights Reserved.
* Copyright 2002-2009, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*/
@@ -164,6 +164,9 @@ InputServer::InputServer()
CALLED();
gInputServer = this;
set_thread_priority(find_thread(NULL), B_URGENT_DISPLAY_PRIORITY);
// elevate priority for client interaction
_StartEventLoop();
char parameter[32];
@@ -654,7 +654,7 @@ AuthenticationManager::Init()
return fRequestPort;
fRequestThread = spawn_thread(&_RequestThreadEntry,
"authentication manager", B_NORMAL_PRIORITY, this);
"authentication manager", B_NORMAL_PRIORITY + 1, this);
if (fRequestThread < 0)
return fRequestThread;
+36 -54
View File
@@ -1,42 +1,25 @@
//------------------------------------------------------------------------------
// Copyright (c) 2001-2002, OpenBeOS
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// File Name: EventQueue.cpp
// Author: Ingo Weinhold ([email protected])
// YellowBites (http://www.yellowbites.com)
// Description: A class providing a mechanism for executing events at
// specified times.
//------------------------------------------------------------------------------
/*
* Copyright 2001-2009, Haiku Inc.
* Distributed under the terms of the MIT License.
*
* Authors:
* Ingo Weinhold (bonefish@users.sf.net)
*/
#include "EventQueue.h"
#include <stdio.h>
#include <String.h>
#include "Event.h"
#include "EventQueue.h"
static const char *kDefaultEventQueueName = "event looper";
/*!
\class EventQueue
/*! \class EventQueue
\brief A class providing a mechanism for executing events at specified
times.
@@ -88,7 +71,6 @@ static const char *kDefaultEventQueueName = "event looper";
*/
// constructor
/*! \brief Creates a new event queue.
The status of the initialization can and should be check with InitCheck().
@@ -97,12 +79,13 @@ static const char *kDefaultEventQueueName = "event looper";
a default name is used.
*/
EventQueue::EventQueue(const char *name)
: fEvents(100),
fEventLooper(-1),
fLooperControl(-1),
fNextEventTime(0),
fStatus(B_ERROR),
fTerminating(false)
:
fEvents(100),
fEventLooper(-1),
fLooperControl(-1),
fNextEventTime(0),
fStatus(B_ERROR),
fTerminating(false)
{
if (!name)
name = kDefaultEventQueueName;
@@ -112,8 +95,8 @@ EventQueue::EventQueue(const char *name)
else
fStatus = fLooperControl;
if (fStatus == B_OK) {
fEventLooper = spawn_thread(_EventLooperEntry, name, B_NORMAL_PRIORITY,
this);
fEventLooper = spawn_thread(_EventLooperEntry, name,
B_DISPLAY_PRIORITY + 1, this);
if (fEventLooper >= B_OK) {
fStatus = B_OK;
resume_thread(fEventLooper);
@@ -122,7 +105,7 @@ EventQueue::EventQueue(const char *name)
}
}
// destructor
/*! \brief Frees all resources associated by this object.
Die() is called to terminate the queue's thread and all events whose
@@ -137,7 +120,7 @@ EventQueue::~EventQueue()
}
}
// InitCheck
/*! \brief Returns the initialization status of the event queue.
\return \c B_OK, if everything went fine, an error code otherwise.
*/
@@ -147,7 +130,7 @@ EventQueue::InitCheck()
return fStatus;
}
// Die
/*! \brief Terminates the queue's thread.
If an event is currently executed, it is allowed to finish its task
@@ -165,7 +148,7 @@ EventQueue::Die()
}
}
// AddEvent
/*! \brief Adds a new event to the queue.
The event's time must be set, before adding it. Afterwards ModifyEvent()
@@ -188,7 +171,7 @@ EventQueue::AddEvent(Event *event)
return result;
}
// RemoveEvent
/*! \brief Removes an event from the queue.
\param event The event to be removed.
\return \c true, if the event has been removed successfully, \c false, if
@@ -205,7 +188,7 @@ EventQueue::RemoveEvent(Event *event)
return result;
}
// ModifyEvent
/*! \brief Modifies an event's time.
The event must be in the queue.
@@ -228,7 +211,7 @@ EventQueue::ModifyEvent(Event *event, bigtime_t newTime)
Unlock();
}
// _AddEvent
/*! \brief Adds an event to the event list.
\note The object must be locked when this method is invoked.
@@ -244,7 +227,7 @@ EventQueue::_AddEvent(Event *event)
return fEvents.AddItem(event, index);
}
// _RemoveEvent
/*! \brief Removes an event from the event list.
\note The object must be locked when this method is invoked.
@@ -260,7 +243,7 @@ EventQueue::_RemoveEvent(Event *event)
return (index >= 0 && fEvents.RemoveItem(index));
}
// _EventAt
/*! \brief Returns an event from the event list.
\note The object must be locked when this method is invoked.
@@ -274,7 +257,7 @@ EventQueue::_EventAt(int32 index) const
return (Event*)fEvents.ItemAt(index);
}
// _IndexOfEvent
/*! \brief Returns the event list index of the supplied event.
\note The object must be locked when this method is invoked.
@@ -299,7 +282,7 @@ EventQueue::_IndexOfEvent(Event *event) const
return -1;
}
// _FindInsertionIndex
/*! \brief Finds the event list index at which an event with the supplied
has to be added.
@@ -330,7 +313,7 @@ EventQueue::_FindInsertionIndex(bigtime_t time) const
return lower;
}
// _EventLooperEntry
/*! \brief Entry point from the queue's thread.
\param data The queue's \c this pointer.
\return The thread's result. Of no relevance in this case.
@@ -341,7 +324,7 @@ EventQueue::_EventLooperEntry(void *data)
return ((EventQueue*)data)->_EventLooper();
}
// _EventLooper
/*! \brief Method with the main loop of the queue's thread.
\return The thread's result. Of no relevance in this case.
*/
@@ -385,7 +368,7 @@ EventQueue::_EventLooper()
return 0;
}
// _Reschedule
/*! \brief To be called, when an event has been added or removed.
Checks whether the queue's thread has to recalculate the time when it
@@ -402,4 +385,3 @@ EventQueue::_Reschedule()
release_sem(fLooperControl);
}
}
+63 -46
View File
@@ -1,4 +1,12 @@
// MIMEManager.cpp
/*
* Copyright 2002-2009, Haiku Inc.
* Distributed under the terms of the MIT License.
*
* Authors:
* Ingo Weinhold (bonefish@users.sf.net)
* Tyler Dauwalder
*/
#include "MIMEManager.h"
@@ -19,23 +27,25 @@
#include "TextSnifferAddon.h"
#include "UpdateMimeInfoThread.h"
using namespace std;
using namespace BPrivate;
/*!
\class MIMEManager
/*! \class MIMEManager
\brief MIMEManager handles communication between BMimeType and the system-wide
MimeDatabase object for BMimeType's write and non-atomic read functions.
*/
// constructor
/*! \brief Creates and initializes a MIMEManager.
*/
MIMEManager::MIMEManager()
: BLooper("main_mime")
, fDatabase()
, fThreadManager()
:
BLooper("main_mime"),
fDatabase(),
fThreadManager()
{
AddHandler(&fThreadManager);
@@ -48,14 +58,14 @@ MIMEManager::MIMEManager()
}
}
// destructor
/*! \brief Frees all resources associate with this object.
*/
MIMEManager::~MIMEManager()
{
}
// MessageReceived
/*! \brief Overrides the super class version to handle the MIME specific
messages.
\param message The message to be handled
@@ -82,8 +92,8 @@ MIMEManager::MessageReceived(BMessage *message)
err = message->FindMessenger("target", &messenger);
if (!err) {
err = message->what == B_REG_MIME_START_WATCHING
? fDatabase.StartWatching(messenger)
: fDatabase.StopWatching(messenger);
? fDatabase.StartWatching(messenger)
: fDatabase.StopWatching(messenger);
}
reply.what = B_REG_RESULT;
@@ -99,8 +109,7 @@ MIMEManager::MessageReceived(BMessage *message)
err = message->FindString("type", &type);
if (!err)
err = message->what == B_REG_MIME_INSTALL
? fDatabase.Install(type)
: fDatabase.Delete(type);
? fDatabase.Install(type) : fDatabase.Delete(type);
reply.what = B_REG_RESULT;
reply.AddInt32("result", err);
@@ -229,7 +238,7 @@ MIMEManager::MessageReceived(BMessage *message)
thread = new(nothrow) CreateAppMetaMimeThread(
synchronous ? "create_app_meta_mime (s)"
: "create_app_meta_mime (a)",
B_NORMAL_PRIORITY, &fDatabase,
B_NORMAL_PRIORITY + 1, &fDatabase,
BMessenger(&fThreadManager), &root, recursive,
force, synchronous ? message : NULL);
break;
@@ -238,7 +247,7 @@ MIMEManager::MessageReceived(BMessage *message)
thread = new(nothrow) UpdateMimeInfoThread(synchronous
? "update_mime_info (s)"
: "update_mime_info (a)",
B_NORMAL_PRIORITY, &fDatabase,
B_NORMAL_PRIORITY + 1, &fDatabase,
BMessenger(&fThreadManager), &root, recursive,
force, synchronous ? message : NULL);
break;
@@ -289,7 +298,7 @@ MIMEManager::MessageReceived(BMessage *message)
}
}
// HandleSetParam
//! Handles all B_REG_MIME_SET_PARAM messages
void
MIMEManager::HandleSetParam(BMessage *message)
@@ -328,10 +337,11 @@ MIMEManager::HandleSetParam(BMessage *message)
err = message->FindBool("long", &isLong);
if (!err)
err = message->FindString("description", &description);
if (!err)
err = (isLong
? fDatabase.SetLongDescription(type, description)
: fDatabase.SetShortDescription(type, description));
if (!err) {
err = isLong
? fDatabase.SetLongDescription(type, description)
: fDatabase.SetShortDescription(type, description);
}
break;
}
@@ -350,25 +360,28 @@ MIMEManager::HandleSetParam(BMessage *message)
const void *data;
ssize_t dataSize;
int32 size;
err = message->FindData("icon data", B_RAW_TYPE, &data, &dataSize);
err = message->FindData("icon data", B_RAW_TYPE, &data,
&dataSize);
if (!err)
err = message->FindInt32("icon size", &size);
if (which == B_REG_MIME_ICON_FOR_TYPE) {
const char *fileType;
if (!err)
err = message->FindString("file type", &fileType);
if (!err)
err = size == -1 ?
fDatabase.SetIconForType(type, fileType, data,
dataSize) :
fDatabase.SetIconForType(type, fileType, data,
if (!err) {
err = size == -1
? fDatabase.SetIconForType(type, fileType, data,
dataSize)
: fDatabase.SetIconForType(type, fileType, data,
dataSize, (icon_size)size);
}
} else {
if (!err)
err = size == -1 ?
fDatabase.SetIcon(type, data, dataSize) :
fDatabase.SetIcon(type, data, dataSize,
if (!err) {
err = size == -1
? fDatabase.SetIcon(type, data, dataSize)
: fDatabase.SetIcon(type, data, dataSize,
(icon_size)size);
}
}
break;
// End temporary fix code
@@ -381,8 +394,10 @@ MIMEManager::HandleSetParam(BMessage *message)
err = message->FindString("signature", &signature);
if (!err)
err = message->FindInt32("app verb", &verb);
if (!err)
err = fDatabase.SetPreferredApp(type, signature, (app_verb)verb);
if (!err) {
err = fDatabase.SetPreferredApp(type, signature,
(app_verb)verb);
}
break;
}
@@ -418,13 +433,11 @@ MIMEManager::HandleSetParam(BMessage *message)
message->SendReply(&reply, this);
}
// HandleSetParam
//! Handles all B_REG_MIME_SET_PARAM messages
void
MIMEManager::HandleDeleteParam(BMessage *message)
{
// using BPrivate::MimeDatabase;
status_t err;
int32 which;
const char *type;
@@ -446,10 +459,11 @@ MIMEManager::HandleDeleteParam(BMessage *message)
{
bool isLong;
err = message->FindBool("long", &isLong);
if (!err)
if (!err) {
err = isLong
? fDatabase.DeleteLongDescription(type)
: fDatabase.DeleteShortDescription(type);
? fDatabase.DeleteLongDescription(type)
: fDatabase.DeleteShortDescription(type);
}
break;
}
@@ -466,15 +480,18 @@ MIMEManager::HandleDeleteParam(BMessage *message)
const char *fileType;
if (!err)
err = message->FindString("file type", &fileType);
if (!err)
err = (size == -1) ?
fDatabase.DeleteIconForType(type, fileType) :
fDatabase.DeleteIconForType(type, fileType, (icon_size)size);
if (!err) {
err = size == -1
? fDatabase.DeleteIconForType(type, fileType)
: fDatabase.DeleteIconForType(type, fileType,
(icon_size)size);
}
} else {
if (!err)
err = (size == -1) ?
fDatabase.DeleteIcon(type) :
fDatabase.DeleteIcon(type, (icon_size)size);
if (!err) {
err = size == -1
? fDatabase.DeleteIcon(type)
: fDatabase.DeleteIcon(type, (icon_size)size);
}
}
break;
}
+1 -1
View File
@@ -509,7 +509,7 @@ MessageDeliverer::Init()
// spawn the deliverer thread
fDelivererThread = spawn_thread(MessageDeliverer::_DelivererThreadEntry,
"message deliverer", B_NORMAL_PRIORITY, this);
"message deliverer", B_NORMAL_PRIORITY + 1, this);
if (fDelivererThread < 0)
return fDelivererThread;
+16 -13
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2001-2007, Haiku, Inc. All Rights Reserved.
* Copyright 2001-2009, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
@@ -54,7 +54,8 @@ static const bigtime_t kRosterSanityEventInterval = 1000000LL;
error code.
*/
Registrar::Registrar(status_t *error)
: BServer(kRegistrarSignature, false, error),
:
BServer(kRegistrarSignature, false, error),
fRoster(NULL),
fClipboardHandler(NULL),
fMIMEManager(NULL),
@@ -65,9 +66,11 @@ Registrar::Registrar(status_t *error)
fAuthenticationManager(NULL)
{
FUNCTION_START();
set_thread_priority(find_thread(NULL), B_NORMAL_PRIORITY + 1);
}
// destructor
/*! \brief Frees all resources associated with the registrar.
All registrar services, that haven't been shut down earlier, are
@@ -93,7 +96,7 @@ Registrar::~Registrar()
FUNCTION_END();
}
// MessageReceived
/*! \brief Overrides the super class version to dispatch roster specific
messages.
\param message The message to be handled
@@ -114,7 +117,7 @@ Registrar::MessageReceived(BMessage *message)
}
}
// ReadyToRun
/*! \brief Overrides the super class version to initialize the registrar
services.
*/
@@ -164,14 +167,14 @@ Registrar::ReadyToRun()
// create and schedule the sanity message event
fSanityEvent = new MessageEvent(system_time() + kRosterSanityEventInterval,
this, B_REG_ROSTER_SANITY_EVENT);
this, B_REG_ROSTER_SANITY_EVENT);
fSanityEvent->SetAutoDelete(false);
fEventQueue->AddEvent(fSanityEvent);
FUNCTION_END();
}
// QuitRequested
/*! \brief Overrides the super class version to avoid termination of the
registrar until the system shutdown.
*/
@@ -183,7 +186,7 @@ Registrar::QuitRequested()
return BApplication::QuitRequested();
}
// GetEventQueue
/*! \brief Returns the registrar's event queue.
\return The registrar's event queue.
*/
@@ -193,7 +196,7 @@ Registrar::GetEventQueue() const
return fEventQueue;
}
// App
/*! \brief Returns the Registrar application object.
\return The Registrar application object.
*/
@@ -203,7 +206,7 @@ Registrar::App()
return dynamic_cast<Registrar*>(be_app);
}
// _MessageReceived
void
Registrar::_MessageReceived(BMessage *message)
{
@@ -352,7 +355,7 @@ Registrar::_MessageReceived(BMessage *message)
}
}
// _HandleShutDown
/*! \brief Handle a shut down request message.
\param request The request to be handled.
*/
@@ -414,7 +417,7 @@ main()
// rename the main thread
rename_thread(find_thread(NULL), kRosterThreadName);
PRINT(("app->Run()...\n"));
PRINT(("app->Run()...\n"));
try {
app->Run();
@@ -427,7 +430,7 @@ PRINT(("app->Run()...\n"));
debugger("registrar main() caught unknown exception");
}
PRINT(("delete app...\n"));
PRINT(("delete app...\n"));
delete app;
FUNCTION_END();
+2 -2
View File
@@ -695,8 +695,8 @@ ShutdownProcess::Init(BMessage* request)
}
// start the worker thread
fWorker = spawn_thread(_WorkerEntry, "shutdown worker", B_NORMAL_PRIORITY,
this);
fWorker = spawn_thread(_WorkerEntry, "shutdown worker",
B_NORMAL_PRIORITY + 1, this);
if (fWorker < 0) {
fRoster->RemoveWatcher(this);
fRoster->SetShuttingDown(false);
@@ -1,6 +1,6 @@
/*
* Copyright 2008, Ingo Weinhold, ingo_weinhold@gmx.de.
* Copyright 2004-2008, Axel Dörfler, axeld@pinc-software.de.
* Copyright 2004-2009, Axel Dörfler, axeld@pinc-software.de.
* Distributed under the terms of the MIT License.
*/
@@ -182,14 +182,14 @@ IOScheduler::Init(const char* name)
strlcpy(buffer, name, sizeof(buffer));
strlcat(buffer, " scheduler", sizeof(buffer));
fSchedulerThread = spawn_kernel_thread(&_SchedulerThread, buffer,
B_NORMAL_PRIORITY, (void *)this);
B_NORMAL_PRIORITY + 2, (void *)this);
if (fSchedulerThread < B_OK)
return fSchedulerThread;
strlcpy(buffer, name, sizeof(buffer));
strlcat(buffer, " notifier", sizeof(buffer));
fRequestNotifierThread = spawn_kernel_thread(&_RequestNotifierThread,
buffer, B_NORMAL_PRIORITY, (void *)this);
buffer, B_NORMAL_PRIORITY + 2, (void *)this);
if (fRequestNotifierThread < B_OK)
return fRequestNotifierThread;