registrar: Whitespace and style cleanup only.

Generally this code still looks horrible (both from a style and from a
complexity point of view) and should eventually be reworked.
This commit is contained in:
Michael Lotz
2015-08-23 12:30:35 +02:00
parent 1deb22eb4b
commit dfb3208fa3
6 changed files with 116 additions and 106 deletions
@@ -1,10 +1,10 @@
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// This software is part of the OpenBeOS distribution and is covered // This software is part of the OpenBeOS distribution and is covered
// by the OpenBeOS license. // by the OpenBeOS license.
//--------------------------------------------------------------------- //---------------------------------------------------------------------
/*! /*!
\file CreateAppMetaMimeThread.h \file CreateAppMetaMimeThread.h
CreateAppMetaMimeThread interface declaration CreateAppMetaMimeThread interface declaration
*/ */
#ifndef _CREATE_APP_META_MIME_THREAD_H #ifndef _CREATE_APP_META_MIME_THREAD_H
+32 -32
View File
@@ -42,10 +42,11 @@ namespace Mime {
If \a replyee is non-NULL and construction succeeds, the MimeThreadObject If \a replyee is non-NULL and construction succeeds, the MimeThreadObject
assumes resposibility for its deletion. assumes resposibility for its deletion.
Also, if \c non-NULL, \a replyee is expected to be a \c B_REG_MIME_UPDATE_MIME_INFO Also, if \c non-NULL, \a replyee is expected to be a
or a \c B_REG_MIME_CREATE_APP_META_MIME message with a \c true \c "synchronous" \c B_REG_MIME_UPDATE_MIME_INFO or a \c B_REG_MIME_CREATE_APP_META_MIME
field detached from the registrar's mime manager looper (though this is not verified). message with a \c true \c "synchronous" field detached from the registrar's
mime manager looper (though this is not verified).
The message will be replied to at the end of the thread's execution. The message will be replied to at the end of the thread's execution.
*/ */
MimeUpdateThread::MimeUpdateThread(const char *name, int32 priority, MimeUpdateThread::MimeUpdateThread(const char *name, int32 priority,
@@ -65,9 +66,9 @@ MimeUpdateThread::MimeUpdateThread(const char *name, int32 priority,
/*! \brief Destroys the MimeUpdateThread object. /*! \brief Destroys the MimeUpdateThread object.
If the object was properly initialized (i.e. InitCheck() returns \c B_OK) and If the object was properly initialized (i.e. InitCheck() returns \c B_OK)
the replyee message passed to the constructor was \c non-NULL, the replyee and the replyee message passed to the constructor was \c non-NULL, the
message is deleted. replyee message is deleted.
*/ */
MimeUpdateThread::~MimeUpdateThread() MimeUpdateThread::~MimeUpdateThread()
{ {
@@ -122,20 +123,21 @@ MimeUpdateThread::ThreadFunction()
// Notify the thread manager to make a cleanup run // Notify the thread manager to make a cleanup run
if (!err) { if (!err) {
BMessage msg(B_REG_MIME_UPDATE_THREAD_FINISHED); BMessage msg(B_REG_MIME_UPDATE_THREAD_FINISHED);
status_t error = fManagerMessenger.SendMessage(&msg, (BHandler*)NULL, 500000); status_t error = fManagerMessenger.SendMessage(&msg, (BHandler*)NULL,
500000);
if (error) if (error)
OUT("WARNING: ThreadManager::ThreadEntryFunction(): Termination notification " OUT("WARNING: ThreadManager::ThreadEntryFunction(): Termination"
"failed with error 0x%" B_PRIx32 "\n", error); " notification failed with error 0x%" B_PRIx32 "\n", error);
} }
DBG(OUT("(id: %ld) exiting mime update thread with result 0x%" B_PRIx32 "\n", DBG(OUT("(id: %ld) exiting mime update thread with result 0x%" B_PRIx32
find_thread(NULL), err)); "\n", find_thread(NULL), err));
return err; return err;
} }
/*! \brief Returns true if the given device supports attributes, false /*! \brief Returns true if the given device supports attributes, false
if not (or if an error occurs while determining). if not (or if an error occurs while determining).
Device numbers and their corresponding support info are cached in Device numbers and their corresponding support info are cached in
a std::list to save unnecessarily \c statvfs()ing devices that have a std::list to save unnecessarily \c statvfs()ing devices that have
already been statvfs()ed (which might otherwise happen quite often already been statvfs()ed (which might otherwise happen quite often
@@ -152,13 +154,12 @@ MimeUpdateThread::DeviceSupportsAttributes(dev_t device)
// See if an entry for this device already exists // See if an entry for this device already exists
std::list< std::pair<dev_t,bool> >::iterator i; std::list< std::pair<dev_t,bool> >::iterator i;
for (i = fAttributeSupportList.begin(); for (i = fAttributeSupportList.begin();
i != fAttributeSupportList.end(); i != fAttributeSupportList.end(); i++)
i++)
{ {
if (i->first == device) if (i->first == device)
return i->second; return i->second;
} }
bool result = false; bool result = false;
// If we get here, no such device is yet in our list, // If we get here, no such device is yet in our list,
@@ -175,24 +176,24 @@ MimeUpdateThread::DeviceSupportsAttributes(dev_t device)
else else
fAttributeSupportList.push_back(p); fAttributeSupportList.push_back(p);
} }
return result; return result;
} }
// UpdateEntry // UpdateEntry
/*! \brief Updates the given entry and then recursively updates all the entry's child /*! \brief Updates the given entry and then recursively updates all the entry's
entries if the entry is a directory and \c fRecursive is true. child entries if the entry is a directory and \c fRecursive is true.
*/ */
status_t status_t
MimeUpdateThread::UpdateEntry(const entry_ref *ref) MimeUpdateThread::UpdateEntry(const entry_ref *ref)
{ {
status_t err = ref ? B_OK : B_BAD_VALUE; status_t err = ref ? B_OK : B_BAD_VALUE;
bool entryIsDir = false; bool entryIsDir = false;
// Look to see if we're being terminated // Look to see if we're being terminated
if (!err && fShouldExit) if (!err && fShouldExit)
err = B_CANCELED; err = B_CANCELED;
// Before we update, make sure this entry lives on a device that supports // Before we update, make sure this entry lives on a device that supports
// attributes. If not, we skip it and any of its children for // attributes. If not, we skip it and any of its children for
// updates (we don't signal an error, however). // updates (we don't signal an error, however).
@@ -202,7 +203,7 @@ MimeUpdateThread::UpdateEntry(const entry_ref *ref)
// (DeviceSupportsAttributes(ref->device) ? "yes" : "no")); // (DeviceSupportsAttributes(ref->device) ? "yes" : "no"));
if (!err && (device_is_root_device(ref->device) if (!err && (device_is_root_device(ref->device)
|| DeviceSupportsAttributes(ref->device))) { || DeviceSupportsAttributes(ref->device))) {
// Update this entry // Update this entry
if (!err) { if (!err) {
// R5 appears to ignore whether or not the update succeeds. // R5 appears to ignore whether or not the update succeeds.
@@ -211,8 +212,8 @@ MimeUpdateThread::UpdateEntry(const entry_ref *ref)
// If we're recursing and this is a directory, update // If we're recursing and this is a directory, update
// each of the directory's children as well // each of the directory's children as well
if (!err && fRecursive && entryIsDir) { if (!err && fRecursive && entryIsDir) {
BDirectory dir; BDirectory dir;
err = dir.SetTo(ref); err = dir.SetTo(ref);
if (!err) { if (!err) {
entry_ref childRef; entry_ref childRef;
@@ -222,16 +223,15 @@ MimeUpdateThread::UpdateEntry(const entry_ref *ref)
// If we've come to the end of the directory listing, // If we've come to the end of the directory listing,
// it's not an error. // it's not an error.
if (err == B_ENTRY_NOT_FOUND) if (err == B_ENTRY_NOT_FOUND)
err = B_OK; err = B_OK;
break; break;
} else { } else
err = UpdateEntry(&childRef); err = UpdateEntry(&childRef);
} }
} }
}
} }
} }
return err; return err;
} }
} // namespace Mime } // namespace Mime
+14 -13
View File
@@ -15,27 +15,28 @@
/*! \class RegistrarThread /*! \class RegistrarThread
\brief Base thread class for threads spawned and managed by the registrar \brief Base thread class for threads spawned and managed by the registrar
*/ */
// constructor // constructor
/*! \brief Creates a new RegistrarThread object, spawning the object's /*! \brief Creates a new RegistrarThread object, spawning the object's
thread. thread.
Call Run() to actually get the thread running. Call Run() to actually get the thread running.
\param name The desired name of the new thread \param name The desired name of the new thread
\param priority The desired priority of the new thread \param priority The desired priority of the new thread
\param managerMessenger A BMessenger to the thread manager to which this \param managerMessenger A BMessenger to the thread manager to which this
thread does or will belong. thread does or will belong.
*/ */
RegistrarThread::RegistrarThread(const char *name, int32 priority, BMessenger managerMessenger) RegistrarThread::RegistrarThread(const char *name, int32 priority,
: fManagerMessenger(managerMessenger) BMessenger managerMessenger)
, fShouldExit(false) :
, fIsFinished(false) fManagerMessenger(managerMessenger),
, fStatus(B_NO_INIT) fShouldExit(false),
, fId(-1) fIsFinished(false),
, fPriority(priority) fStatus(B_NO_INIT),
fId(-1),
fPriority(priority)
{ {
fName[0] = 0; fName[0] = 0;
status_t err = name && fManagerMessenger.IsValid() ? B_OK : B_BAD_VALUE; status_t err = name && fManagerMessenger.IsValid() ? B_OK : B_BAD_VALUE;
@@ -71,7 +72,7 @@ RegistrarThread::Run()
fId = spawn_thread(&RegistrarThread::EntryFunction, fName, fId = spawn_thread(&RegistrarThread::EntryFunction, fName,
fPriority, (void*)this); fPriority, (void*)this);
err = fId >= 0 ? B_OK : fId; err = fId >= 0 ? B_OK : fId;
if (err == B_OK) if (err == B_OK)
err = resume_thread(fId); err = resume_thread(fId);
} }
return err; return err;
@@ -86,13 +87,13 @@ RegistrarThread::Id() const
} }
// Name // Name
//! Returns the name of the thread //! Returns the name of the thread
const char* const char*
RegistrarThread::Name() const RegistrarThread::Name() const
{ {
return fName; return fName;
} }
// AskToExit // AskToExit
/*! \brief Signals to thread that it needs to quit politely as soon /*! \brief Signals to thread that it needs to quit politely as soon
as possible. as possible.
+14 -12
View File
@@ -1,10 +1,10 @@
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// This software is part of the OpenBeOS distribution and is covered // This software is part of the OpenBeOS distribution and is covered
// by the OpenBeOS license. // by the OpenBeOS license.
//--------------------------------------------------------------------- //---------------------------------------------------------------------
/*! /*!
\file RegistrarThread.h \file RegistrarThread.h
RegistrarThread interface declaration RegistrarThread interface declaration
*/ */
#ifndef REGISTRAR_THREAD_H #ifndef REGISTRAR_THREAD_H
@@ -15,30 +15,32 @@
class RegistrarThread { class RegistrarThread {
public: public:
RegistrarThread(const char *name, int32 priority, BMessenger managerMessenger); RegistrarThread(const char *name, int32 priority,
BMessenger managerMessenger);
virtual ~RegistrarThread(); virtual ~RegistrarThread();
virtual status_t InitCheck(); virtual status_t InitCheck();
status_t Run(); status_t Run();
thread_id Id() const; thread_id Id() const;
const char* Name() const; const char* Name() const;
void AskToExit(); void AskToExit();
bool IsFinished() const; bool IsFinished() const;
protected: protected:
//! The function executed in the object's thread when Run() is called //! The function executed in the object's thread when Run() is called
virtual status_t ThreadFunction() = 0; virtual status_t ThreadFunction() = 0;
BMessenger fManagerMessenger; BMessenger fManagerMessenger;
bool fShouldExit; // Initially false, may be set to true by AskToExit() bool fShouldExit; // Initially false, may be set to true by AskToExit()
bool fIsFinished; // Initially false, set to true by the thread itself upon completion bool fIsFinished; // Initially false, set to true by the thread itself
// upon completion
private: private:
static int32 EntryFunction(void *data); static int32 EntryFunction(void *data);
status_t fStatus; status_t fStatus;
thread_id fId; thread_id fId;
char fName[B_OS_NAME_LENGTH]; char fName[B_OS_NAME_LENGTH];
int32 fPriority; int32 fPriority;
}; };
@@ -24,8 +24,8 @@ using namespace BPrivate;
/*! /*!
\class RegistrarThreadManager \class RegistrarThreadManager
\brief RegistrarThreadManager is the master of all threads spawned by the registrar \brief RegistrarThreadManager is the master of all threads spawned by the
registrar
*/ */
//! Creates a new RegistrarThreadManager object //! Creates a new RegistrarThreadManager object
@@ -35,8 +35,8 @@ RegistrarThreadManager::RegistrarThreadManager()
} }
// destructor // destructor
/*! \brief Destroys the RegistrarThreadManager object, killing and deleting any still /*! \brief Destroys the RegistrarThreadManager object, killing and deleting any
running threads. still running threads.
*/ */
RegistrarThreadManager::~RegistrarThreadManager() RegistrarThreadManager::~RegistrarThreadManager()
{ {
@@ -44,9 +44,11 @@ RegistrarThreadManager::~RegistrarThreadManager()
} }
// MessageReceived // MessageReceived
/*! \brief Handles \c B_REG_MIME_UPDATE_THREAD_FINISHED messages, passing on all others. /*! \brief Handles \c B_REG_MIME_UPDATE_THREAD_FINISHED messages, passing on all
others.
Each \c B_REG_MIME_UPDATE_THREAD_FINISHED message triggers a call to CleanupThreads(). Each \c B_REG_MIME_UPDATE_THREAD_FINISHED message triggers a call to
CleanupThreads().
*/ */
void void
RegistrarThreadManager::MessageReceived(BMessage* message) RegistrarThreadManager::MessageReceived(BMessage* message)
@@ -57,7 +59,7 @@ RegistrarThreadManager::MessageReceived(BMessage* message)
CleanupThreads(); CleanupThreads();
break; break;
} }
default: default:
{ {
BHandler::MessageReceived(message); BHandler::MessageReceived(message);
@@ -71,15 +73,16 @@ RegistrarThreadManager::MessageReceived(BMessage* message)
RegistrarThreadManager object. RegistrarThreadManager object.
\param thread Pointer to a newly allocated \c RegistrarThread object. \param thread Pointer to a newly allocated \c RegistrarThread object.
If the result of the function is \c B_OK, the \c RegistrarThreadManager object If the result of the function is \c B_OK, the \c RegistrarThreadManager
assumes ownership of \a thread; if the result is an error code, it object assumes ownership of \a thread; if the result is an error code, it
does not. does not.
\return \return
- \c B_OK: success - \c B_OK: success
- \c B_NO_MORE_THREADS: the number of concurrently allowed threads (defined by - \c B_NO_MORE_THREADS: the number of concurrently allowed threads (defined
RegistrarThreadManager::kThreadLimit) has already been reached by RegistrarThreadManager::kThreadLimit) has
already been reached
- \c B_BAD_THREAD_STATE: the thread has already been launched - \c B_BAD_THREAD_STATE: the thread has already been launched
- other error code: failure - other error code: failure
*/ */
@@ -110,14 +113,14 @@ RegistrarThreadManager::LaunchThread(RegistrarThread *thread)
} }
} }
if (!err) if (!err)
DBG(OUT("RegistrarThreadManager::LaunchThread(): launched new '%s' thread, " DBG(OUT("RegistrarThreadManager::LaunchThread(): launched new '%s'"
"id %ld\n", thread->Name(), thread->Id())); " thread, id %ld\n", thread->Name(), thread->Id()));
return err; return err;
} }
// CleanupThreads // CleanupThreads
/*! \brief Frees the resources of any threads that are no longer running /*! \brief Frees the resources of any threads that are no longer running
\todo This function should perhaps be triggered periodically by a \todo This function should perhaps be triggered periodically by a
BMessageRunner once we have our own BMessageRunner implementation. BMessageRunner once we have our own BMessageRunner implementation.
*/ */
@@ -128,18 +131,19 @@ RegistrarThreadManager::CleanupThreads()
for (i = fThreads.begin(); i != fThreads.end(); ) { for (i = fThreads.begin(); i != fThreads.end(); ) {
if (*i) { if (*i) {
if ((*i)->IsFinished()) { if ((*i)->IsFinished()) {
DBG(OUT("RegistrarThreadManager::CleanupThreads(): Cleaning up thread %ld\n", DBG(OUT("RegistrarThreadManager::CleanupThreads(): Cleaning up"
(*i)->Id())); " thread %ld\n", (*i)->Id()));
RemoveThread(i); RemoveThread(i);
// adjusts i // adjusts i
} else } else
++i; ++i;
} else { } else {
OUT("WARNING: RegistrarThreadManager::CleanupThreads(): NULL mime_update_thread_shared_data " OUT("WARNING: RegistrarThreadManager::CleanupThreads(): NULL"
"pointer found in and removed from RegistrarThreadManager::fThreads list\n"); " mime_update_thread_shared_data pointer found in and removed"
" from RegistrarThreadManager::fThreads list\n");
i = fThreads.erase(i); i = fThreads.erase(i);
} }
} }
return B_OK; return B_OK;
} }
@@ -157,28 +161,29 @@ RegistrarThreadManager::ShutdownThreads()
for (i = fThreads.begin(); i != fThreads.end(); ) { for (i = fThreads.begin(); i != fThreads.end(); ) {
if (*i) { if (*i) {
if ((*i)->IsFinished()) { if ((*i)->IsFinished()) {
DBG(OUT("RegistrarThreadManager::ShutdownThreads(): Cleaning up thread %ld\n", DBG(OUT("RegistrarThreadManager::ShutdownThreads(): Cleaning up"
(*i)->Id())); " thread %ld\n", (*i)->Id()));
RemoveThread(i); RemoveThread(i);
// adjusts i // adjusts i
} else { } else {
DBG(OUT("RegistrarThreadManager::ShutdownThreads(): Shutting down thread %ld\n", DBG(OUT("RegistrarThreadManager::ShutdownThreads(): Shutting"
(*i)->Id())); " down thread %ld\n", (*i)->Id()));
(*i)->AskToExit(); (*i)->AskToExit();
++i; ++i;
} }
} else { } else {
OUT("WARNING: RegistrarThreadManager::ShutdownThreads(): NULL mime_update_thread_shared_data " OUT("WARNING: RegistrarThreadManager::ShutdownThreads(): NULL"
"pointer found in and removed from RegistrarThreadManager::fThreads list\n"); " mime_update_thread_shared_data pointer found in and removed"
" from RegistrarThreadManager::fThreads list\n");
i = fThreads.erase(i); i = fThreads.erase(i);
} }
} }
/*! \todo We may want to iterate back through the list at this point, /*! \todo We may want to iterate back through the list at this point,
snooze for a moment if find an unfinished thread, and kill it if snooze for a moment if find an unfinished thread, and kill it if
it still isn't finished by the time we're done snoozing. it still isn't finished by the time we're done snoozing.
*/ */
return B_OK; return B_OK;
} }
@@ -195,21 +200,22 @@ RegistrarThreadManager::KillThreads()
for (i = fThreads.begin(); i != fThreads.end(); ) { for (i = fThreads.begin(); i != fThreads.end(); ) {
if (*i) { if (*i) {
if (!(*i)->IsFinished()) { if (!(*i)->IsFinished()) {
DBG(OUT("RegistrarThreadManager::KillThreads(): Killing thread %ld\n", DBG(OUT("RegistrarThreadManager::KillThreads(): Killing thread"
(*i)->Id())); " %ld\n", (*i)->Id()));
status_t err = kill_thread((*i)->Id()); status_t err = kill_thread((*i)->Id());
if (err) if (err)
OUT("WARNING: RegistrarThreadManager::KillThreads(): kill_thread(%" OUT("WARNING: RegistrarThreadManager::KillThreads():"
B_PRId32 ") failed with error code 0x%" B_PRIx32 "\n", " kill_thread(%" B_PRId32 ") failed with error code"
(*i)->Id(), err); " 0x%" B_PRIx32 "\n", (*i)->Id(), err);
} }
DBG(OUT("RegistrarThreadManager::KillThreads(): Cleaning up thread %ld\n", DBG(OUT("RegistrarThreadManager::KillThreads(): Cleaning up thread"
(*i)->Id())); " %ld\n", (*i)->Id()));
RemoveThread(i); RemoveThread(i);
// adjusts i // adjusts i
} else { } else {
OUT("WARNING: RegistrarThreadManager::KillThreads(): NULL mime_update_thread_shared_data " OUT("WARNING: RegistrarThreadManager::KillThreads(): NULL"
"pointer found in and removed from RegistrarThreadManager::fThreads list\n"); " mime_update_thread_shared_data pointer found in and removed"
" from RegistrarThreadManager::fThreads list\n");
i = fThreads.erase(i); i = fThreads.erase(i);
} }
} }
@@ -222,7 +228,7 @@ RegistrarThreadManager::KillThreads()
This is not necessarily a count of how many threads are actually running, This is not necessarily a count of how many threads are actually running,
as threads may remain in the thread list that are finished and waiting as threads may remain in the thread list that are finished and waiting
to be cleaned up. to be cleaned up.
\return The number of threads currently under management \return The number of threads currently under management
*/ */
uint uint
@@ -1,10 +1,10 @@
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// This software is part of the OpenBeOS distribution and is covered // This software is part of the OpenBeOS distribution and is covered
// by the OpenBeOS license. // by the OpenBeOS license.
//--------------------------------------------------------------------- //---------------------------------------------------------------------
/*! /*!
\file RegistrarThreadManager.h \file RegistrarThreadManager.h
RegistrarThreadManager interface declaration RegistrarThreadManager interface declaration
*/ */
#ifndef REGISTRAR_THREAD_MANAGER_H #ifndef REGISTRAR_THREAD_MANAGER_H
@@ -21,7 +21,7 @@ class RegistrarThreadManager : public BHandler {
public: public:
RegistrarThreadManager(); RegistrarThreadManager();
~RegistrarThreadManager(); ~RegistrarThreadManager();
// BHandler virtuals // BHandler virtuals
virtual void MessageReceived(BMessage* message); virtual void MessageReceived(BMessage* message);
@@ -30,14 +30,15 @@ public:
status_t CleanupThreads(); status_t CleanupThreads();
status_t ShutdownThreads(); status_t ShutdownThreads();
status_t KillThreads(); status_t KillThreads();
uint ThreadCount() const; uint ThreadCount() const;
static const int kThreadLimit = 12; static const int kThreadLimit = 12;
private: private:
std::list<RegistrarThread*>::iterator& RemoveThread(std::list<RegistrarThread*>::iterator &i); std::list<RegistrarThread*>::iterator&
RemoveThread(std::list<RegistrarThread*>::iterator &i);
std::list<RegistrarThread*> fThreads; std::list<RegistrarThread*> fThreads;
int32 fThreadCount; int32 fThreadCount;
}; };