forked from wujunyang/MobileProject
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
690 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// GCD.h | ||
// GCD | ||
// | ||
// 用法 | ||
// http://www.cnblogs.com/YouXianMing/p/3659204.html | ||
// | ||
// Created by XianMingYou on 15/3/15. | ||
// Copyright (c) 2015年 XianMingYou. All rights reserved. | ||
// | ||
|
||
#import "GCDQueue.h" | ||
#import "GCDGroup.h" | ||
#import "GCDSemaphore.h" | ||
#import "GCDTimer.h" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// GCDGroup.h | ||
// GCD | ||
// 用法 | ||
// http://www.cnblogs.com/YouXianMing/p/3659204.html | ||
// | ||
// Created by XianMingYou on 15/3/15. | ||
// Copyright (c) 2015年 XianMingYou. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@interface GCDGroup : NSObject | ||
|
||
@property (strong, nonatomic, readonly) dispatch_group_t dispatchGroup; | ||
|
||
#pragma 初始化 | ||
- (instancetype)init; | ||
|
||
#pragma mark - 用法 | ||
- (void)enter; | ||
- (void)leave; | ||
- (void)wait; | ||
- (BOOL)wait:(int64_t)delta; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// | ||
// GCDGroup.m | ||
// GCD | ||
// | ||
// http://home.cnblogs.com/u/YouXianMing/ | ||
// https://github.com/YouXianMing | ||
// | ||
// Created by XianMingYou on 15/3/15. | ||
// Copyright (c) 2015年 XianMingYou. All rights reserved. | ||
// | ||
|
||
#import "GCDGroup.h" | ||
|
||
@interface GCDGroup () | ||
|
||
@property (strong, nonatomic, readwrite) dispatch_group_t dispatchGroup; | ||
|
||
@end | ||
|
||
@implementation GCDGroup | ||
|
||
- (instancetype)init { | ||
|
||
self = [super init]; | ||
|
||
if (self) { | ||
|
||
self.dispatchGroup = dispatch_group_create(); | ||
} | ||
|
||
return self; | ||
} | ||
|
||
- (void)enter { | ||
|
||
dispatch_group_enter(self.dispatchGroup); | ||
} | ||
|
||
- (void)leave { | ||
|
||
dispatch_group_leave(self.dispatchGroup); | ||
} | ||
|
||
- (void)wait { | ||
|
||
dispatch_group_wait(self.dispatchGroup, DISPATCH_TIME_FOREVER); | ||
} | ||
|
||
- (BOOL)wait:(int64_t)delta { | ||
|
||
return dispatch_group_wait(self.dispatchGroup, dispatch_time(DISPATCH_TIME_NOW, delta)) == 0; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// | ||
// GCDQueue.h | ||
// GCD | ||
// | ||
// 用法 | ||
// http://www.cnblogs.com/YouXianMing/p/3659204.html | ||
// | ||
// Created by XianMingYou on 15/3/15. | ||
// Copyright (c) 2015年 XianMingYou. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@class GCDGroup; | ||
|
||
@interface GCDQueue : NSObject | ||
|
||
@property (strong, readonly, nonatomic) dispatch_queue_t dispatchQueue; | ||
|
||
+ (GCDQueue *)mainQueue; | ||
+ (GCDQueue *)globalQueue; | ||
+ (GCDQueue *)highPriorityGlobalQueue; | ||
+ (GCDQueue *)lowPriorityGlobalQueue; | ||
+ (GCDQueue *)backgroundPriorityGlobalQueue; | ||
|
||
#pragma mark - 便利的构造方法 | ||
+ (void)executeInMainQueue:(dispatch_block_t)block; | ||
+ (void)executeInGlobalQueue:(dispatch_block_t)block; | ||
+ (void)executeInHighPriorityGlobalQueue:(dispatch_block_t)block; | ||
+ (void)executeInLowPriorityGlobalQueue:(dispatch_block_t)block; | ||
+ (void)executeInBackgroundPriorityGlobalQueue:(dispatch_block_t)block; | ||
+ (void)executeInMainQueue:(dispatch_block_t)block afterDelaySecs:(NSTimeInterval)sec; | ||
+ (void)executeInGlobalQueue:(dispatch_block_t)block afterDelaySecs:(NSTimeInterval)sec; | ||
+ (void)executeInHighPriorityGlobalQueue:(dispatch_block_t)block afterDelaySecs:(NSTimeInterval)sec; | ||
+ (void)executeInLowPriorityGlobalQueue:(dispatch_block_t)block afterDelaySecs:(NSTimeInterval)sec; | ||
+ (void)executeInBackgroundPriorityGlobalQueue:(dispatch_block_t)block afterDelaySecs:(NSTimeInterval)sec; | ||
|
||
#pragma 初始化 | ||
- (instancetype)init; | ||
- (instancetype)initSerial; | ||
- (instancetype)initSerialWithLabel:(NSString *)label; | ||
- (instancetype)initConcurrent; | ||
- (instancetype)initConcurrentWithLabel:(NSString *)label; | ||
|
||
#pragma mark - 用法 | ||
- (void)execute:(dispatch_block_t)block; | ||
- (void)execute:(dispatch_block_t)block afterDelay:(int64_t)delta; | ||
- (void)execute:(dispatch_block_t)block afterDelaySecs:(float)delta; | ||
- (void)waitExecute:(dispatch_block_t)block; | ||
- (void)barrierExecute:(dispatch_block_t)block; | ||
- (void)waitBarrierExecute:(dispatch_block_t)block; | ||
- (void)suspend; | ||
- (void)resume; | ||
|
||
#pragma mark - 与GCDGroup相关 | ||
- (void)execute:(dispatch_block_t)block inGroup:(GCDGroup *)group; | ||
- (void)notify:(dispatch_block_t)block inGroup:(GCDGroup *)group; | ||
|
||
@end |
Oops, something went wrong.