This will cause NPEs. Please don't sync on an object which you believe
may be null!
On Tue, Jul 11, 2006 at 11:45:18AM +0000, nextgens at freenetproject.org wrote:
> Author: nextgens
> Date: 2006-07-11 11:45:16 +0000 (Tue, 11 Jul 2006)
> New Revision: 9557
>
> Modified:
> trunk/freenet/src/freenet/node/Node.java
> trunk/freenet/src/freenet/node/PeerNode.java
> Log:
> Small locking tweakings
>
> Modified: trunk/freenet/src/freenet/node/Node.java
> ===================================================================
> --- trunk/freenet/src/freenet/node/Node.java 2006-07-11 08:59:43 UTC (rev
> 9556)
> +++ trunk/freenet/src/freenet/node/Node.java 2006-07-11 11:45:16 UTC (rev
> 9557)
> @@ -166,21 +166,25 @@
> Logger.minor(this, "update()");
> if(!checkIPUpdated()) return;
> Logger.minor(this, "Inserting ARK because peers list
> changed");
> - synchronized(this) {
> + synchronized (inserter) {
> if(inserter != null) {
> // Already inserting.
> // Re-insert after finished.
> - shouldInsert = true;
> + synchronized(this) {
> + shouldInsert = true;
> + }
> return;
> }
> // Otherwise need to start an insert
> if(!peers.anyConnectedPeers()) {
> // Can't start an insert yet
> - shouldInsert = true;
> + synchronized (this) {
> + shouldInsert = true;
> + }
> return;
> - }
> - startInserter();
> + }
> }
> + startInserter();
> }
>
> private boolean checkIPUpdated() {
> @@ -228,14 +232,19 @@
>
> Logger.minor(this, "Inserting ARK: "+uri);
>
> - synchronized (this) {
> + synchronized (inserter) {
> inserter = new ClientPutter(this, b, uri,
> new
> ClientMetadata("text/plain") /* it won't quite fit in an SSK anyway */,
>
> Node.this.makeClient((short)0).getInserterContext(),
> chkPutScheduler,
> sskPutScheduler, RequestStarter.INTERACTIVE_PRIORITY_CLASS, false, false,
> this);
> -
> - try {
> - inserter.start();
> + }
> +
> + try {
> + synchronized (inserter) {
> + inserter.start();
> + }
> +
> + synchronized (this) {
> if(fs.get("physical.udp") == null)
> lastInsertedPeers = null;
> else {
> @@ -251,9 +260,11 @@
> Logger.error(this,
> "Error parsing own ref: "+e1+" : "+fs.get("physical.udp"), e1);
> }
> }
> - } catch (InserterException e) {
> - onFailure(e, inserter);
> }
> + } catch (InserterException e) {
> + synchronized (inserter) {
> + onFailure(e, inserter);
> + }
> }
> }
>
> @@ -267,12 +278,19 @@
>
> public void onSuccess(BaseClientPutter state) {
> Logger.minor(this, "ARK insert succeeded");
> - synchronized(this) {
> + synchronized(inserter) {
> inserter = null;
> - if(shouldInsert) {
> - shouldInsert = false;
> + boolean myShouldInsert;
> + synchronized (this) {
> + myShouldInsert = shouldInsert;
> + }
> + if(myShouldInsert) {
> + myShouldInsert = false;
> startInserter();
> }
> + synchronized (this){
> + shouldInsert = myShouldInsert;
> + }
> }
> }
>
> @@ -288,9 +306,8 @@
> } catch (InterruptedException e1) {
> // Ignore
> }
> - synchronized(this) {
> - startInserter();
> - }
> +
> + startInserter();
> }
>
> public void onGeneratedURI(FreenetURI uri, BaseClientPutter
> state) {
> @@ -307,21 +324,26 @@
>
> public void onConnectedPeer() {
> if(!checkIPUpdated()) return;
> - synchronized(this) {
> - if(!shouldInsert) return;
> - if(inserter != null) {
> - // Already inserting.
> - return;
> + synchronized(inserter) {
> + synchronized (this) {
> + if(!shouldInsert) return;
> }
> + // Already inserting.
> + if(inserter != null) return;
> +
> // Otherwise need to start an insert
> if(!peers.anyConnectedPeers()) {
> // Can't start an insert yet
> - shouldInsert = true;
> + synchronized (this) {
> + shouldInsert = true;
> + }
> return;
> }
> - shouldInsert = false;
> - startInserter();
> + synchronized (this) {
> + shouldInsert = false;
> + }
> }
> + startInserter();
> }
>
> }
>
> Modified: trunk/freenet/src/freenet/node/PeerNode.java
> ===================================================================
> --- trunk/freenet/src/freenet/node/PeerNode.java 2006-07-11 08:59:43 UTC
> (rev 9556)
> +++ trunk/freenet/src/freenet/node/PeerNode.java 2006-07-11 11:45:16 UTC
> (rev 9557)
> @@ -1551,9 +1551,11 @@
> fs.put("version", version);
> fs.put("myName", myName);
> if(myARK != null) {
> - // Decrement it because we keep the number we would like to
> fetch, not the last one fetched.
> - fs.put("ark.number", Long.toString(myARK.suggestedEdition-1));
> - fs.put("ark.pubURI", myARK.getBaseSSK().toString(false));
> + synchronized (this) {
> + // Decrement it because we keep the number we would like to
> fetch, not the last one fetched.
> + fs.put("ark.number", Long.toString(myARK.suggestedEdition-1));
> + fs.put("ark.pubURI", myARK.getBaseSSK().toString(false));
>
> + }
> }
> return fs;
> }
>
> _______________________________________________
> cvs mailing list
> cvs at freenetproject.org
> http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs
>
--
Matthew J Toseland - toad at amphibian.dyndns.org
Freenet Project Official Codemonkey - http://freenetproject.org/
ICTHUS - Nothing is impossible. Our Boss says so.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL:
<https://emu.freenetproject.org/pipermail/cvs/attachments/20060711/65738bd2/attachment.pgp>