[haiku-commits] BRANCH looncraz-github.setviewuicolor [c299b7c5e960] in src: servers/app kits/interface

  • From: looncraz-github.setviewuicolor <community@xxxxxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Thu, 19 Nov 2015 05:17:00 +0100 (CET)

added 6 changesets to branch 'refs/remotes/looncraz-github/setviewuicolor'
old head: f3f3ae3aa9d72e7aa947db8e67f38ec9425e6c9a
new head: c299b7c5e960db14f273bc85523bf8444b5bbe53
overview: https://github.com/looncraz/haiku/compare/f3f3ae3aa9d7...c299b7c5e960

----------------------------------------------------------------------------

1eb241833068: Move DelayedMessagePrivate

Move DMScheduledMessage into DelayedMessageSender.cpp
Move DelayedMessageData into DelayedMessage.h/cpp
Remove DelayedMessagePrivate.h/cpp

Incorportates some style cleanup.

9d971483611c: Rename DMScheduledMessage to
DelayedMessagePrivate::ScheduledMessage

73253d815139: DelayedMessageSender: Don't use an interactive thread shutdown

Per Axel, now using wait_for_thread.

692ed309994f: Remove CHECK_READ and CHECK_WRITE macros.

Per Axel these are not desirable, as such they have been removed.

In addition, write access failures now reliably describe the error, rather
than
fInitStatus.

9a2d4d2914f8: BColorMap: Use BMessage::SetInt32 instead of RemoveName and
AddInt32

Thanks to axel for letting me know this even existed!
The actual computational complexity is probably no different, and the
operation should
be identical.

c299b7c5e960: Style Cleanup

No functional changes.

[ looncraz <looncraz@xxxxxxxxxxxx> ]

----------------------------------------------------------------------------

11 files changed, 624 insertions(+), 611 deletions(-)
headers/os/interface/ColorMap.h | 2 +-
headers/private/interface/ColorMapPrivate.h | 9 +-
src/kits/interface/ColorMap.cpp | 97 ++++--
src/servers/app/DelayedMessage.cpp | 277 ++++++++++++++-
src/servers/app/DelayedMessage.h | 79 ++++-
src/servers/app/DelayedMessagePrivate.cpp | 426 ------------------------
src/servers/app/DelayedMessagePrivate.h | 103 ------
src/servers/app/DelayedMessageSender.cpp | 224 +++++++++++--
src/servers/app/DelayedMessageSender.h | 13 +-
src/servers/app/Jamfile | 1 -
src/servers/app/MessageLooper.h | 4 +-

############################################################################

Commit: 1eb241833068b84ae53d5203d9fbd2951a38c309
Author: looncraz <looncraz@xxxxxxxxxxxx>
Date: Wed Nov 18 21:53:11 2015 UTC

Move DelayedMessagePrivate

Move DMScheduledMessage into DelayedMessageSender.cpp
Move DelayedMessageData into DelayedMessage.h/cpp
Remove DelayedMessagePrivate.h/cpp

Incorportates some style cleanup.

----------------------------------------------------------------------------

diff --git a/src/servers/app/DelayedMessage.cpp
b/src/servers/app/DelayedMessage.cpp
index ce89024..9b6e468 100644
--- a/src/servers/app/DelayedMessage.cpp
+++ b/src/servers/app/DelayedMessage.cpp
@@ -5,6 +5,15 @@
* Authors:
* Joseph Groover <looncraz@xxxxxxxxxxxx>
*/
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <LinkSender.h>
+#include <ServerProtocol.h>
+
#include "DelayedMessage.h"
#include "DelayedMessageSender.h"

