pEpObjCAdapter/PEPCopyableThread.m
author Dirk Zimmermann <dz@pep.security>
Thu, 12 Sep 2019 16:41:52 +0200
branchIOSAD-141
changeset 1244 d780d1356405
parent 278 08ef7a7ad650
permissions -rw-r--r--
IOSAD-141 Give the threads a name.
     1 //
     2 //  PEPCopyableThread.m
     3 //  pEpObjCAdapter
     4 //
     5 //  Created by Andreas Buff on 06.10.17.
     6 //  Copyright © 2017 p≡p. All rights reserved.
     7 //
     8 
     9 #import "PEPCopyableThread.h"
    10 
    11 @interface PEPCopyableThread()
    12 @property (atomic, strong) NSThread *thread;
    13 @end
    14 
    15 @implementation PEPCopyableThread
    16 
    17 - (BOOL)isFinished
    18 {
    19     return self.thread.isFinished || !self.thread;
    20 }
    21 
    22 - (void)cancel
    23 {
    24     [self.thread cancel];
    25 }
    26 
    27 #pragma mark - Life Cycle
    28 
    29 - (instancetype)init
    30 {
    31     NSAssert(false, @"Please call initWithThread instead");
    32     return nil;
    33 }
    34 
    35 - (instancetype)initWithThread:(NSThread * _Nonnull)thread;
    36 {
    37     self = [super init];
    38     if (self) {
    39         self.thread = thread;
    40     }
    41     return self;
    42 }
    43 
    44 - (void)dealloc
    45 {
    46     self.thread = nil;
    47 }
    48 
    49 #pragma mark - NSObject
    50 
    51 - (BOOL)isEqual:(PEPCopyableThread *)object
    52 {
    53     return [self.thread isEqual:object.thread];
    54 }
    55 
    56 - (NSUInteger)hash
    57 {
    58     return [NSString stringWithFormat:@"%@", self.thread].hash;
    59 }
    60 
    61 - (NSString *)description
    62 {
    63     return [self.thread description];
    64 }
    65 
    66 #pragma mark - NSCopying
    67 
    68 - (instancetype)copyWithZone:(NSZone *)zone
    69 {
    70     PEPCopyableThread *copy = [[PEPCopyableThread alloc] initWithThread:self.thread];
    71     return copy;
    72 }
    73 
    74 @end