Migrate Deprecated OSAtomicIncrement32 function. (#2074)

As per clang output:
`warning: 'OSAtomicIncrement32' is deprecated: first deprecated in macOS 10.12 - Use std::atomic_fetch_add_explicit(std::memory_order_relaxed) from <atomic> instead`
This commit is contained in:
Dzmitry Neviadomski 2021-11-03 09:00:52 +03:00 committed by GitHub
parent 25f68ec815
commit 1bf6189526
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 7 deletions

View File

@ -23,10 +23,11 @@
#import <IOKit/IOMessage.h>
#import <IOKit/pwr_mgt/IOPMLib.h>
#import <Carbon/Carbon.h>
#import <libkern/OSAtomic.h>
#import <Sparkle/Sparkle.h>
#include <atomic> /* atomic, atomic_fetch_add_explicit, memory_order_relaxed */
#include <libtransmission/transmission.h>
#include <libtransmission/utils.h>
#include <libtransmission/variant.h>
@ -2673,7 +2674,6 @@ static void removeKeRangerRansomware()
- (void)applyFilter
{
__block int32_t active = 0, downloading = 0, seeding = 0, paused = 0;
NSString* filterType = [fDefaults stringForKey:@"Filter"];
BOOL filterActive = NO, filterDownload = NO, filterSeed = NO, filterPause = NO, filterStatus = YES;
if ([filterType isEqualToString:FILTER_ACTIVE])
@ -2707,6 +2707,12 @@ static void removeKeRangerRansomware()
}
BOOL const filterTracker = searchStrings && [[fDefaults stringForKey:@"FilterSearchType"] isEqualToString:FILTER_TYPE_TRACKER];
std::atomic<int32_t> active{0}, downloading{0}, seeding{0}, paused{0};
// Pointers to be captured by Obj-C Block as const*
auto* activeRef = &active;
auto* downloadingRef = &downloading;
auto* seedingRef = &seeding;
auto* pausedRef = &paused;
//filter & get counts of each type
NSIndexSet* indexesOfNonFilteredTorrents = [fTorrents
indexesOfObjectsWithOptions:NSEnumerationConcurrent passingTest:^BOOL(Torrent* torrent, NSUInteger idx, BOOL* stop) {
@ -2716,12 +2722,12 @@ static void removeKeRangerRansomware()
BOOL const isActive = !torrent.stalled;
if (isActive)
{
OSAtomicIncrement32(&active);
std::atomic_fetch_add_explicit(activeRef, 1, std::memory_order_relaxed);
}
if (torrent.seeding)
{
OSAtomicIncrement32(&seeding);
std::atomic_fetch_add_explicit(seedingRef, 1, std::memory_order_relaxed);
if (filterStatus && !((filterActive && isActive) || filterSeed))
{
return NO;
@ -2729,7 +2735,7 @@ static void removeKeRangerRansomware()
}
else
{
OSAtomicIncrement32(&downloading);
std::atomic_fetch_add_explicit(downloadingRef, 1, std::memory_order_relaxed);
if (filterStatus && !((filterActive && isActive) || filterDownload))
{
return NO;
@ -2738,7 +2744,7 @@ static void removeKeRangerRansomware()
}
else
{
OSAtomicIncrement32(&paused);
std::atomic_fetch_add_explicit(pausedRef, 1, std::memory_order_relaxed);
if (filterStatus && !filterPause)
{
return NO;
@ -2804,7 +2810,11 @@ static void removeKeRangerRansomware()
//set button tooltips
if (fFilterBar)
{
[fFilterBar setCountAll:fTorrents.count active:active downloading:downloading seeding:seeding paused:paused];
[fFilterBar setCountAll:fTorrents.count
active:active.load()
downloading:downloading.load()
seeding:seeding.load()
paused:paused.load()];
}
//if either the previous or current lists are blank, set its value to the other