In case you might want to reuse this code...
On Friday 17 April 2009 18:12:49 nextgens at freenetproject.org wrote:
> Author: nextgens
> Date: 2009-04-17 17:12:49 +0000 (Fri, 17 Apr 2009)
> New Revision: 26946
>
> Modified:
> branches/nextgens-stuffs/freenet/src/freenet/io/comm/MessageCore.java
> Log:
> Reduce locking on MessageCore.
>
> Needs to be tested ^-^
>
> Modified:
branches/nextgens-stuffs/freenet/src/freenet/io/comm/MessageCore.java
> ===================================================================
> --- branches/nextgens-stuffs/freenet/src/freenet/io/comm/MessageCore.java
2009-04-17 16:58:16 UTC (rev 26945)
> +++ branches/nextgens-stuffs/freenet/src/freenet/io/comm/MessageCore.java
2009-04-17 17:12:49 UTC (rev 26946)
...
> @@ -115,14 +121,21 @@
> // Avoids exhaustive and unsuccessful search in waitFor()
> removal of a
timed out filter.
> if(logMINOR)
> Logger.minor(this, "Removing timed out filters");
> - synchronized (_filters) {
> +
> + try {
> + messageFiltersWriteLock.lock();
> for(LinkedList<MessageFilter> mfl : _filters.values()) {
> for (ListIterator<MessageFilter> i =
> mfl.listIterator(); i.hasNext();)
{
> MessageFilter f = i.next();
> if (f.timedOut(tStart)) {
> if(logMINOR)
> Logger.minor(this,
> "Removing "+f);
> - i.remove();
> + try {
> +
> messageFiltersWriteLock.lock();
You seem to be taking the same lock twice here. Presumably you meant to take
the ReadLock?
...
> @@ -245,7 +279,14 @@
> }
> if(!matched) {
> while (_unclaimed.size() >
> MAX_UNMATCHED_FIFO_SIZE) {
> - Message removed =
> _unclaimed.removeFirst();
> + Message removed = null;
> + try {
> +
> messageFiltersWriteLock.lock();
> +
> _unclaimed.removeFirst();
> + } finally {
> +
> messageFiltersWriteLock.unlock();
> + }
> + if(removed == null) continue;
removed is never set.
...
> @@ -500,11 +582,14 @@
> if(!filter.matched()) {
> // We must remove it from _filters before we return, or
> when it is
re-added,
> // it will be in the list twice, and potentially many
> more times than
twice!
> - synchronized(_filters) {
> + try {
> // Fortunately, it will be close to the
> beginning of the filters list,
having
> // just timed out. That is assuming it hasn't
> already been removed; in
that
> // case, this will be slower.
> + messageFiltersWriteLock.lock();
> _filters.remove(filter);
This can't work, why is it not a compile error? You're removing a
MessageFilter from a TreeSet of LinkedList<MessageFilter> !
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 835 bytes
Desc: This is a digitally signed message part.
URL:
<https://emu.freenetproject.org/pipermail/devl/attachments/20090430/87e7dc5a/attachment.pgp>