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
+17 -17
View File
@@ -43,9 +43,10 @@ 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,13 +123,14 @@ 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;
} }
@@ -152,8 +154,7 @@ 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;
@@ -180,8 +181,8 @@ MimeUpdateThread::DeviceSupportsAttributes(dev_t device)
} }
// 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)
@@ -224,13 +225,12 @@ MimeUpdateThread::UpdateEntry(const entry_ref *ref)
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;
} }
@@ -15,7 +15,6 @@
/*! \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
@@ -29,13 +28,15 @@
\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;
+4 -2
View File
@@ -15,7 +15,8 @@
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();
@@ -33,7 +34,8 @@ protected:
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);
@@ -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)
@@ -72,14 +74,15 @@ RegistrarThreadManager::MessageReceived(BMessage* message)
\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,8 +113,8 @@ 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;
} }
@@ -128,15 +131,16 @@ 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);
} }
} }
@@ -157,19 +161,20 @@ 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);
} }
} }
@@ -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);
} }
} }
@@ -36,7 +36,8 @@ public:
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;