Skip to content

Commit

Permalink
Attempt to fix outstanding dead operations
Browse files Browse the repository at this point in the history
  • Loading branch information
parg committed Sep 28, 2023
1 parent 8e234de commit dbec3b5
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 6 deletions.
27 changes: 27 additions & 0 deletions core/src/com/biglybt/core/CoreOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

package com.biglybt.core;

import java.util.concurrent.atomic.AtomicBoolean;

public interface
CoreOperation
{
Expand All @@ -36,4 +38,29 @@

public CoreOperationTask
getTask();

public boolean
isRemoved();

public void
setRemoved();

public static abstract class
CoreOperationAdapter
implements CoreOperation
{
private AtomicBoolean removed = new AtomicBoolean();

public boolean
isRemoved()
{
return( removed.get());
}

public void
setRemoved()
{
removed.set( true );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@
};

operation =
new CoreOperation()
new CoreOperation.CoreOperationAdapter()
{
public int
getOperationType()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@
};

op =
new CoreOperation()
new CoreOperation.CoreOperationAdapter()
{
public int
getOperationType()
Expand Down
23 changes: 20 additions & 3 deletions core/src/com/biglybt/core/impl/CoreImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -3226,7 +3226,7 @@ public void runSupport(){
CoreOperationTask task )
{
CoreOperation op =
new CoreOperation()
new CoreOperation.CoreOperationAdapter()
{
@Override
public int
Expand Down Expand Up @@ -3281,7 +3281,15 @@ public void runSupport(){
addOperation(
CoreOperation op )
{
operations.add( op );
synchronized( operations ){

if ( op.isRemoved()){

return;
}

operations.add( op );
}

for ( CoreOperationListener l: operation_listeners ){

Expand All @@ -3300,7 +3308,16 @@ public void runSupport(){
removeOperation(
CoreOperation op )
{
if ( operations.remove( op )){
boolean was_added;

synchronized( operations ){

was_added = operations.remove( op );

op.setRemoved();
}

if ( was_added ){

for ( CoreOperationListener l: operation_listeners ){

Expand Down
19 changes: 18 additions & 1 deletion uis/src/com/biglybt/ui/swt/progress/ProgressWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@

for ( CoreOperation op: ops ){

if ( op.isRemoved()){

continue;
}

int type = op.getOperationType();

if ( type == CoreOperation.OP_DOWNLOAD_CHECKING ||
Expand All @@ -85,9 +90,21 @@
type == CoreOperation.OP_FILE_MOVE ){

CoreOperationTask task = op.getTask();

if ( task != null ){

ProgressCallback cb = task.getProgressCallback();

if ( cb != null ){

int state = cb.getTaskState();

if ( state == ProgressCallback.ST_CANCEL ){

continue;
}
}

if ( active.length() > 128 ){

active += ", ...";
Expand Down

0 comments on commit dbec3b5

Please sign in to comment.