GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - lyandy/AndyGCD: AndyGCD aimed to make C GCD easier and simpler to use. Include dispatchQueue、delay、group、timer、semaphore、apply、barrier

BranchesTags
Open more actions menu

Latest commit

 

History

20 Commits
20 Commits

Folders and files

NameName
Last commit message
Last commit date
AndyGCD
AndyGCD
 
 
AndyGCD_Test.xcodeproj
AndyGCD_Test.xcodeproj
 
 
AndyGCD_Test
AndyGCD_Test
 
 
AndyGCD_TestTests
AndyGCD_TestTests
 
 
AndyGCD_TestUITests
AndyGCD_TestUITests
 
 
.gitignore
.gitignore
 
 
AndyGCD.podspec
AndyGCD.podspec
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 

Repository files navigation

AndyGCD

AndyGCD aimed to make C GCD easier and simpler to use. Include dispatchQueue、delay、group、timer、semaphore、apply、barrier.

Use in pod: pod 'AndyGCD'


dispatchQueue

[AndyGCDQueue executeInGlobalQueue:^{

    NSLog(@"---%@", [NSThread currentThread]);

    [AndyGCDQueue executeInMainQueue:^{

        NSLog(@"---%@", [NSThread currentThread]);
    }];
}];


delay


[AndyGCDQueue executeInGlobalQueue:^{

    NSLog(@"---%@", [NSThread currentThread]);

    [AndyGCDQueue executeInMainQueue:^{

        NSLog(@"---%@", [NSThread currentThread]);
    } afterDelaySecs:3];
} afterDelaySecs:3];


group


AndyGCDGroup *group = [[AndyGCDGroup alloc] init];

[[AndyGCDQueue globalQueue] execute:^{

    NSLog(@"---%@", [NSThread currentThread]);
} inGroup:group];

[[AndyGCDQueue globalQueue] execute:^{

    NSLog(@"---%@", [NSThread currentThread]);
} inGroup:group];

[[AndyGCDQueue mainQueue] notify:^{

    NSLog(@"---%@", [NSThread currentThread]);
} inGroup:group];


timer


self.timer = [[AndyGCDTimer alloc] initInQueue:[AndyGCDQueue mainQueue]];

[self.timer timerExecute:^{

    NSLog(@"---%@", [NSThread currentThread]);
} timeInterval:NSEC_PER_SEC * 3 delay:NSEC_PER_SEC * 3];

[self.timer resume];



semaphore


AndyGCDSemaphore *semaphore = [[AndyGCDSemaphore alloc] init];

[AndyGCDQueue executeInGlobalQueue:^{

    NSLog(@"---%@", [NSThread currentThread]);
    [semaphore wait];
}];

[AndyGCDQueue executeInGlobalQueue:^{

    NSLog(@"---%@", [NSThread currentThread]);
    [semaphore signal];
}];


apply


NSString *from = @"/Users/liyang/Desktop/From";
NSString *to = @"/Users/liyang/Desktop/To";

NSFileManager *mgr = [NSFileManager defaultManager];
NSArray *subpaths = [mgr subpathsAtPath:from];

[[AndyGCDQueue globalQueue] applyExecute:subpaths.count block:^(size_t index) {
    NSString *subpath = subpaths[index];
    NSString *fromFullpath = [from stringByAppendingPathComponent:subpath];
    NSString *toFullpath = [to stringByAppendingPathComponent:subpath];
    // cut
    [mgr moveItemAtPath:fromFullpath toPath:toFullpath error:nil];

    NSLog(@"%@---%@", [NSThread currentThread], subpath);
}];


barrier

注意使用全局并发队列 dispatch_get_global_queue(<#long identifier#>, <#unsigned long flags#>)是不行的,即不可以使用[AndyGCDQueue globalQueue]全局队列, 效果等同于 dispatch_async. 只能使用自己创建的 dispatch_async_create 并队列,即 [[AndyGCDQueue alloc] initConcurrent]


AndyGCDQueue *concurrentQueue = [[AndyGCDQueue alloc] initConcurrent];
[concurrentQueue execute:^{
    NSLog(@"----1-----%@", [NSThread currentThread]);
}];

[concurrentQueue execute:^{
    NSLog(@"----2-----%@", [NSThread currentThread]);
}];

[concurrentQueue barrierExecute:^{
    NSLog(@"----barrier-----%@", [NSThread currentThread]);
}];

[concurrentQueue execute:^{
    NSLog(@"----3-----%@", [NSThread currentThread]);
}];

[concurrentQueue execute:^{
    NSLog(@"----4-----%@", [NSThread currentThread]);
}];


QOS DispatchContextQueue

AndyGCDQueue *contextQueue = [[AndyGCDQueue alloc] initWithQOS:NSQualityOfServiceUtility queueCount:5];
for (int i = 0; i < 100; i++) {
    [contextQueue execute:^{

        NSLog(@"=====> %@", [NSThread currentThread]);
    }];

    [contextQueue execute:^{

        NSLog(@"=====> %@", [NSThread currentThread]);
    }];

    [contextQueue execute:^{

        NSLog(@"=====> %@", [NSThread currentThread]);
    }];
}


AndyLifeFreedomThread

AndyLifeFreedomThread *lifeFreedomThread = [[AndyLifeFreedomThread alloc] init];
    [lifeFreedomThread asyncExecuteBlock:^{
        NSLog(@"-----%@", [NSThread currentThread]);
    }];

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [lifeFreedomThread syncExecuteBlock:^{
            NSLog(@"block-----%@", [NSThread currentThread]);
        }];

        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [lifeFreedomThread stop];
        });
    });


AndySafeThread

[[AndySafeThread sharedSafeThread] syncExecuteBlock:^{
        NSLog(@"111-----%@", [NSThread currentThread]);
        [[AndySafeThread sharedSafeThread] syncExecuteBlock:^{
            NSLog(@"222-----%@", [NSThread currentThread]);
            [[AndySafeThread sharedSafeThread] asyncExecuteBlock:^{
                NSLog(@"333-----%@", [NSThread currentThread]);

            }];
            [[AndySafeThread sharedSafeThread] syncExecuteBlock:^{
                NSLog(@"444-----%@", [NSThread currentThread]);

            }];
        }];
    }];

如果想自定义 SafeThread 用于处理自己的任务,可以继承自 AndySafeThread ,并重写 +[AndySafeThread sharedSafeThread] 方法即可


About

AndyGCD aimed to make C GCD easier and simpler to use. Include dispatchQueue、delay、group、timer、semaphore、apply、barrier

Resources

Readme
MIT license
Activity

Stars

6 stars

Watchers

1 watching

Forks

2 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.