mirror of
https://github.com/GLEGram/GLEGram-iOS.git
synced 2026-04-24 03:46:23 +02:00
4647310322
Based on Swiftgram 12.5 (Telegram iOS 12.5). All GLEGram features ported and organized in GLEGram/ folder. Features: Ghost Mode, Saved Deleted Messages, Content Protection Bypass, Font Replacement, Fake Profile, Chat Export, Plugin System, and more. See CHANGELOG_12.5.md for full details.
59 lines
1.0 KiB
Objective-C
59 lines
1.0 KiB
Objective-C
#import "SBlockDisposable.h"
|
|
|
|
#import <libkern/OSAtomic.h>
|
|
#import <objc/runtime.h>
|
|
|
|
@interface SBlockDisposable ()
|
|
{
|
|
void *_block;
|
|
}
|
|
|
|
@end
|
|
|
|
@implementation SBlockDisposable
|
|
|
|
- (instancetype)initWithBlock:(void (^)())block
|
|
{
|
|
self = [super init];
|
|
if (self != nil)
|
|
{
|
|
_block = (__bridge_retained void *)[block copy];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (void)dealloc
|
|
{
|
|
void *block = _block;
|
|
if (block != NULL)
|
|
{
|
|
if (OSAtomicCompareAndSwapPtr(block, 0, &_block))
|
|
{
|
|
if (block != nil)
|
|
{
|
|
__strong id strongBlock = (__bridge_transfer id)block;
|
|
strongBlock = nil;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
- (void)dispose
|
|
{
|
|
void *block = _block;
|
|
if (block != NULL)
|
|
{
|
|
if (OSAtomicCompareAndSwapPtr(block, 0, &_block))
|
|
{
|
|
if (block != nil)
|
|
{
|
|
__strong id strongBlock = (__bridge_transfer id)block;
|
|
((dispatch_block_t)strongBlock)();
|
|
strongBlock = nil;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@end
|