Fix for bug 6991, replace registrars timer tick

Registrar schedules an event every second to do
fRoster-CheckSanity(). This uses 2.5% cpu on my machine
when idle. Changing it to five seconds lowers it to 0.1%

waddlesplash then pointed me to this bug which changes it
to watch for team deletion and call fRoster->CheckSanity()

As I know little in this area, it's mostly based on what
LaunchDaemon does in MessageRecieved.
This commit is contained in:
Fredrik Holmqvist 2019-01-12 21:05:47 +01:00
parent 40cdf7d607
commit a02e4534f5
3 changed files with 17 additions and 16 deletions

View File

@ -96,7 +96,6 @@ enum {
B_REG_GET_MESSAGE_RUNNER_INFO = 'rgri',
// internal registrar messages
B_REG_ROSTER_SANITY_EVENT = 'rgir',
B_REG_SHUTDOWN_FINISHED = 'rgsf',
B_REG_ROSTER_DEVICE_RESCAN = 'rgrs',

View File

@ -16,9 +16,11 @@
#include <Application.h>
#include <Clipboard.h>
#include <Message.h>
#include <MessengerPrivate.h>
#include <OS.h>
#include <RegistrarDefs.h>
#include <RosterPrivate.h>
#include <system_info.h>
#include "AuthenticationManager.h"
#include "ClipboardHandler.h"
@ -47,9 +49,6 @@ using namespace BPrivate;
//! Name of the event queue.
static const char *kEventQueueName = "timer_thread";
//! Time interval between two roster sanity checks (1 s).
static const bigtime_t kRosterSanityEventInterval = 1000000LL;
/*! \brief Creates the registrar application class.
\param error Passed to the BApplication constructor for returning an
@ -63,7 +62,6 @@ Registrar::Registrar(status_t* _error)
fMIMEManager(NULL),
fEventQueue(NULL),
fMessageRunnerManager(NULL),
fSanityEvent(NULL),
fShutdownProcess(NULL),
fAuthenticationManager(NULL),
fPackageWatchingManager(NULL)
@ -88,7 +86,6 @@ Registrar::~Registrar()
delete fPackageWatchingManager;
delete fMessageRunnerManager;
delete fEventQueue;
delete fSanityEvent;
fMIMEManager->Lock();
fMIMEManager->Quit();
RemoveHandler(fClipboardHandler);
@ -172,11 +169,15 @@ Registrar::ReadyToRun()
// create the package watching manager
fPackageWatchingManager = new PackageWatchingManager;
// create and schedule the sanity message event
fSanityEvent = new MessageEvent(system_time() + kRosterSanityEventInterval,
this, B_REG_ROSTER_SANITY_EVENT);
fSanityEvent->SetAutoDelete(false);
fEventQueue->AddEvent(fSanityEvent);
// Sanity check roster after team deletion
BMessenger target(this);
BMessenger::Private messengerPrivate(target);
port_id port = messengerPrivate.Port();
int32 token = messengerPrivate.Token();
__start_watching_system(-1, B_WATCH_SYSTEM_TEAM_DELETION, port, token);
//Clean up any early teams
fRoster->CheckSanity();
FUNCTION_END();
}
@ -352,11 +353,13 @@ Registrar::_MessageReceived(BMessage *message)
break;
// internal messages
case B_REG_ROSTER_SANITY_EVENT:
fRoster->CheckSanity();
fSanityEvent->SetTime(system_time() + kRosterSanityEventInterval);
fEventQueue->AddEvent(fSanityEvent);
case B_SYSTEM_OBJECT_UPDATE:
{
team_id team = (team_id)message->GetInt32("team", -1);
if (team >= 0 && message->GetInt32("opcode", 0) == B_TEAM_DELETED)
fRoster->HandleRemoveApp(message);
break;
}
case B_REG_SHUTDOWN_FINISHED:
if (fShutdownProcess) {
fShutdownProcess->PostMessage(B_QUIT_REQUESTED,

View File

@ -64,7 +64,6 @@ private:
MIMEManager *fMIMEManager;
EventQueue *fEventQueue;
MessageRunnerManager *fMessageRunnerManager;
MessageEvent *fSanityEvent;
ShutdownProcess *fShutdownProcess;
AuthenticationManager *fAuthenticationManager;
PackageWatchingManager *fPackageWatchingManager;