Skip to content

Commit

Permalink
Fix concurrent access bug
Browse files Browse the repository at this point in the history
  • Loading branch information
parg committed Nov 20, 2024
1 parent dd6177f commit ab477be
Showing 1 changed file with 28 additions and 32 deletions.
60 changes: 28 additions & 32 deletions core/src/com/biglybt/core/content/PlatformContentDirectory.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@

package com.biglybt.core.content;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import com.biglybt.core.tag.*;
import com.biglybt.core.util.CopyOnWriteList;
Expand Down Expand Up @@ -160,7 +158,7 @@ public PlatformContentDirectory() {
{
private final Download download;

private final Map<Integer, ContentFile> cfs = new HashMap<>();
private final Map<Integer, ContentFile> cfs = new ConcurrentHashMap<>();

private
ContentFileHandler(
Expand All @@ -178,7 +176,7 @@ public PlatformContentDirectory() {
TorrentAttribute attribute,
int eventType )
{
fireCatsChanged( cfs.values());
fireCatsChanged();
}
},
ta_category,
Expand Down Expand Up @@ -217,7 +215,7 @@ public PlatformContentDirectory() {
update(
Taggable tagged )
{
fireTagsChanged( cfs.values());
fireTagsChanged();
}
});
}
Expand Down Expand Up @@ -315,6 +313,30 @@ public PlatformContentDirectory() {

return( acf );
}

private void
fireCatsChanged()
{
for ( ContentDirectoryListener l: listeners ){

for ( ContentFile cf: cfs.values()){

l.contentChanged( cf, ContentFile.PT_CATEGORIES );
}
}
}

private void
fireTagsChanged()
{
for ( ContentDirectoryListener l: listeners ){

for ( ContentFile cf: cfs.values()){

l.contentChanged( cf, ContentFile.PT_TAGS );
}
}
}
}


Expand Down Expand Up @@ -349,32 +371,6 @@ public PlatformContentDirectory() {
}
}

private static void
fireCatsChanged(
Collection<ContentFile> cfs )
{
for ( ContentDirectoryListener l: listeners ){

for ( ContentFile cf: cfs ){

l.contentChanged( cf, ContentFile.PT_CATEGORIES );
}
}
}

private static void
fireTagsChanged(
Collection<ContentFile> cfs )
{
for ( ContentDirectoryListener l: listeners ){

for ( ContentFile cf: cfs ){

l.contentChanged( cf, ContentFile.PT_TAGS );
}
}
}

public static void
fireCatsChanged(
ContentFile cf )
Expand Down

0 comments on commit ab477be

Please sign in to comment.