@@ -31,8 +40,7 @@ DelayedMessage::~DelayedMessage()
bool
DelayedMessage::AddTarget(port_id port)
{
- if (fData == NULL
- || fHandedOff)
+ if (fData == NULL || fHandedOff)
return false;

return fData->AddTarget(port);
@@ -60,8 +68,7 @@ DelayedMessage::Attach(const void* data, size_t size)
status_t
DelayedMessage::Flush()
{
- if (fData == NULL
- || gDelayedMessageSender == NULL)
+ if (fData == NULL || gDelayedMessageSender == NULL)
return B_NO_MEMORY;

if (fHandedOff)
@@ -77,8 +84,7 @@ DelayedMessage::Flush()
DelayedMessageData*
DelayedMessage::HandOff()
{
- if (fData == NULL
- || fHandedOff)
+ if (fData == NULL || fHandedOff)
return NULL;

if (fData->CopyData()) {
@@ -89,3 +95,262 @@ DelayedMessage::HandOff()
return NULL;
}

+
+// #pragma mark DelayedMessageData
+
+
+DelayedMessageData::DelayedMessageData(port_id port, int32 code,
+ bigtime_t delay, uint32 delayMode, uint32 mergeMode, uint32 mergeMask)
+ :
+ fAttachments(3, true),
+ fValid(false),
+ fScheduledTime(delay),
+ fTargets(NULL),
+ fMainTarget(port),
+ fCode(code),
+ fMergeMode(mergeMode),
+ fMergeMask(mergeMask)
+{
+ bigtime_t currentTime = system_time();
+
+ if (delayMode == B_RELATIVE_TIMEOUT) {
+ if (fScheduledTime > DM_MAX_DELAY) {
+ fScheduledTime = DM_MINIMUM_DELAY;
+ // Set to minimum so error is apparent
+ }
+
+ fScheduledTime += currentTime;
+ } else if (delayMode == B_ABSOLUTE_TIMEOUT) {
+ if (fScheduledTime - currentTime > DM_MAX_DELAY)
+ fScheduledTime = currentTime + DM_MINIMUM_DELAY;
+ }
+}
+
+
+DelayedMessageData::~DelayedMessageData()
+{
+ // fAttachments goes out of scope and frees all memory allocated by the
+ // attachments upon copying.
+}
+
+
+bool
+DelayedMessageData::AddTarget(port_id port)
+{
+ if (fMainTarget == port || port <= 0)
+ return false;
+
+ if (fMainTarget < 0) {
+ fMainTarget = port;
+ return true;
+ }
+
+ if (fTargets == NULL)
+ fTargets = new(std::nothrow) BObjectList<port_id>(1, true);
+
+ if (fTargets == NULL)
+ return false;
+
+ // check for duplicates:
+ for (int32 index = 0; index < fTargets->CountItems(); ++index) {
+ if (port == *fTargets->ItemAt(index))
+ return false;
+ }
+
+ return fTargets->AddItem(new(std::nothrow) port_id(port));
+}
+
+
+void
+DelayedMessageData::RemoveTarget(port_id port)
+{
+ if (port <= 0)
+ return;
+
+ if (fMainTarget == port) {
+ fMainTarget = -1;
+ return;
+ }
+
+ if (fTargets != NULL) {
+ for (int32 index = 0; index < fTargets->CountItems(); ++index) {
+ port_id* target = fTargets->ItemAt(index);
+ if (port == *target) {
+ fTargets->RemoveItem(target, true);
+ return;
+ }
+ }
+ }
+}
+
+
+int32
+DelayedMessageData::CountTargets() const
+{
+ int32 count = 0;
+
+ if (fMainTarget > 0)
+ ++count;
+
+ if (fTargets == NULL)
+ return count;
+
+ return count + fTargets->CountItems();
+}
+
+
+void
+DelayedMessageData::MergeTargets(DelayedMessageData* other)
+{
+ AddTarget(other->fMainTarget);
+
+ if (other->fTargets != NULL) {
+ for (int32 index = 0; index < other->fTargets->CountItems();
++index)
+ AddTarget(*(other->fTargets->ItemAt(index)));
+ }
+}
+
+
+//! Copy data from original location - merging failed
+bool
+DelayedMessageData::CopyData()
+{
+ Attachment* attached = NULL;
+
+ for (int32 index = 0; index < fAttachments.CountItems(); ++index) {
+ attached = fAttachments.ItemAt(index);
+
+ if (attached == NULL || attached->data != NULL)
+ return false;
+
+ attached->data = malloc(attached->size);
+ if (attached->data == NULL)
+ return false;
+
+ memcpy(attached->data, attached->constData, attached->size);
+ }
+
+ fValid = true;
+ return true;
+}
+
+
+bool
+DelayedMessageData::MergeData(DelayedMessageData* other)
+{
+ if (!fValid
+ || other == NULL
+ || other->fCode != fCode
+ || fMergeMode == DM_NO_MERGE
+ || other->fMergeMode == DM_NO_MERGE
+ || other->fMergeMode != fMergeMode
+ || other->fAttachments.CountItems() !=
fAttachments.CountItems())
+ return false;
+
+ if (other->fMergeMode == DM_MERGE_CANCEL) {
+ MergeTargets(other);
+ return true;
+ }
+
+ // Compare data
+ Attachment* attached = NULL;
+ Attachment* otherAttached = NULL;
+
+ for (int32 index = 0; index < fAttachments.CountItems(); ++index) {
+ attached = fAttachments.ItemAt(index);
+ otherAttached = other->fAttachments.ItemAt(index);
+
+ if (attached == NULL
+ || otherAttached == NULL
+ || attached->data == NULL
+ || otherAttached->constData == NULL
+ || attached->size != otherAttached->size)
+ return false;
+
+ // Compares depending upon mode & flags
+ if (!_Compare(attached, otherAttached, index))
+ return false;
+ }
+
+ // add any targets not included in the existing message!
+ MergeTargets(other);
+
+ // since these are duplicates, we need not copy anything...
+ if (fMergeMode == DM_MERGE_DUPLICATES)
+ return true;
+
+ // DM_MERGE_REPLACE:
+
+ // Import the new data!
+ for (int32 index = 0; index < fAttachments.CountItems(); ++index) {
+ attached = fAttachments.ItemAt(index);
+ otherAttached = other->fAttachments.ItemAt(index);
+
+ // We already have allocated our memory, but the other data
+ // has not. So this reduces memory allocations.
+ memcpy(attached->data, otherAttached->constData,
attached->size);
+ }
+
+ return true;
+}
+
+
+bool
+DelayedMessageData::IsValid() const
+{
+ return fValid;
+}
+
+
+status_t
+DelayedMessageData::Attach(const void* data, size_t size)
+{
+ // Sanity checking already performed
+ Attachment* attach = new(std::nothrow) Attachment(data, size);
+
+ if (attach == NULL)
+ return B_NO_MEMORY;
+
+ if (fAttachments.AddItem(attach) == false) {
+ delete attach;
+ return B_ERROR;
+ }
+
+ return B_OK;
+}
+
+
+bool
+DelayedMessageData::_Compare(DelayedMessageData::Attachment* one,
+ DelayedMessageData::Attachment* two, int32 index)
+{
+ if (fMergeMode == DM_MERGE_DUPLICATES) {
+
+ // Default-policy: all data must match
+ if (fMergeMask == DM_DATA_DEFAULT || (fMergeMask & 1 << index)
!= 0)
+ return memcmp(one->data, two->constData, one->size) ==
0;
+
+ } else if (fMergeMode == DM_MERGE_REPLACE) {
+
+ // Default Policy: no data needs to match
+ if (fMergeMask != DM_DATA_DEFAULT && (fMergeMask & 1 << index)
!= 0)
+ return memcmp(one->data, two->constData, one->size) ==
0;
+ }
+
+ return true;
+}
+
+
+DelayedMessageData::Attachment::Attachment(const void* _data, size_t _size)
+ :
+ constData(_data),
+ data(NULL),
+ size(_size)
+{
+}
+
+
+DelayedMessageData::Attachment::~Attachment()
+{
+ free(data);
+}
diff --git a/src/servers/app/DelayedMessage.h b/src/servers/app/DelayedMessage.h
index 4cee92d..d5f799c 100644
--- a/src/servers/app/DelayedMessage.h
+++ b/src/servers/app/DelayedMessage.h
@@ -15,14 +15,14 @@

//! Method by which to merge DelayedMessages with the same code.
enum DMMergeMode {
- DM_NO_MERGE = 0,// Will send this message, and the
other(s)
- DM_MERGE_REPLACE = 1,// Replace older data with newer data
- DM_MERGE_CANCEL = 2,// keeps older data, cancels this message
- DM_MERGE_DUPLICATES = 3 // If data is the same, cancel new message
+ DM_NO_MERGE = 0, // Will send this message, and the
other(s)
+ DM_MERGE_REPLACE = 1, // Replace older data with newer data
+ DM_MERGE_CANCEL = 2, // keeps older data, cancels this message
+ DM_MERGE_DUPLICATES = 3 // If data is the same, cancel new message
};


-//! Merge-mode data-matching Z
+//! Merge-mode data-matching
enum {
DM_DATA_DEFAULT = 0,
DM_DATA_1 = 1 << 0,
@@ -96,8 +96,8 @@ private:
friend class DMScheduledMessage;

// forbidden methods
- void* operator new(size_t);
- void* operator new[](size_t);
+ void* operator new(size_t);
+ void* operator new[](size_t);

DelayedMessageData* HandOff();

@@ -145,12 +145,13 @@ DelayedMessage::AttachList(const BObjectList<Type>& list,
bool* which)
return AttachList(list);

int32 count = 0;
- for (int32 index = 0; index < list.CountItems(); ++index)
+ for (int32 index = 0; index < list.CountItems(); ++index) {
if (which[index])
++count;
+ }

if (count == 0)
- return B_ERROR;
+ return B_BAD_VALUE;

status_t error = Attach<int32>(count);

@@ -159,11 +160,63 @@ DelayedMessage::AttachList(const BObjectList<Type>& list,
bool* which)
break;

if (which[index])
- error = Attach<Type>(*(list.ItemAt(index)));
+ error = Attach<Type>(*list.ItemAt(index));
}

return error;
}


+/*! \class DelayedMessageData DelayedMessageSender.h
+ \brief Owns DelayedMessage data, allocates memory and copies data only
+ when needed,
+*/
+class DelayedMessageData {
+private:
+ friend class DMScheduledMessage;
+ friend class DelayedMessage;
+
+
DelayedMessageData(port_id port, int32 code,
+
bigtime_t delay, uint32 delayMode,
+ uint32
mergeMode, uint32 mergeMask);
+
~DelayedMessageData();
+
+ bool AddTarget(port_id port);
+ void RemoveTarget(port_id
port);
+ int32 CountTargets() const;
+
+ void
MergeTargets(DelayedMessageData* other);
+
+ bool CopyData();
+ bool
MergeData(DelayedMessageData* other);
+
+ bool IsValid() const;
+ // Only valid after a successful CopyData()
+
+ status_t Attach(const void*
data, size_t size);
+
+private:
+ struct Attachment {
+ const void* constData;
+ void* data;
+ size_t size;
+
+
Attachment(const void*, size_t);
+ ~Attachment();
+ };
+
+ bool _Compare(Attachment*
one, Attachment* two,
+ int32
index);
+
+ BObjectList<Attachment> fAttachments;
+ bool fValid;
+ bigtime_t fScheduledTime;
+ BObjectList<port_id>* fTargets;
+ port_id fMainTarget;
+ int32 fCode;
+ uint32 fMergeMode;
+ uint32 fMergeMask;
+};
+
+
#endif // AS_DELAYED_MESSAGE_H
diff --git a/src/servers/app/DelayedMessagePrivate.cpp
b/src/servers/app/DelayedMessagePrivate.cpp
deleted file mode 100644
index cf2d8c1..0000000
--- a/src/servers/app/DelayedMessagePrivate.cpp
+++ /dev/null
@@ -1,426 +0,0 @@
-/*
- * Copyright 2015, Haiku.
- * Distributed under the terms of the MIT License.
- *
- * Authors:
- * Joseph Groover <looncraz@xxxxxxxxxxxx>
-*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <LinkSender.h>
-#include <ServerProtocol.h>
-
-#include "DelayedMessagePrivate.h"
-
-#include "DelayedMessage.h"
-#include "DelayedMessageSender.h"
-
-
-//#pragma mark DelayedMessageData
-
-
-DelayedMessageData::DelayedMessageData(port_id port, int32 code,
- bigtime_t delay, uint32 delayMode, uint32 mergeMode, uint32 mergeMask)
- :
- fAttachments(3, true),
- fValid(false),
- fScheduledTime(delay),
- fTargets(NULL),
- fMainTarget(port),
- fCode(code),
- fMergeMode(mergeMode),
- fMergeMask(mergeMask)
-{
- bigtime_t currentTime = system_time();
-
- if (delayMode == B_RELATIVE_TIMEOUT) {
- if (fScheduledTime > DM_MAX_DELAY)
- fScheduledTime = DM_MINIMUM_DELAY;
- // Set to minimum so error is apparent
-
- fScheduledTime += currentTime;
- } else if (delayMode == B_ABSOLUTE_TIMEOUT) {
- if (fScheduledTime - currentTime > DM_MAX_DELAY)
- fScheduledTime = currentTime + DM_MINIMUM_DELAY;
- }
-}
-
-
-DelayedMessageData::~DelayedMessageData()
-{
- // fAttachments goes out of scope and frees all memory allocated by the
- // attachments upon copying.
-}
-
-
-bool
-DelayedMessageData::AddTarget(port_id port)
-{
- if (fMainTarget == port
- || port <= 0)
- return false;
-
- if (fMainTarget < 0) {
- fMainTarget = port;
- return true;
- }
-
- if (fTargets == NULL)
- fTargets = new(std::nothrow) BObjectList<port_id>(1, true);
-
- if (fTargets == NULL)
- return false;
-
- // check for duplicates:
- for (int32 index = 0; index < fTargets->CountItems(); ++index)
- if (port == *(fTargets->ItemAt(index)))
- return false;
-
- return fTargets->AddItem(new(std::nothrow) port_id(port));
-}
-
-
-void
-DelayedMessageData::RemoveTarget(port_id port)
-{
- if (port <= 0)
- return;
-
- if (fMainTarget == port) {
- fMainTarget = -1;
- return;
- }
-
- if (fTargets != NULL) {
- port_id* target = NULL;
- for (int32 index = 0; index < fTargets->CountItems(); ++index) {
- target = fTargets->ItemAt(index);
- if (port == *target) {
- fTargets->RemoveItem(target, true);
- return;
- }
- }
- }
-}
-
-
-int32
-DelayedMessageData::CountTargets() const
-{
- int32 count = 0;
-
- if (fMainTarget > 0)
- ++count;
-
- if (fTargets == NULL)
- return count;
-
- return count + fTargets->CountItems();
-}
-
-
-void
-DelayedMessageData::MergeTargets(DelayedMessageData* other)
-{
- AddTarget(other->fMainTarget);
-
- if (other->fTargets != NULL)
- for (int32 index = 0; index < other->fTargets->CountItems();
++index)
- AddTarget(*(other->fTargets->ItemAt(index)));
-}
-
-
-//! Copy data from original location - merging failed
-bool
-DelayedMessageData::CopyData()
-{
- Attachment* attached = NULL;
-
- for (int32 index = 0; index < fAttachments.CountItems(); ++index) {
- attached = fAttachments.ItemAt(index);
-
- if (attached == NULL
- || attached->data != NULL)
- return false;
-
- attached->data = malloc(attached->size);
- if (attached->data == NULL)
- return false;
-
- memcpy(attached->data, attached->constData, attached->size);
- }
-
- fValid = true;
- return true;
-}
-
-
-bool
-DelayedMessageData::MergeData(DelayedMessageData* other)
-{
- if (!fValid
- || other == NULL
- || other->fCode != fCode
- || fMergeMode == DM_NO_MERGE
- || other->fMergeMode == DM_NO_MERGE
- || other->fMergeMode != fMergeMode
- || other->fAttachments.CountItems() !=
fAttachments.CountItems())
- return false;
-
- if (other->fMergeMode == DM_MERGE_CANCEL) {
- MergeTargets(other);
- return true;
- }
-
- // Compare data
- Attachment* attached = NULL;
- Attachment* otherAttached = NULL;
-
- for (int32 index = 0; index < fAttachments.CountItems(); ++index) {
- attached = fAttachments.ItemAt(index);
- otherAttached = other->fAttachments.ItemAt(index);
-
- if (attached == NULL
- || otherAttached == NULL
- || attached->data == NULL
- || otherAttached->constData == NULL
- || attached->size != otherAttached->size)
- return false;
-
- // Compares depending upon mode & flags
- if (!_Compare(attached, otherAttached, index))
- return false;
- }
-
- // add any targets not included in the existing message!
- MergeTargets(other);
-
- // since these are duplicates, we need not copy anything...
- if (fMergeMode == DM_MERGE_DUPLICATES)
- return true;
-
- // DM_MERGE_REPLACE:
-
- // Import the new data!
- for (int32 index = 0; index < fAttachments.CountItems(); ++index) {
- attached = fAttachments.ItemAt(index);
- otherAttached = other->fAttachments.ItemAt(index);
-
- // We already have allocated our memory, but the other data
- // has not. So this reduces memory allocations.
- memcpy(attached->data, otherAttached->constData,
attached->size);
- }
-
- return true;
-}
-
-
-bool
-DelayedMessageData::IsValid() const
-{
- return fValid;
-}
-
-
-status_t
-DelayedMessageData::Attach(const void* data, size_t size)
-{
- // Sanity checking already performed
- Attachment* attach = new(std::nothrow) Attachment(data, size);
-
- if (attach == NULL)
- return B_NO_MEMORY;
-
- if (fAttachments.AddItem(attach) == false) {
- delete attach;
- return B_ERROR;
- }
-
- return B_OK;
-}
-
-
-bool
-DelayedMessageData::_Compare(DelayedMessageData::Attachment* one,
- DelayedMessageData::Attachment* two, int32 index)
-{
- if (fMergeMode == DM_MERGE_DUPLICATES) {
-
- // Default-policy: all data must match
- if (fMergeMask == DM_DATA_DEFAULT
- || (fMergeMask & 1 << index) != 0)
- return memcmp(one->data, two->constData, one->size) ==
0;
-
- } else if (fMergeMode == DM_MERGE_REPLACE) {
-
- // Default Policy: no data needs to match
- if (fMergeMask != DM_DATA_DEFAULT
- && (fMergeMask & 1 << index) != 0)
- return memcmp(one->data, two->constData, one->size) ==
0;
- }
-
- return true;
-}
-
-
-DelayedMessageData::Attachment::Attachment(const void* _data, size_t _size)
- :
- constData(_data),
- data(NULL),
- size(_size)
-{
-}
-
-
-DelayedMessageData::Attachment::~Attachment()
-{
- free(data);
-}
-
-
-//#pragma mark DMScheduledMessage
-
-
-DMScheduledMessage::DMScheduledMessage(DelayedMessage& message)
- :
- fData(message.HandOff()),
- fFailureCount(0)
-{
-}
-
-
-DMScheduledMessage::~DMScheduledMessage()
-{
- delete fData;
-}
-
-
-int32
-DMScheduledMessage::CountTargets() const
-{
- if (fData == NULL)
- return 0;
-
- return fData->CountTargets();
-}
-
-
-bigtime_t
-DMScheduledMessage::ScheduledTime() const
-{
- if (fData == NULL)
- return 0;
-
- return fData->fScheduledTime;
-}
-
-
-//! Send our message and data to their intended target(s)
-int32
-DMScheduledMessage::SendMessage()
-{
- if (fData == NULL
- || !fData->IsValid()) {
- fFailureCount += 10000;
- return -2;
- }
-
- int32 sent = 0;
- if (_SendMessageToPort(fData->fMainTarget) == B_OK)
- ++sent;
- else
- ++fFailureCount;
-
- if (fData->fTargets == NULL)
- return sent;
-
- port_id port;
- for (int32 index = 0; index < fData->fTargets->CountItems(); ++index) {
- port = *(fData->fTargets->ItemAt(index));
-
- if (_SendMessageToPort(port) == B_OK)
- ++sent;
- else
- ++fFailureCount;
- }
-
- return sent;
-}
-
-
-status_t
-DMScheduledMessage::_SendMessageToPort(port_id port)
-{
- if (fData == NULL
- || !fData->IsValid())
- return B_BAD_DATA;
-
- if (port == B_BAD_PORT_ID)
- return B_BAD_VALUE;
-
- BPrivate::LinkSender sender(port);
- if (sender.StartMessage(fData->fCode) != B_OK)
- return B_ERROR;
-
- BObjectList<DelayedMessageData::Attachment>& list = fData->fAttachments;
- DelayedMessageData::Attachment* attached = NULL;
- status_t error = B_OK;
-
- // The data has been checked already, so we assume it is all good
- for (int32 index = 0; index < list.CountItems(); ++index) {
- attached = list.ItemAt(index);
-
- error = sender.Attach(attached->data, attached->size);
- if (error != B_OK) {
- sender.CancelMessage();
- return error;
- }
- }
-
- error = sender.Flush(DM_ONE_SECOND_DELAY);
-
- if (error == B_OK
- || error == B_BAD_PORT_ID)
- fData->RemoveTarget(port);
-
- return error;
-}
-
-
-bool
-DMScheduledMessage::IsValid() const
-{
- return fData != NULL && fData->IsValid();
-}
-
-
-bool
-DMScheduledMessage::Merge(DelayedMessage& other)
-{
- if (!IsValid())
- return false;
-
- return fData->MergeData(other.fData);
-}
-
-
-uint32
-DMScheduledMessage::FailureCount() const
-{
- return fFailureCount;
-}
-
-
-bool
-DMScheduledMessage:: operator<(const DMScheduledMessage& other) const
-{
- if (!IsValid()
- || !other.IsValid())
- return false;
-
- return fData->fScheduledTime < other.fData->fScheduledTime;
-}
-
diff --git a/src/servers/app/DelayedMessagePrivate.h
b/src/servers/app/DelayedMessagePrivate.h
deleted file mode 100644
index 1f19fed..0000000
--- a/src/servers/app/DelayedMessagePrivate.h
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * Copyright 2015, Haiku.
- * Distributed under the terms of the MIT License.
- *
- * Authors:
- * Joseph Groover <looncraz@xxxxxxxxxxxx>
-*/
-#ifndef DELAYED_MESSAGE_PRIVATE_H
-#define DELAYED_MESSAGE_PRIVATE_H
-
-
-#include <ObjectList.h>
-#include <OS.h>
-
-
-class DelayedMessage;
-class DelayedMessageSender;
-
-
-/*! \class DelayedMessageData DelayedMessageSender.h
- \brief Owns DelayedMessage data, allocates memory and copies data only
- when needed,
-*/
-class DelayedMessageData {
-private:
- friend class DMScheduledMessage;
- friend class DelayedMessage;
-
-
DelayedMessageData(port_id port, int32 code,
-
bigtime_t delay, uint32 delayMode,
- uint32
mergeMode, uint32 mergeMask);
-
~DelayedMessageData();
-
- bool AddTarget(port_id port);
- void RemoveTarget(port_id
port);
- int32 CountTargets() const;
-
- void
MergeTargets(DelayedMessageData* other);
-
- bool CopyData();
- bool
MergeData(DelayedMessageData* other);
-
- bool IsValid() const;
- // Only valid after a successful CopyData()
-
- status_t Attach(const void*
data, size_t size);
-
-private:
- struct Attachment {
- const void* constData;
- void* data;
- size_t size;
-
-
Attachment(const void*, size_t);
- ~Attachment();
- };
-
- bool _Compare(Attachment*
one, Attachment* two,
- int32
index);
-
- BObjectList<Attachment> fAttachments;
- bool fValid;
- bigtime_t fScheduledTime;
- BObjectList<port_id>* fTargets;
- port_id fMainTarget;
- int32 fCode;
- uint32 fMergeMode;
- uint32 fMergeMask;
-};
-
-
-/*! \class DMScheduledMessage DelayedMessageSender.h
- \brief Responsible for sending of delayed message.
-*/
-class DMScheduledMessage {
-private:
-
DMScheduledMessage(DelayedMessage& message);
-
~DMScheduledMessage();
-
- int32 CountTargets() const;
-
- void Finalize();
- bigtime_t ScheduledTime() const;
- int32 SendMessage();
- bool IsValid() const;
- bool Merge(DelayedMessage&
message);
- uint32 FailureCount() const;
-
-private:
- status_t
_SendMessageToPort(port_id port);
-
- DelayedMessageData* fData;
- uint32 fFailureCount;
-
- friend class DelayedMessageSender;
- friend class DelayedMessage;
- friend class BObjectList<DMScheduledMessage>;
-public:
- bool operator <(const DMScheduledMessage&
other) const;
-};
-
-
-#endif // DELAYED_MESSAGE_PRIVATE_H
diff --git a/src/servers/app/DelayedMessageSender.cpp
b/src/servers/app/DelayedMessageSender.cpp
index 732118f..4ab83ae 100644
--- a/src/servers/app/DelayedMessageSender.cpp
+++ b/src/servers/app/DelayedMessageSender.cpp
@@ -5,6 +5,8 @@
* Authors:
* Joseph Groover <looncraz@xxxxxxxxxxxx>
*/
+
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -26,10 +28,190 @@ static const char* kName = "DMT is here for you,
eventually...";
static int32 kPriority = B_URGENT_DISPLAY_PRIORITY;
static int32 kPortCapacity = 10;

-
DelayedMessageSender* gDelayedMessageSender = NULL;


+/*! \class DMScheduledMessage DelayedMessageSender.h
+ \brief Responsible for sending of delayed message.
+*/
+class DMScheduledMessage {
+private:
+
DMScheduledMessage(DelayedMessage& message);
+
~DMScheduledMessage();
+
+ int32 CountTargets() const;
+
+ void Finalize();
+ bigtime_t ScheduledTime() const;
+ int32 SendMessage();
+ bool IsValid() const;
+ bool Merge(DelayedMessage&
message);
+ uint32 FailureCount() const;
+
+private:
+ status_t
_SendMessageToPort(port_id port);
+
+ DelayedMessageData* fData;
+ uint32 fFailureCount;
+
+ friend class DelayedMessageSender;
+ friend class DelayedMessage;
+ friend class BObjectList<DMScheduledMessage>;
+public:
+ bool operator <(const DMScheduledMessage&
other) const;
+};
+
+
+// #pragma mark -
+
+
+DMScheduledMessage::DMScheduledMessage(DelayedMessage& message)
+ :
+ fData(message.HandOff()),
+ fFailureCount(0)
+{
+}
+
+
+DMScheduledMessage::~DMScheduledMessage()
+{
+ delete fData;
+}
+
+
+int32
+DMScheduledMessage::CountTargets() const
+{
+ if (fData == NULL)
+ return 0;
+
+ return fData->CountTargets();
+}
+
+
+bigtime_t
+DMScheduledMessage::ScheduledTime() const
+{
+ if (fData == NULL)
+ return 0;
+
+ return fData->fScheduledTime;
+}
+
+
+//! Send our message and data to their intended target(s)
+int32
+DMScheduledMessage::SendMessage()
+{
+ if (fData == NULL || !fData->IsValid()) {
+ fFailureCount += 10000;
+ return -2;
+ }
+
+ int32 sent = 0;
+ if (_SendMessageToPort(fData->fMainTarget) == B_OK)
+ ++sent;
+ else
+ ++fFailureCount;
+
+ if (fData->fTargets == NULL)
+ return sent;
+
+ port_id port;
+ for (int32 index = 0; index < fData->fTargets->CountItems(); ++index) {
+ port = *(fData->fTargets->ItemAt(index));
+
+ if (_SendMessageToPort(port) == B_OK)
+ ++sent;
+ else
+ ++fFailureCount;
+ }
+
+ return sent;
+}
+
+
+status_t
+DMScheduledMessage::_SendMessageToPort(port_id port)
+{
+ if (fData == NULL || !fData->IsValid())
+ return B_BAD_DATA;
+
+ if (port == B_BAD_PORT_ID)
+ return B_BAD_VALUE;
+
+ BPrivate::LinkSender sender(port);
+ if (sender.StartMessage(fData->fCode) != B_OK)
+ return B_ERROR;
+
+ BObjectList<DelayedMessageData::Attachment>& list = fData->fAttachments;
+ DelayedMessageData::Attachment* attached = NULL;
+ status_t error = B_OK;
+
+ // The data has been checked already, so we assume it is all good
+ for (int32 index = 0; index < list.CountItems(); ++index) {
+ attached = list.ItemAt(index);
+
+ error = sender.Attach(attached->data, attached->size);
+ if (error != B_OK) {
+ sender.CancelMessage();
+ return error;
+ }
+ }
+
+ error = sender.Flush(DM_ONE_SECOND_DELAY);
+
+ if (error == B_OK || error == B_BAD_PORT_ID)
+ fData->RemoveTarget(port);
+
+ return error;
+}
+
+
+bool
+DMScheduledMessage::IsValid() const
+{
+ return fData != NULL && fData->IsValid();
+}
+
+
+bool
+DMScheduledMessage::Merge(DelayedMessage& other)
+{
+ if (!IsValid())
+ return false;
+
+ return fData->MergeData(other.fData);
+}
+
+
+uint32
+DMScheduledMessage::FailureCount() const
+{
+ return fFailureCount;
+}
+
+
+bool
+DMScheduledMessage::operator<(const DMScheduledMessage& other) const
+{
+ if (!IsValid() || !other.IsValid())
+ return false;
+
+ return fData->fScheduledTime < other.fData->fScheduledTime;
+}
+
+
+int CompareMessages(const DMScheduledMessage* one,
+ const DMScheduledMessage* two)
+{
+ return *one < *two;
+}
+
+
+// #pragma mark -
+
+
DelayedMessageSender::DelayedMessageSender()
:
fLock("DelayedMessageSender"),
@@ -63,13 +245,6 @@ DelayedMessageSender::~DelayedMessageSender()
}


-int CompareMessages(const DMScheduledMessage* one,
- const DMScheduledMessage* two)
-{
- return *one < *two;
-}
-
-
status_t
DelayedMessageSender::ScheduleMessage(DelayedMessage& message)
{
diff --git a/src/servers/app/DelayedMessageSender.h
b/src/servers/app/DelayedMessageSender.h
index a80a452..4c027ed 100644
--- a/src/servers/app/DelayedMessageSender.h
+++ b/src/servers/app/DelayedMessageSender.h
@@ -13,7 +13,6 @@
#include <ObjectList.h>

#include "DelayedMessage.h"
-#include "DelayedMessagePrivate.h"


/*! \class DelayedMessageSender DelayedMessageSender.h
@@ -36,7 +35,7 @@ private:
void _Wakeup(bigtime_t
whatTime);

mutable BLocker fLock;
- BObjectList<DMScheduledMessage> fMessages;
+ BObjectList<DMScheduledMessage> fMessages;

bigtime_t fScheduledWakeup;

diff --git a/src/servers/app/Jamfile b/src/servers/app/Jamfile
index 5a3d81a..2f60068 100644
--- a/src/servers/app/Jamfile
+++ b/src/servers/app/Jamfile
@@ -57,7 +57,6 @@ Server app_server :
CursorManager.cpp
CursorSet.cpp
DelayedMessage.cpp
- DelayedMessagePrivate.cpp
DelayedMessageSender.cpp
Desktop.cpp
DesktopListener.cpp

############################################################################

Commit: 9d971483611cef5e7f7f8e94d74dd1c7bb899931
Author: looncraz <looncraz@xxxxxxxxxxxx>
Date: Thu Nov 19 03:21:55 2015 UTC

Rename DMScheduledMessage to DelayedMessagePrivate::ScheduledMessage

----------------------------------------------------------------------------

diff --git a/src/servers/app/DelayedMessage.h b/src/servers/app/DelayedMessage.h
index d5f799c..64e7a96 100644
--- a/src/servers/app/DelayedMessage.h
+++ b/src/servers/app/DelayedMessage.h
@@ -54,7 +54,9 @@ enum {


class DelayedMessageData;
-class DMScheduledMessage;
+namespace DelayedMessagePrivate {
+ class ScheduledMessage;
+};


/*! \class DelayedMessage
@@ -93,7 +95,7 @@ public:
status_t Flush();

private:
- friend class DMScheduledMessage;
+ friend class DelayedMessagePrivate::ScheduledMessage;

// forbidden methods
void* operator new(size_t);
@@ -173,7 +175,7 @@ DelayedMessage::AttachList(const BObjectList<Type>& list,
bool* which)
*/
class DelayedMessageData {
private:
- friend class DMScheduledMessage;
+ friend class DelayedMessagePrivate::ScheduledMessage;
friend class DelayedMessage;


DelayedMessageData(port_id port, int32 code,
diff --git a/src/servers/app/DelayedMessageSender.cpp
b/src/servers/app/DelayedMessageSender.cpp
index 4ab83ae..966d9bf 100644
--- a/src/servers/app/DelayedMessageSender.cpp
+++ b/src/servers/app/DelayedMessageSender.cpp
@@ -31,13 +31,15 @@ static int32 kPortCapacity = 10;
DelayedMessageSender* gDelayedMessageSender = NULL;


-/*! \class DMScheduledMessage DelayedMessageSender.h
+namespace DelayedMessagePrivate {
+
+/*! \class ScheduledMessage DelayedMessageSender.h
\brief Responsible for sending of delayed message.
*/
-class DMScheduledMessage {
-private:
-
DMScheduledMessage(DelayedMessage& message);
-
~DMScheduledMessage();
+class ScheduledMessage {
+public:
+
ScheduledMessage(DelayedMessage& message);
+
~ScheduledMessage();

int32 CountTargets() const;

@@ -48,24 +50,19 @@ private:
bool Merge(DelayedMessage&
message);
uint32 FailureCount() const;

-private:
status_t
_SendMessageToPort(port_id port);

DelayedMessageData* fData;
uint32 fFailureCount;

- friend class DelayedMessageSender;
- friend class DelayedMessage;
- friend class BObjectList<DMScheduledMessage>;
-public:
- bool operator <(const DMScheduledMessage&
other) const;
+ bool operator <(const ScheduledMessage&
other) const;
};


// #pragma mark -


-DMScheduledMessage::DMScheduledMessage(DelayedMessage& message)
+ScheduledMessage::ScheduledMessage(DelayedMessage& message)
:
fData(message.HandOff()),
fFailureCount(0)
@@ -73,14 +70,14 @@ DMScheduledMessage::DMScheduledMessage(DelayedMessage&
message)
}


-DMScheduledMessage::~DMScheduledMessage()
+ScheduledMessage::~ScheduledMessage()
{
delete fData;
}


int32
-DMScheduledMessage::CountTargets() const
+ScheduledMessage::CountTargets() const
{
if (fData == NULL)
return 0;
@@ -90,7 +87,7 @@ DMScheduledMessage::CountTargets() const


bigtime_t
-DMScheduledMessage::ScheduledTime() const
+ScheduledMessage::ScheduledTime() const
{
if (fData == NULL)
return 0;
@@ -101,7 +98,7 @@ DMScheduledMessage::ScheduledTime() const

//! Send our message and data to their intended target(s)
int32
-DMScheduledMessage::SendMessage()
+ScheduledMessage::SendMessage()
{
if (fData == NULL || !fData->IsValid()) {
fFailureCount += 10000;
@@ -132,7 +129,7 @@ DMScheduledMessage::SendMessage()


status_t
-DMScheduledMessage::_SendMessageToPort(port_id port)
+ScheduledMessage::_SendMessageToPort(port_id port)
{
if (fData == NULL || !fData->IsValid())
return B_BAD_DATA;
@@ -169,14 +166,14 @@ DMScheduledMessage::_SendMessageToPort(port_id port)


bool
-DMScheduledMessage::IsValid() const
+ScheduledMessage::IsValid() const
{
return fData != NULL && fData->IsValid();
}


bool
-DMScheduledMessage::Merge(DelayedMessage& other)
+ScheduledMessage::Merge(DelayedMessage& other)
{
if (!IsValid())
return false;
@@ -186,14 +183,14 @@ DMScheduledMessage::Merge(DelayedMessage& other)


uint32
-DMScheduledMessage::FailureCount() const
+ScheduledMessage::FailureCount() const
{
return fFailureCount;
}


bool
-DMScheduledMessage::operator<(const DMScheduledMessage& other) const
+ScheduledMessage::operator<(const ScheduledMessage& other) const
{
if (!IsValid() || !other.IsValid())
return false;
@@ -202,8 +199,14 @@ DMScheduledMessage::operator<(const DMScheduledMessage&
other) const
}


-int CompareMessages(const DMScheduledMessage* one,
- const DMScheduledMessage* two)
+}; // namespace DelayedMessagePrivate
+
+
+using namespace DelayedMessagePrivate;
+
+
+int
+CompareMessages(const ScheduledMessage* one, const ScheduledMessage* two)
{
return *one < *two;
}
@@ -251,7 +254,7 @@ DelayedMessageSender::ScheduleMessage(DelayedMessage&
message)
BAutolock _(fLock);

// Can we merge with a pending message?
- DMScheduledMessage* pending = NULL;
+ ScheduledMessage* pending = NULL;
for (int32 index = 0; index < fMessages.CountItems(); ++index) {
pending = fMessages.ItemAt(index);
if (pending->Merge(message))
@@ -259,7 +262,7 @@ DelayedMessageSender::ScheduleMessage(DelayedMessage&
message)
}

// Guess not, add it to our list!
- DMScheduledMessage* scheduled = new(std::nothrow)
DMScheduledMessage(message);
+ ScheduledMessage* scheduled = new(std::nothrow)
ScheduledMessage(message);

if (scheduled == NULL)
return B_NO_MEMORY;
@@ -303,9 +306,10 @@ DelayedMessageSender::_MessageLoop()
timeout = atomic_get64(&fScheduledWakeup) - (system_time()
+ (DM_MINIMUM_DELAY / 2));

- if (timeout > DM_MINIMUM_DELAY / 4)
- status = read_port_etc(fPort, &code, NULL, 0,
B_TIMEOUT, timeout);
- else
+ if (timeout > DM_MINIMUM_DELAY / 4) {
+ status = read_port_etc(fPort, &code, NULL, 0,
B_RELATIVE_TIMEOUT,
+ timeout);
+ } else
status = B_TIMED_OUT;

if (status == B_INTERRUPTED)
@@ -372,9 +376,9 @@ DelayedMessageSender::_SendDelayedMessages()
bigtime_t time = system_time() + DM_MINIMUM_DELAY / 2;
// capture any that may be on the verge of being sent.

- BObjectList<DMScheduledMessage> remove;
+ BObjectList<ScheduledMessage> remove;

- DMScheduledMessage* message = NULL;
+ ScheduledMessage* message = NULL;
for (int32 index = 0; index < fMessages.CountItems(); ++index) {
message = fMessages.ItemAt(index);

diff --git a/src/servers/app/DelayedMessageSender.h
b/src/servers/app/DelayedMessageSender.h
index 4c027ed..8cb22ac 100644
--- a/src/servers/app/DelayedMessageSender.h
+++ b/src/servers/app/DelayedMessageSender.h
@@ -15,6 +15,12 @@
#include "DelayedMessage.h"


+// Forward declaration.
+namespace DelayedMessagePrivate {
+ class ScheduledMessage;
+};
+
+
/*! \class DelayedMessageSender DelayedMessageSender.h
\brief Responsible for scheduling and sending of delayed messages
*/
@@ -34,8 +40,10 @@ private:
static int32 _thread_func(void* sender);
void _Wakeup(bigtime_t
whatTime);

+private:
+ typedef BObjectList<DelayedMessagePrivate::ScheduledMessage>
ScheduledList;
mutable BLocker fLock;
- BObjectList<DMScheduledMessage> fMessages;
+ ScheduledList fMessages;

bigtime_t fScheduledWakeup;

@@ -47,6 +55,8 @@ private:
mutable int64 fSentCount;
};

+
extern DelayedMessageSender* gDelayedMessageSender;

+
#endif // AS_DELAYED_MESSAGE_SENDER_H

############################################################################

Commit: 73253d815139e3c797eff0f1f57d3c5f312f58dd
Author: looncraz <looncraz@xxxxxxxxxxxx>
Date: Thu Nov 19 03:25:17 2015 UTC

DelayedMessageSender: Don't use an interactive thread shutdown

Per Axel, now using wait_for_thread.

----------------------------------------------------------------------------

diff --git a/src/servers/app/DelayedMessageSender.cpp
b/src/servers/app/DelayedMessageSender.cpp
index 966d9bf..75ab036 100644
--- a/src/servers/app/DelayedMessageSender.cpp
+++ b/src/servers/app/DelayedMessageSender.cpp
@@ -235,12 +235,8 @@ DelayedMessageSender::~DelayedMessageSender()
// write the exit message to our port
write_port(fPort, kExitMessage, NULL, 0);

- // send data to the thread so it knows how to respond
- send_data(fThread, 0, NULL, 0);
-
- // wait for response
- thread_id sender = -1;
- receive_data(&sender, NULL, 0);
+ status_t status = B_OK;
+ while (wait_for_thread(fThread, &status) == B_OK);

// We now know the thread has exited, it is safe to cleanup
delete_port(fPort);
@@ -325,13 +321,8 @@ DelayedMessageSender::_MessageLoop()
case kWakeupMessage:
continue;

- case kExitMessage: {
- thread_id sender = -1;
- code = receive_data(&sender, NULL, 0);
- send_data(sender, 0, NULL, 0);
- gDelayedMessageSender = NULL;
+ case kExitMessage:
return;
- }

// TODO: trace unhandled messages
default:

############################################################################

Commit: 692ed309994f8050d5da0faab344f32906a6af4c
Author: looncraz <looncraz@xxxxxxxxxxxx>
Date: Thu Nov 19 03:48:35 2015 UTC

Remove CHECK_READ and CHECK_WRITE macros.

Per Axel these are not desirable, as such they have been removed.

In addition, write access failures now reliably describe the error, rather than
fInitStatus.

----------------------------------------------------------------------------

diff --git a/src/kits/interface/ColorMap.cpp b/src/kits/interface/ColorMap.cpp
index e8d7a1a..b3883bd 100644
--- a/src/kits/interface/ColorMap.cpp
+++ b/src/kits/interface/ColorMap.cpp
@@ -5,6 +5,8 @@
* Authors:
* Joseph Groover <looncraz@xxxxxxxxxxxx>
*/
+
+
#include <stdio.h>
#include <stdlib.h>

@@ -20,11 +22,6 @@
#include <ServerReadOnlyMemory.h>


-// helpful macros
-#define CHECK_READ_STATUS(X) if (InitCheck() != B_OK) return X ;
-#define CHECK_WRITE_STATUS(X) if (_InitCopyOnWrite() != B_OK) return X ;
-
-
static BLocker be_global_colormap_lock;
static BColorMap* be_default_colormap = NULL;
static BColorMap* be_current_colormap = NULL;
@@ -80,7 +77,8 @@ BColorMap::~BColorMap()
status_t
BColorMap::Archive(BMessage* into, bool deep) const
{
- CHECK_READ_STATUS(fInitStatus);
+ if (InitCheck() != B_OK)
+ return fInitStatus;

if (into == NULL)
return B_BAD_VALUE;
@@ -254,7 +252,10 @@ BColorMap::Add(color_which which, rgb_color color)
status_t
BColorMap::Add(const BString& key, rgb_color color)
{
- CHECK_WRITE_STATUS(fInitStatus);
+ status_t writeStatus = _InitCopyOnWrite();
+ if (writeStatus != B_OK)
+ return writeStatus;
+
BAutolock _(fData);

if (HasColor(key))
@@ -267,7 +268,10 @@ BColorMap::Add(const BString& key, rgb_color color)
status_t
BColorMap::Add(const BColorMap& colorMap)
{
- CHECK_WRITE_STATUS(fInitStatus);
+ status_t writeStatus = _InitCopyOnWrite();
+ if (writeStatus != B_OK)
+ return writeStatus;
+
BAutolock _(fData);

// Technically not an error
@@ -313,7 +317,10 @@ BColorMap::Set(color_which which, rgb_color color)
status_t
BColorMap::Set(const BString& key, rgb_color color)
{
- CHECK_WRITE_STATUS(fInitStatus);
+ status_t writeStatus = _InitCopyOnWrite();
+ if (writeStatus != B_OK)
+ return writeStatus;
+
BAutolock _(fData);

fData->Remove(key);
@@ -324,7 +331,10 @@ BColorMap::Set(const BString& key, rgb_color color)
status_t
BColorMap::Set(const BColorMap& colorMap)
{
- CHECK_WRITE_STATUS(fInitStatus);
+ status_t writeStatus = _InitCopyOnWrite();
+ if (writeStatus != B_OK)
+ return writeStatus;
+
BAutolock _(fData);

// Technically not an error
@@ -372,7 +382,10 @@ BColorMap::Remove(color_which which)
status_t
BColorMap::Remove(const BString& key)
{
- CHECK_WRITE_STATUS(fInitStatus);
+ status_t writeStatus = _InitCopyOnWrite();
+ if (writeStatus != B_OK)
+ return writeStatus;
+
BAutolock _(fData);

if (!HasColor(key))
@@ -386,7 +399,10 @@ BColorMap::Remove(const BString& key)
status_t
BColorMap::Remove(const BColorMap& colorMap)
{
- CHECK_WRITE_STATUS(fInitStatus);
+ status_t writeStatus = _InitCopyOnWrite();
+ if (writeStatus != B_OK)
+ return writeStatus;
+
BAutolock _(fData);

if (colorMap.CountColors() == 0)
@@ -438,7 +454,9 @@ BColorMap::Get(color_which which, rgb_color* color) const
status_t
BColorMap::Get(const BString& key, rgb_color* color) const
{
- CHECK_READ_STATUS(fInitStatus);
+ if (InitCheck() != B_OK)
+ return fInitStatus;
+
BAutolock _(fData);

int32 intColor = 0;
@@ -459,7 +477,9 @@ BColorMap::GetNext(int32* index, BString* key, rgb_color*
color)
if (index == NULL || key == NULL || *index < 0)
return B_BAD_VALUE;

- CHECK_READ_STATUS(fInitStatus);
+ if (InitCheck() != B_OK)
+ return fInitStatus;
+
BAutolock _(fData);

int32 intColor = 0;
@@ -497,7 +517,9 @@ BColorMap::HasColor(color_which which) const
bool
BColorMap::HasColor(const BString& key) const
{
- CHECK_READ_STATUS(false);
+ if (InitCheck() != B_OK)
+ return false;
+
BAutolock _(fData);

int32 color = 0;
@@ -515,7 +537,9 @@ BColorMap::InitCheck() const
int32
BColorMap::CountColors() const
{
- CHECK_READ_STATUS(0);
+ if (InitCheck() != B_OK)
+ return 0;
+
BAutolock _(fData);

return fData->CountNames(B_INT32_TYPE);
@@ -615,9 +639,12 @@ BColorMap::operator=(const BColorMap& other)


status_t
-BColorMap::Set(const BMessage* message)
+BColorMap::_Set(const BMessage* message)
{
- CHECK_WRITE_STATUS(fInitStatus);
+ status_t writeStatus = _InitCopyOnWrite();
+ if (writeStatus != B_OK)
+ return writeStatus;
+
BAutolock _(fData);

int32 count = message->CountNames(B_INT32_TYPE);
@@ -686,12 +713,14 @@ status_t
BColorMap::_InitCopyOnWrite()
{
// If we can't read, we can't copy for writing...
- CHECK_READ_STATUS(fInitStatus);
+ if (InitCheck() != B_OK)
+ return fInitStatus;
+
BAutolock _(fData);

if (fData->IsShared()) {
- BPrivate::BColorMapData* newData = new(std::nothrow) BPrivate
- ::BColorMapData(*fData);
+ BPrivate::BColorMapData* newData
+ = new(std::nothrow) BPrivate::BColorMapData(*fData);

if (newData == NULL)
return B_NO_MEMORY;
@@ -918,7 +947,7 @@ BColorMapPrivate::Update(const BMessage* message)
{
if (be_global_colormap_lock.Lock()) {
if (be_current_colormap != NULL)
- be_current_colormap->Set(message);
+ be_current_colormap->_Set(message);

be_global_colormap_lock.Unlock();
}

############################################################################

Commit: 9a2d4d2914f8524354bd08ad50bd06701f197874
Author: looncraz <looncraz@xxxxxxxxxxxx>
Date: Thu Nov 19 04:06:02 2015 UTC

BColorMap: Use BMessage::SetInt32 instead of RemoveName and AddInt32

Thanks to axel for letting me know this even existed!
The actual computational complexity is probably no different, and the operation
should
be identical.

----------------------------------------------------------------------------

diff --git a/src/kits/interface/ColorMap.cpp b/src/kits/interface/ColorMap.cpp
index b3883bd..9249633 100644
--- a/src/kits/interface/ColorMap.cpp
+++ b/src/kits/interface/ColorMap.cpp
@@ -323,8 +323,7 @@ BColorMap::Set(const BString& key, rgb_color color)

BAutolock _(fData);

- fData->Remove(key);
- return fData->Add(key, color);
+ return fData->Set(key, color);
}


@@ -349,8 +348,7 @@ BColorMap::Set(const BColorMap& colorMap)
if (!colorMap._GetDataAt(index, &key, &color))
return B_BAD_DATA;

- fData->Remove(key);
- error = fData->Add(key, color);
+ error = fData->Set(key, color);

if (error != B_OK)
break;
@@ -659,9 +657,7 @@ BColorMap::_Set(const BMessage* message)
name << which;
key = name.String();
if (message->FindInt32(key, &intColor) == B_OK) {
- fData->Remove(name);
-
- fData->AddInt32(key, intColor);
+ fData->Set(key, intColor);
++count;
}
}
@@ -804,6 +800,20 @@ BColorMapData::Add(const BString& key, int32 color)
}


+status_t
+BColorMapData::Set(const BString& key, rgb_color color)
+{
+ return Set(key, B_BENDIAN_TO_HOST_INT32(*(int32*)&color));
+}
+
+
+status_t
+BColorMapData::Set(const BString& key, int32 color)
+{
+ return SetInt32(key.String(), color);
+}
+
+
void
BColorMapData::Remove(const BString& key)
{

############################################################################

Commit: c299b7c5e960db14f273bc85523bf8444b5bbe53
Author: looncraz <looncraz@xxxxxxxxxxxx>
Date: Thu Nov 19 04:13:38 2015 UTC

Style Cleanup

No functional changes.

----------------------------------------------------------------------------

diff --git a/headers/os/interface/ColorMap.h b/headers/os/interface/ColorMap.h
index e65bcf5..2259c7d 100644
--- a/headers/os/interface/ColorMap.h
+++ b/headers/os/interface/ColorMap.h
@@ -87,7 +87,7 @@ private:
friend class BPrivate::BColorMapPrivate;
typedef BPrivate::BColorMapData* ColorMap;

- status_t Set(const BMessage*
message);
+ status_t _Set(const BMessage*
message);
bool _GetDataAt(int32 index,
BString* key,
int32*
data) const;
void _Init(BMessage* from);
diff --git a/headers/private/interface/ColorMapPrivate.h
b/headers/private/interface/ColorMapPrivate.h
index d1b82ad..29d72e3 100644
--- a/headers/private/interface/ColorMapPrivate.h
+++ b/headers/private/interface/ColorMapPrivate.h
@@ -25,6 +25,9 @@ public:

status_t Add(const BString& key,
rgb_color color);
status_t Add(const BString& key,
int32 color);
+ status_t Set(const BString& key,
rgb_color color);
+ status_t Set(const BString& key,
int32 color);
+
void Remove(const BString&
key);
void RemoveAll();

@@ -44,11 +47,11 @@ private:

//! Data acquisition modes
enum {
- B_CM_SHARE_DATA = 0,// Default - just acquire a reference
+ B_CM_SHARE_DATA = 0, // Default - just acquire a reference
// Copies are made if modifications are made to maps which share
// data.

- B_CM_STEAL_DATA = 1,// Take the data, and reset the colormap
+ B_CM_STEAL_DATA = 1, // Take the data, and reset the colormap
// The given color map will get a new, clean, data object, and
// the caller will take ownership of the acquired data.

@@ -62,7 +65,7 @@ public:
static BColorMapData* AcquireData(BColorMap& colorMap,
int32
count = 1,
uint32
mode = B_CM_SHARE_DATA);
- static void
ReleaseData(BColorMapData* data,
+ static void ReleaseData(BColorMapData* data,
int32
count = 1,
bool
ensureDestruction = false);

diff --git a/src/servers/app/MessageLooper.h b/src/servers/app/MessageLooper.h
index a797006..d9c0271 100644
--- a/src/servers/app/MessageLooper.h
+++ b/src/servers/app/MessageLooper.h
@@ -34,14 +34,16 @@ class MessageLooper : public BLocker {
static status_t WaitForQuit(sem_id semaphore,
bigtime_t timeout =
B_INFINITE_TIMEOUT);

- protected:
+ private:
virtual void _PrepareQuit();
virtual void _GetLooperName(char* name, size_t length);
virtual void _DispatchMessage(int32 code,
BPrivate::LinkReceiver &link);
virtual void _MessageLooper();

+ protected:
static int32 _message_thread(void *_looper);

+ protected:
thread_id fThread;
BPrivate::PortLink fLink;
bool fQuitting;


Other related posts:

  • » [haiku-commits] BRANCH looncraz-github.setviewuicolor [c299b7c5e960] in src: servers/app kits/interface - looncraz-github . setviewuicolor