├── GCD.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ ├── xcshareddata │ │ └── IDEWorkspaceChecks.plist │ └── xcuserdata │ │ └── YouXianMing.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ ├── YouXianMing.xcuserdatad │ ├── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ │ ├── GCD.xcscheme │ │ └── xcschememanagement.plist │ └── YouXianMing1987@iCloud.com.xcuserdatad │ └── xcschemes │ └── GCD.xcscheme ├── GCD ├── AppDelegate.h ├── AppDelegate.m ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── GCD │ ├── GCD.h │ ├── GCDGroup.h │ ├── GCDGroup.m │ ├── GCDQueue.h │ ├── GCDQueue.m │ ├── GCDSemaphore.h │ ├── GCDSemaphore.m │ ├── GCDTimer.h │ └── GCDTimer.m ├── Info.plist ├── ViewController.h ├── ViewController.m └── main.m └── README.md /GCD.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 10EC02D91BD4769900973DD9 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 10EC02D81BD4769900973DD9 /* main.m */; }; 11 | 10EC02DC1BD4769900973DD9 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 10EC02DB1BD4769900973DD9 /* AppDelegate.m */; }; 12 | 10EC02DF1BD4769900973DD9 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 10EC02DE1BD4769900973DD9 /* ViewController.m */; }; 13 | 10EC02E21BD4769900973DD9 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 10EC02E01BD4769900973DD9 /* Main.storyboard */; }; 14 | 10EC02E41BD4769900973DD9 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 10EC02E31BD4769900973DD9 /* Assets.xcassets */; }; 15 | 10EC02E71BD4769900973DD9 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 10EC02E51BD4769900973DD9 /* LaunchScreen.storyboard */; }; 16 | 10EC03141BD476CC00973DD9 /* GCDGroup.m in Sources */ = {isa = PBXBuildFile; fileRef = 10EC030D1BD476CC00973DD9 /* GCDGroup.m */; }; 17 | 10EC03151BD476CC00973DD9 /* GCDQueue.m in Sources */ = {isa = PBXBuildFile; fileRef = 10EC030F1BD476CC00973DD9 /* GCDQueue.m */; }; 18 | 10EC03161BD476CC00973DD9 /* GCDSemaphore.m in Sources */ = {isa = PBXBuildFile; fileRef = 10EC03111BD476CC00973DD9 /* GCDSemaphore.m */; }; 19 | 10EC03171BD476CC00973DD9 /* GCDTimer.m in Sources */ = {isa = PBXBuildFile; fileRef = 10EC03131BD476CC00973DD9 /* GCDTimer.m */; }; 20 | /* End PBXBuildFile section */ 21 | 22 | /* Begin PBXFileReference section */ 23 | 10EC02D41BD4769900973DD9 /* GCD.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = GCD.app; sourceTree = BUILT_PRODUCTS_DIR; }; 24 | 10EC02D81BD4769900973DD9 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 25 | 10EC02DA1BD4769900973DD9 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 26 | 10EC02DB1BD4769900973DD9 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 27 | 10EC02DD1BD4769900973DD9 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 28 | 10EC02DE1BD4769900973DD9 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 29 | 10EC02E11BD4769900973DD9 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 30 | 10EC02E31BD4769900973DD9 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 31 | 10EC02E61BD4769900973DD9 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 32 | 10EC02E81BD4769900973DD9 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 33 | 10EC030B1BD476CC00973DD9 /* GCD.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GCD.h; sourceTree = ""; }; 34 | 10EC030C1BD476CC00973DD9 /* GCDGroup.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GCDGroup.h; sourceTree = ""; }; 35 | 10EC030D1BD476CC00973DD9 /* GCDGroup.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GCDGroup.m; sourceTree = ""; }; 36 | 10EC030E1BD476CC00973DD9 /* GCDQueue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GCDQueue.h; sourceTree = ""; }; 37 | 10EC030F1BD476CC00973DD9 /* GCDQueue.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GCDQueue.m; sourceTree = ""; }; 38 | 10EC03101BD476CC00973DD9 /* GCDSemaphore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GCDSemaphore.h; sourceTree = ""; }; 39 | 10EC03111BD476CC00973DD9 /* GCDSemaphore.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GCDSemaphore.m; sourceTree = ""; }; 40 | 10EC03121BD476CC00973DD9 /* GCDTimer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GCDTimer.h; sourceTree = ""; }; 41 | 10EC03131BD476CC00973DD9 /* GCDTimer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GCDTimer.m; sourceTree = ""; }; 42 | /* End PBXFileReference section */ 43 | 44 | /* Begin PBXFrameworksBuildPhase section */ 45 | 10EC02D11BD4769900973DD9 /* Frameworks */ = { 46 | isa = PBXFrameworksBuildPhase; 47 | buildActionMask = 2147483647; 48 | files = ( 49 | ); 50 | runOnlyForDeploymentPostprocessing = 0; 51 | }; 52 | /* End PBXFrameworksBuildPhase section */ 53 | 54 | /* Begin PBXGroup section */ 55 | 10EC02CB1BD4769900973DD9 = { 56 | isa = PBXGroup; 57 | children = ( 58 | 10EC02D61BD4769900973DD9 /* GCD */, 59 | 10EC02D51BD4769900973DD9 /* Products */, 60 | ); 61 | sourceTree = ""; 62 | }; 63 | 10EC02D51BD4769900973DD9 /* Products */ = { 64 | isa = PBXGroup; 65 | children = ( 66 | 10EC02D41BD4769900973DD9 /* GCD.app */, 67 | ); 68 | name = Products; 69 | sourceTree = ""; 70 | }; 71 | 10EC02D61BD4769900973DD9 /* GCD */ = { 72 | isa = PBXGroup; 73 | children = ( 74 | 10EC02DA1BD4769900973DD9 /* AppDelegate.h */, 75 | 10EC02DB1BD4769900973DD9 /* AppDelegate.m */, 76 | 10EC02DD1BD4769900973DD9 /* ViewController.h */, 77 | 10EC02DE1BD4769900973DD9 /* ViewController.m */, 78 | 10EC030A1BD476CC00973DD9 /* GCD */, 79 | 10EC02E01BD4769900973DD9 /* Main.storyboard */, 80 | 10EC02E31BD4769900973DD9 /* Assets.xcassets */, 81 | 10EC02E51BD4769900973DD9 /* LaunchScreen.storyboard */, 82 | 10EC02E81BD4769900973DD9 /* Info.plist */, 83 | 10EC02D71BD4769900973DD9 /* Supporting Files */, 84 | ); 85 | path = GCD; 86 | sourceTree = ""; 87 | }; 88 | 10EC02D71BD4769900973DD9 /* Supporting Files */ = { 89 | isa = PBXGroup; 90 | children = ( 91 | 10EC02D81BD4769900973DD9 /* main.m */, 92 | ); 93 | name = "Supporting Files"; 94 | sourceTree = ""; 95 | }; 96 | 10EC030A1BD476CC00973DD9 /* GCD */ = { 97 | isa = PBXGroup; 98 | children = ( 99 | 10EC030B1BD476CC00973DD9 /* GCD.h */, 100 | 10EC030E1BD476CC00973DD9 /* GCDQueue.h */, 101 | 10EC030F1BD476CC00973DD9 /* GCDQueue.m */, 102 | 10EC030C1BD476CC00973DD9 /* GCDGroup.h */, 103 | 10EC030D1BD476CC00973DD9 /* GCDGroup.m */, 104 | 10EC03101BD476CC00973DD9 /* GCDSemaphore.h */, 105 | 10EC03111BD476CC00973DD9 /* GCDSemaphore.m */, 106 | 10EC03121BD476CC00973DD9 /* GCDTimer.h */, 107 | 10EC03131BD476CC00973DD9 /* GCDTimer.m */, 108 | ); 109 | path = GCD; 110 | sourceTree = ""; 111 | }; 112 | /* End PBXGroup section */ 113 | 114 | /* Begin PBXNativeTarget section */ 115 | 10EC02D31BD4769900973DD9 /* GCD */ = { 116 | isa = PBXNativeTarget; 117 | buildConfigurationList = 10EC03011BD4769900973DD9 /* Build configuration list for PBXNativeTarget "GCD" */; 118 | buildPhases = ( 119 | 10EC02D01BD4769900973DD9 /* Sources */, 120 | 10EC02D11BD4769900973DD9 /* Frameworks */, 121 | 10EC02D21BD4769900973DD9 /* Resources */, 122 | ); 123 | buildRules = ( 124 | ); 125 | dependencies = ( 126 | ); 127 | name = GCD; 128 | productName = GCD; 129 | productReference = 10EC02D41BD4769900973DD9 /* GCD.app */; 130 | productType = "com.apple.product-type.application"; 131 | }; 132 | /* End PBXNativeTarget section */ 133 | 134 | /* Begin PBXProject section */ 135 | 10EC02CC1BD4769900973DD9 /* Project object */ = { 136 | isa = PBXProject; 137 | attributes = { 138 | LastUpgradeCheck = 0930; 139 | ORGANIZATIONNAME = ZiPeiYi; 140 | TargetAttributes = { 141 | 10EC02D31BD4769900973DD9 = { 142 | CreatedOnToolsVersion = 7.0.1; 143 | }; 144 | }; 145 | }; 146 | buildConfigurationList = 10EC02CF1BD4769900973DD9 /* Build configuration list for PBXProject "GCD" */; 147 | compatibilityVersion = "Xcode 3.2"; 148 | developmentRegion = English; 149 | hasScannedForEncodings = 0; 150 | knownRegions = ( 151 | en, 152 | Base, 153 | ); 154 | mainGroup = 10EC02CB1BD4769900973DD9; 155 | productRefGroup = 10EC02D51BD4769900973DD9 /* Products */; 156 | projectDirPath = ""; 157 | projectRoot = ""; 158 | targets = ( 159 | 10EC02D31BD4769900973DD9 /* GCD */, 160 | ); 161 | }; 162 | /* End PBXProject section */ 163 | 164 | /* Begin PBXResourcesBuildPhase section */ 165 | 10EC02D21BD4769900973DD9 /* Resources */ = { 166 | isa = PBXResourcesBuildPhase; 167 | buildActionMask = 2147483647; 168 | files = ( 169 | 10EC02E71BD4769900973DD9 /* LaunchScreen.storyboard in Resources */, 170 | 10EC02E41BD4769900973DD9 /* Assets.xcassets in Resources */, 171 | 10EC02E21BD4769900973DD9 /* Main.storyboard in Resources */, 172 | ); 173 | runOnlyForDeploymentPostprocessing = 0; 174 | }; 175 | /* End PBXResourcesBuildPhase section */ 176 | 177 | /* Begin PBXSourcesBuildPhase section */ 178 | 10EC02D01BD4769900973DD9 /* Sources */ = { 179 | isa = PBXSourcesBuildPhase; 180 | buildActionMask = 2147483647; 181 | files = ( 182 | 10EC03141BD476CC00973DD9 /* GCDGroup.m in Sources */, 183 | 10EC02DF1BD4769900973DD9 /* ViewController.m in Sources */, 184 | 10EC02DC1BD4769900973DD9 /* AppDelegate.m in Sources */, 185 | 10EC02D91BD4769900973DD9 /* main.m in Sources */, 186 | 10EC03171BD476CC00973DD9 /* GCDTimer.m in Sources */, 187 | 10EC03151BD476CC00973DD9 /* GCDQueue.m in Sources */, 188 | 10EC03161BD476CC00973DD9 /* GCDSemaphore.m in Sources */, 189 | ); 190 | runOnlyForDeploymentPostprocessing = 0; 191 | }; 192 | /* End PBXSourcesBuildPhase section */ 193 | 194 | /* Begin PBXVariantGroup section */ 195 | 10EC02E01BD4769900973DD9 /* Main.storyboard */ = { 196 | isa = PBXVariantGroup; 197 | children = ( 198 | 10EC02E11BD4769900973DD9 /* Base */, 199 | ); 200 | name = Main.storyboard; 201 | sourceTree = ""; 202 | }; 203 | 10EC02E51BD4769900973DD9 /* LaunchScreen.storyboard */ = { 204 | isa = PBXVariantGroup; 205 | children = ( 206 | 10EC02E61BD4769900973DD9 /* Base */, 207 | ); 208 | name = LaunchScreen.storyboard; 209 | sourceTree = ""; 210 | }; 211 | /* End PBXVariantGroup section */ 212 | 213 | /* Begin XCBuildConfiguration section */ 214 | 10EC02FF1BD4769900973DD9 /* Debug */ = { 215 | isa = XCBuildConfiguration; 216 | buildSettings = { 217 | ALWAYS_SEARCH_USER_PATHS = NO; 218 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 219 | CLANG_CXX_LIBRARY = "libc++"; 220 | CLANG_ENABLE_MODULES = YES; 221 | CLANG_ENABLE_OBJC_ARC = YES; 222 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 223 | CLANG_WARN_BOOL_CONVERSION = YES; 224 | CLANG_WARN_COMMA = YES; 225 | CLANG_WARN_CONSTANT_CONVERSION = YES; 226 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 227 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 228 | CLANG_WARN_EMPTY_BODY = YES; 229 | CLANG_WARN_ENUM_CONVERSION = YES; 230 | CLANG_WARN_INFINITE_RECURSION = YES; 231 | CLANG_WARN_INT_CONVERSION = YES; 232 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 233 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 234 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 235 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 236 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 237 | CLANG_WARN_STRICT_PROTOTYPES = YES; 238 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 239 | CLANG_WARN_UNREACHABLE_CODE = YES; 240 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 241 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 242 | COPY_PHASE_STRIP = NO; 243 | DEBUG_INFORMATION_FORMAT = dwarf; 244 | ENABLE_STRICT_OBJC_MSGSEND = YES; 245 | ENABLE_TESTABILITY = YES; 246 | GCC_C_LANGUAGE_STANDARD = gnu99; 247 | GCC_DYNAMIC_NO_PIC = NO; 248 | GCC_NO_COMMON_BLOCKS = YES; 249 | GCC_OPTIMIZATION_LEVEL = 0; 250 | GCC_PREPROCESSOR_DEFINITIONS = ( 251 | "DEBUG=1", 252 | "$(inherited)", 253 | ); 254 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 255 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 256 | GCC_WARN_UNDECLARED_SELECTOR = YES; 257 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 258 | GCC_WARN_UNUSED_FUNCTION = YES; 259 | GCC_WARN_UNUSED_VARIABLE = YES; 260 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 261 | MTL_ENABLE_DEBUG_INFO = YES; 262 | ONLY_ACTIVE_ARCH = YES; 263 | SDKROOT = iphoneos; 264 | }; 265 | name = Debug; 266 | }; 267 | 10EC03001BD4769900973DD9 /* Release */ = { 268 | isa = XCBuildConfiguration; 269 | buildSettings = { 270 | ALWAYS_SEARCH_USER_PATHS = NO; 271 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 272 | CLANG_CXX_LIBRARY = "libc++"; 273 | CLANG_ENABLE_MODULES = YES; 274 | CLANG_ENABLE_OBJC_ARC = YES; 275 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 276 | CLANG_WARN_BOOL_CONVERSION = YES; 277 | CLANG_WARN_COMMA = YES; 278 | CLANG_WARN_CONSTANT_CONVERSION = YES; 279 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 280 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 281 | CLANG_WARN_EMPTY_BODY = YES; 282 | CLANG_WARN_ENUM_CONVERSION = YES; 283 | CLANG_WARN_INFINITE_RECURSION = YES; 284 | CLANG_WARN_INT_CONVERSION = YES; 285 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 286 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 287 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 288 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 289 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 290 | CLANG_WARN_STRICT_PROTOTYPES = YES; 291 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 292 | CLANG_WARN_UNREACHABLE_CODE = YES; 293 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 294 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 295 | COPY_PHASE_STRIP = NO; 296 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 297 | ENABLE_NS_ASSERTIONS = NO; 298 | ENABLE_STRICT_OBJC_MSGSEND = YES; 299 | GCC_C_LANGUAGE_STANDARD = gnu99; 300 | GCC_NO_COMMON_BLOCKS = YES; 301 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 302 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 303 | GCC_WARN_UNDECLARED_SELECTOR = YES; 304 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 305 | GCC_WARN_UNUSED_FUNCTION = YES; 306 | GCC_WARN_UNUSED_VARIABLE = YES; 307 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 308 | MTL_ENABLE_DEBUG_INFO = NO; 309 | SDKROOT = iphoneos; 310 | VALIDATE_PRODUCT = YES; 311 | }; 312 | name = Release; 313 | }; 314 | 10EC03021BD4769900973DD9 /* Debug */ = { 315 | isa = XCBuildConfiguration; 316 | buildSettings = { 317 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 318 | INFOPLIST_FILE = GCD/Info.plist; 319 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 320 | PRODUCT_BUNDLE_IDENTIFIER = mc.TextCapital.GCD; 321 | PRODUCT_NAME = "$(TARGET_NAME)"; 322 | }; 323 | name = Debug; 324 | }; 325 | 10EC03031BD4769900973DD9 /* Release */ = { 326 | isa = XCBuildConfiguration; 327 | buildSettings = { 328 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 329 | INFOPLIST_FILE = GCD/Info.plist; 330 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 331 | PRODUCT_BUNDLE_IDENTIFIER = mc.TextCapital.GCD; 332 | PRODUCT_NAME = "$(TARGET_NAME)"; 333 | }; 334 | name = Release; 335 | }; 336 | /* End XCBuildConfiguration section */ 337 | 338 | /* Begin XCConfigurationList section */ 339 | 10EC02CF1BD4769900973DD9 /* Build configuration list for PBXProject "GCD" */ = { 340 | isa = XCConfigurationList; 341 | buildConfigurations = ( 342 | 10EC02FF1BD4769900973DD9 /* Debug */, 343 | 10EC03001BD4769900973DD9 /* Release */, 344 | ); 345 | defaultConfigurationIsVisible = 0; 346 | defaultConfigurationName = Release; 347 | }; 348 | 10EC03011BD4769900973DD9 /* Build configuration list for PBXNativeTarget "GCD" */ = { 349 | isa = XCConfigurationList; 350 | buildConfigurations = ( 351 | 10EC03021BD4769900973DD9 /* Debug */, 352 | 10EC03031BD4769900973DD9 /* Release */, 353 | ); 354 | defaultConfigurationIsVisible = 0; 355 | defaultConfigurationName = Release; 356 | }; 357 | /* End XCConfigurationList section */ 358 | }; 359 | rootObject = 10EC02CC1BD4769900973DD9 /* Project object */; 360 | } 361 | -------------------------------------------------------------------------------- /GCD.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /GCD.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /GCD.xcodeproj/project.xcworkspace/xcuserdata/YouXianMing.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YouXianMing/GCD-Program/a7dea7a7427341ed5b7ce5f3fa93e10eb18b32aa/GCD.xcodeproj/project.xcworkspace/xcuserdata/YouXianMing.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /GCD.xcodeproj/xcuserdata/YouXianMing.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /GCD.xcodeproj/xcuserdata/YouXianMing.xcuserdatad/xcschemes/GCD.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 43 | 49 | 50 | 51 | 52 | 53 | 59 | 60 | 61 | 62 | 63 | 64 | 74 | 76 | 82 | 83 | 84 | 85 | 86 | 87 | 93 | 95 | 101 | 102 | 103 | 104 | 106 | 107 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /GCD.xcodeproj/xcuserdata/YouXianMing.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | GCD.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 10EC02D31BD4769900973DD9 16 | 17 | primary 18 | 19 | 20 | 10EC02EC1BD4769900973DD9 21 | 22 | primary 23 | 24 | 25 | 10EC02F71BD4769900973DD9 26 | 27 | primary 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /GCD.xcodeproj/xcuserdata/YouXianMing1987@iCloud.com.xcuserdatad/xcschemes/GCD.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /GCD/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // GCD 4 | // 5 | // Created by YouXianMing on 15/10/19. 6 | // Copyright © 2015年 ZiPeiYi. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /GCD/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // GCD 4 | // 5 | // Created by YouXianMing on 15/10/19. 6 | // Copyright © 2015年 ZiPeiYi. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | - (void)applicationWillResignActive:(UIApplication *)application { 24 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 25 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 26 | } 27 | 28 | - (void)applicationDidEnterBackground:(UIApplication *)application { 29 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 31 | } 32 | 33 | - (void)applicationWillEnterForeground:(UIApplication *)application { 34 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 35 | } 36 | 37 | - (void)applicationDidBecomeActive:(UIApplication *)application { 38 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application { 42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /GCD/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /GCD/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /GCD/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /GCD/GCD/GCD.h: -------------------------------------------------------------------------------- 1 | // 2 | // GCD.h 3 | // GCD 4 | // 5 | // http://home.cnblogs.com/u/YouXianMing/ 6 | // https://github.com/YouXianMing 7 | // 8 | // Created by XianMingYou on 15/3/15. 9 | // Copyright (c) 2015年 XianMingYou. All rights reserved. 10 | // 11 | 12 | #import "GCDQueue.h" 13 | #import "GCDGroup.h" 14 | #import "GCDSemaphore.h" 15 | #import "GCDTimer.h" 16 | 17 | 18 | -------------------------------------------------------------------------------- /GCD/GCD/GCDGroup.h: -------------------------------------------------------------------------------- 1 | // 2 | // GCDGroup.h 3 | // GCD 4 | // 5 | // http://home.cnblogs.com/u/YouXianMing/ 6 | // https://github.com/YouXianMing 7 | // 8 | // Created by XianMingYou on 15/3/15. 9 | // Copyright (c) 2015年 XianMingYou. All rights reserved. 10 | // 11 | 12 | #import 13 | 14 | @interface GCDGroup : NSObject 15 | 16 | @property (strong, nonatomic, readonly) dispatch_group_t dispatchGroup; 17 | 18 | #pragma 初始化 19 | - (instancetype)init; 20 | 21 | #pragma mark - 用法 22 | - (void)enter; 23 | - (void)leave; 24 | - (void)wait; 25 | - (BOOL)wait:(int64_t)delta; 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /GCD/GCD/GCDGroup.m: -------------------------------------------------------------------------------- 1 | // 2 | // GCDGroup.m 3 | // GCD 4 | // 5 | // http://home.cnblogs.com/u/YouXianMing/ 6 | // https://github.com/YouXianMing 7 | // 8 | // Created by XianMingYou on 15/3/15. 9 | // Copyright (c) 2015年 XianMingYou. All rights reserved. 10 | // 11 | 12 | #import "GCDGroup.h" 13 | 14 | @interface GCDGroup () 15 | 16 | @property (strong, nonatomic, readwrite) dispatch_group_t dispatchGroup; 17 | 18 | @end 19 | 20 | @implementation GCDGroup 21 | 22 | - (instancetype)init { 23 | 24 | self = [super init]; 25 | 26 | if (self) { 27 | 28 | self.dispatchGroup = dispatch_group_create(); 29 | } 30 | 31 | return self; 32 | } 33 | 34 | - (void)enter { 35 | 36 | dispatch_group_enter(self.dispatchGroup); 37 | } 38 | 39 | - (void)leave { 40 | 41 | dispatch_group_leave(self.dispatchGroup); 42 | } 43 | 44 | - (void)wait { 45 | 46 | dispatch_group_wait(self.dispatchGroup, DISPATCH_TIME_FOREVER); 47 | } 48 | 49 | - (BOOL)wait:(int64_t)delta { 50 | 51 | return dispatch_group_wait(self.dispatchGroup, dispatch_time(DISPATCH_TIME_NOW, delta)) == 0; 52 | } 53 | 54 | @end 55 | -------------------------------------------------------------------------------- /GCD/GCD/GCDQueue.h: -------------------------------------------------------------------------------- 1 | // 2 | // GCDQueue.h 3 | // GCD 4 | // 5 | // http://home.cnblogs.com/u/YouXianMing/ 6 | // https://github.com/YouXianMing 7 | // 8 | // Created by XianMingYou on 15/3/15. 9 | // Copyright (c) 2015年 XianMingYou. All rights reserved. 10 | // 11 | 12 | #import 13 | 14 | @class GCDGroup; 15 | 16 | @interface GCDQueue : NSObject 17 | 18 | @property (strong, readonly, nonatomic) dispatch_queue_t dispatchQueue; 19 | 20 | + (GCDQueue *)mainQueue; 21 | + (GCDQueue *)globalQueue; 22 | + (GCDQueue *)highPriorityGlobalQueue; 23 | + (GCDQueue *)lowPriorityGlobalQueue; 24 | + (GCDQueue *)backgroundPriorityGlobalQueue; 25 | 26 | #pragma mark - 便利的构造方法 27 | + (void)executeInMainQueue:(dispatch_block_t)block; 28 | + (void)executeInGlobalQueue:(dispatch_block_t)block; 29 | + (void)executeInHighPriorityGlobalQueue:(dispatch_block_t)block; 30 | + (void)executeInLowPriorityGlobalQueue:(dispatch_block_t)block; 31 | + (void)executeInBackgroundPriorityGlobalQueue:(dispatch_block_t)block; 32 | + (void)executeInMainQueue:(dispatch_block_t)block afterDelaySecs:(NSTimeInterval)sec; 33 | + (void)executeInGlobalQueue:(dispatch_block_t)block afterDelaySecs:(NSTimeInterval)sec; 34 | + (void)executeInHighPriorityGlobalQueue:(dispatch_block_t)block afterDelaySecs:(NSTimeInterval)sec; 35 | + (void)executeInLowPriorityGlobalQueue:(dispatch_block_t)block afterDelaySecs:(NSTimeInterval)sec; 36 | + (void)executeInBackgroundPriorityGlobalQueue:(dispatch_block_t)block afterDelaySecs:(NSTimeInterval)sec; 37 | 38 | #pragma 初始化 39 | - (instancetype)init; 40 | - (instancetype)initSerial; 41 | - (instancetype)initSerialWithLabel:(NSString *)label; 42 | - (instancetype)initConcurrent; 43 | - (instancetype)initConcurrentWithLabel:(NSString *)label; 44 | 45 | #pragma mark - 用法 46 | - (void)execute:(dispatch_block_t)block; 47 | - (void)execute:(dispatch_block_t)block afterDelay:(int64_t)delta; 48 | - (void)execute:(dispatch_block_t)block afterDelaySecs:(float)delta; 49 | - (void)waitExecute:(dispatch_block_t)block; 50 | - (void)barrierExecute:(dispatch_block_t)block; 51 | - (void)waitBarrierExecute:(dispatch_block_t)block; 52 | - (void)suspend; 53 | - (void)resume; 54 | 55 | #pragma mark - 与GCDGroup相关 56 | - (void)execute:(dispatch_block_t)block inGroup:(GCDGroup *)group; 57 | - (void)notify:(dispatch_block_t)block inGroup:(GCDGroup *)group; 58 | 59 | @end 60 | -------------------------------------------------------------------------------- /GCD/GCD/GCDQueue.m: -------------------------------------------------------------------------------- 1 | // 2 | // GCDQueue.m 3 | // GCD 4 | // 5 | // http://home.cnblogs.com/u/YouXianMing/ 6 | // https://github.com/YouXianMing 7 | // 8 | // Created by XianMingYou on 15/3/15. 9 | // Copyright (c) 2015年 XianMingYou. All rights reserved. 10 | // 11 | 12 | #import "GCDQueue.h" 13 | #import "GCDGroup.h" 14 | 15 | static GCDQueue *mainQueue; 16 | static GCDQueue *globalQueue; 17 | static GCDQueue *highPriorityGlobalQueue; 18 | static GCDQueue *lowPriorityGlobalQueue; 19 | static GCDQueue *backgroundPriorityGlobalQueue; 20 | 21 | @interface GCDQueue () 22 | 23 | @property (strong, readwrite, nonatomic) dispatch_queue_t dispatchQueue; 24 | 25 | @end 26 | 27 | @implementation GCDQueue 28 | 29 | + (GCDQueue *)mainQueue { 30 | 31 | return mainQueue; 32 | } 33 | 34 | + (GCDQueue *)globalQueue { 35 | 36 | return globalQueue; 37 | } 38 | 39 | + (GCDQueue *)highPriorityGlobalQueue { 40 | 41 | return highPriorityGlobalQueue; 42 | } 43 | 44 | + (GCDQueue *)lowPriorityGlobalQueue { 45 | 46 | return lowPriorityGlobalQueue; 47 | } 48 | 49 | + (GCDQueue *)backgroundPriorityGlobalQueue { 50 | 51 | return backgroundPriorityGlobalQueue; 52 | } 53 | 54 | + (void)initialize { 55 | 56 | /** 57 | Initializes the class before it receives its first message. 58 | 59 | 1. The runtime sends the initialize message to classes in a 60 | thread-safe manner. 61 | 62 | 2. initialize is invoked only once per class. If you want to 63 | perform independent initialization for the class and for 64 | categories of the class, you should implement load methods. 65 | */ 66 | if (self == [GCDQueue self]) { 67 | 68 | mainQueue = [GCDQueue new]; 69 | globalQueue = [GCDQueue new]; 70 | highPriorityGlobalQueue = [GCDQueue new]; 71 | lowPriorityGlobalQueue = [GCDQueue new]; 72 | backgroundPriorityGlobalQueue = [GCDQueue new]; 73 | 74 | mainQueue.dispatchQueue = dispatch_get_main_queue(); 75 | globalQueue.dispatchQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); 76 | highPriorityGlobalQueue.dispatchQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0); 77 | lowPriorityGlobalQueue.dispatchQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0); 78 | backgroundPriorityGlobalQueue.dispatchQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0); 79 | } 80 | } 81 | 82 | - (instancetype)init { 83 | 84 | return [self initSerial]; 85 | } 86 | 87 | - (instancetype)initSerial { 88 | 89 | self = [super init]; 90 | 91 | if (self) { 92 | 93 | self.dispatchQueue = dispatch_queue_create(nil, DISPATCH_QUEUE_SERIAL); 94 | } 95 | 96 | return self; 97 | } 98 | 99 | - (instancetype)initSerialWithLabel:(NSString *)label { 100 | 101 | self = [super init]; 102 | if (self) 103 | { 104 | self.dispatchQueue = dispatch_queue_create([label UTF8String], DISPATCH_QUEUE_SERIAL); 105 | } 106 | 107 | return self; 108 | } 109 | 110 | - (instancetype)initConcurrent { 111 | 112 | self = [super init]; 113 | 114 | if (self) { 115 | 116 | self.dispatchQueue = dispatch_queue_create(nil, DISPATCH_QUEUE_CONCURRENT); 117 | } 118 | 119 | return self; 120 | } 121 | 122 | - (instancetype)initConcurrentWithLabel:(NSString *)label { 123 | self = [super init]; 124 | if (self) 125 | { 126 | self.dispatchQueue = dispatch_queue_create([label UTF8String], DISPATCH_QUEUE_CONCURRENT); 127 | } 128 | return self; 129 | } 130 | 131 | - (void)execute:(dispatch_block_t)block { 132 | 133 | NSParameterAssert(block); 134 | dispatch_async(self.dispatchQueue, block); 135 | } 136 | 137 | - (void)execute:(dispatch_block_t)block afterDelay:(int64_t)delta { 138 | 139 | NSParameterAssert(block); 140 | dispatch_after(dispatch_time(DISPATCH_TIME_NOW, delta), self.dispatchQueue, block); 141 | } 142 | 143 | - (void)execute:(dispatch_block_t)block afterDelaySecs:(float)delta { 144 | 145 | NSParameterAssert(block); 146 | dispatch_after(dispatch_time(DISPATCH_TIME_NOW, delta * NSEC_PER_SEC), self.dispatchQueue, block); 147 | } 148 | 149 | - (void)waitExecute:(dispatch_block_t)block { 150 | 151 | /* 152 | As an optimization, this function invokes the block on 153 | the current thread when possible. 154 | 155 | 作为一个建议,这个方法尽量在当前线程池中调用. 156 | */ 157 | 158 | NSParameterAssert(block); 159 | dispatch_sync(self.dispatchQueue, block); 160 | } 161 | 162 | - (void)barrierExecute:(dispatch_block_t)block { 163 | 164 | /* 165 | The queue you specify should be a concurrent queue that you 166 | create yourself using the dispatch_queue_create function. 167 | If the queue you pass to this function is a serial queue or 168 | one of the global concurrent queues, this function behaves 169 | like the dispatch_async function. 170 | 171 | 使用的线程池应该是你自己创建的并发线程池.如果你传进来的参数为串行线程池 172 | 或者是系统的并发线程池中的某一个,这个方法就会被当做一个普通的async操作 173 | */ 174 | 175 | NSParameterAssert(block); 176 | dispatch_barrier_async(self.dispatchQueue, block); 177 | } 178 | 179 | - (void)waitBarrierExecute:(dispatch_block_t)block { 180 | 181 | /* 182 | The queue you specify should be a concurrent queue that you 183 | create yourself using the dispatch_queue_create function. 184 | If the queue you pass to this function is a serial queue or 185 | one of the global concurrent queues, this function behaves 186 | like the dispatch_sync function. 187 | 188 | 使用的线程池应该是你自己创建的并发线程池.如果你传进来的参数为串行线程池 189 | 或者是系统的并发线程池中的某一个,这个方法就会被当做一个普通的sync操作 190 | 191 | As an optimization, this function invokes the barrier block 192 | on the current thread when possible. 193 | 194 | 作为一个建议,这个方法尽量在当前线程池中调用. 195 | */ 196 | 197 | NSParameterAssert(block); 198 | dispatch_barrier_sync(self.dispatchQueue, block); 199 | } 200 | 201 | - (void)suspend { 202 | 203 | dispatch_suspend(self.dispatchQueue); 204 | } 205 | 206 | - (void)resume { 207 | 208 | dispatch_resume(self.dispatchQueue); 209 | } 210 | 211 | - (void)execute:(dispatch_block_t)block inGroup:(GCDGroup *)group { 212 | 213 | NSParameterAssert(block); 214 | dispatch_group_async(group.dispatchGroup, self.dispatchQueue, block); 215 | } 216 | 217 | - (void)notify:(dispatch_block_t)block inGroup:(GCDGroup *)group { 218 | 219 | NSParameterAssert(block); 220 | dispatch_group_notify(group.dispatchGroup, self.dispatchQueue, block); 221 | } 222 | 223 | 224 | #pragma mark - 便利的构造方法 225 | + (void)executeInMainQueue:(dispatch_block_t)block afterDelaySecs:(NSTimeInterval)sec { 226 | 227 | NSParameterAssert(block); 228 | dispatch_after(dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC * sec), mainQueue.dispatchQueue, block); 229 | } 230 | 231 | + (void)executeInGlobalQueue:(dispatch_block_t)block afterDelaySecs:(NSTimeInterval)sec { 232 | 233 | NSParameterAssert(block); 234 | dispatch_after(dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC * sec), globalQueue.dispatchQueue, block); 235 | } 236 | 237 | + (void)executeInHighPriorityGlobalQueue:(dispatch_block_t)block afterDelaySecs:(NSTimeInterval)sec { 238 | 239 | NSParameterAssert(block); 240 | dispatch_after(dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC * sec), highPriorityGlobalQueue.dispatchQueue, block); 241 | } 242 | 243 | + (void)executeInLowPriorityGlobalQueue:(dispatch_block_t)block afterDelaySecs:(NSTimeInterval)sec { 244 | 245 | NSParameterAssert(block); 246 | dispatch_after(dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC * sec), lowPriorityGlobalQueue.dispatchQueue, block); 247 | } 248 | 249 | + (void)executeInBackgroundPriorityGlobalQueue:(dispatch_block_t)block afterDelaySecs:(NSTimeInterval)sec { 250 | 251 | NSParameterAssert(block); 252 | dispatch_after(dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC * sec), backgroundPriorityGlobalQueue.dispatchQueue, block); 253 | } 254 | 255 | + (void)executeInMainQueue:(dispatch_block_t)block { 256 | 257 | NSParameterAssert(block); 258 | dispatch_async(mainQueue.dispatchQueue, block); 259 | } 260 | 261 | + (void)executeInGlobalQueue:(dispatch_block_t)block { 262 | 263 | NSParameterAssert(block); 264 | dispatch_async(globalQueue.dispatchQueue, block); 265 | } 266 | 267 | + (void)executeInHighPriorityGlobalQueue:(dispatch_block_t)block { 268 | 269 | NSParameterAssert(block); 270 | dispatch_async(highPriorityGlobalQueue.dispatchQueue, block); 271 | } 272 | 273 | + (void)executeInLowPriorityGlobalQueue:(dispatch_block_t)block { 274 | 275 | NSParameterAssert(block); 276 | dispatch_async(lowPriorityGlobalQueue.dispatchQueue, block); 277 | } 278 | 279 | + (void)executeInBackgroundPriorityGlobalQueue:(dispatch_block_t)block { 280 | 281 | NSParameterAssert(block); 282 | dispatch_async(backgroundPriorityGlobalQueue.dispatchQueue, block); 283 | } 284 | 285 | @end 286 | -------------------------------------------------------------------------------- /GCD/GCD/GCDSemaphore.h: -------------------------------------------------------------------------------- 1 | // 2 | // GCDSemaphore.h 3 | // GCD 4 | // 5 | // http://home.cnblogs.com/u/YouXianMing/ 6 | // https://github.com/YouXianMing 7 | // 8 | // Created by XianMingYou on 15/3/15. 9 | // Copyright (c) 2015年 XianMingYou. All rights reserved. 10 | // 11 | 12 | #import 13 | 14 | @interface GCDSemaphore : NSObject 15 | 16 | @property (strong, readonly, nonatomic) dispatch_semaphore_t dispatchSemaphore; 17 | 18 | #pragma 初始化 19 | - (instancetype)init; 20 | - (instancetype)initWithValue:(long)value; 21 | 22 | #pragma mark - 用法 23 | - (BOOL)signal; 24 | - (void)wait; 25 | - (BOOL)wait:(int64_t)delta; 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /GCD/GCD/GCDSemaphore.m: -------------------------------------------------------------------------------- 1 | // 2 | // GCDSemaphore.m 3 | // GCD 4 | // 5 | // http://home.cnblogs.com/u/YouXianMing/ 6 | // https://github.com/YouXianMing 7 | // 8 | // Created by XianMingYou on 15/3/15. 9 | // Copyright (c) 2015年 XianMingYou. All rights reserved. 10 | // 11 | 12 | #import "GCDSemaphore.h" 13 | 14 | @interface GCDSemaphore () 15 | 16 | @property (strong, readwrite, nonatomic) dispatch_semaphore_t dispatchSemaphore; 17 | 18 | @end 19 | 20 | @implementation GCDSemaphore 21 | 22 | - (instancetype)init { 23 | 24 | self = [super init]; 25 | 26 | if (self) { 27 | 28 | self.dispatchSemaphore = dispatch_semaphore_create(0); 29 | } 30 | 31 | return self; 32 | } 33 | 34 | - (instancetype)initWithValue:(long)value { 35 | 36 | self = [super init]; 37 | 38 | if (self) { 39 | 40 | self.dispatchSemaphore = dispatch_semaphore_create(value); 41 | } 42 | 43 | return self; 44 | } 45 | 46 | - (BOOL)signal { 47 | 48 | return dispatch_semaphore_signal(self.dispatchSemaphore) != 0; 49 | } 50 | 51 | - (void)wait { 52 | 53 | dispatch_semaphore_wait(self.dispatchSemaphore, DISPATCH_TIME_FOREVER); 54 | } 55 | 56 | - (BOOL)wait:(int64_t)delta { 57 | 58 | return dispatch_semaphore_wait(self.dispatchSemaphore, dispatch_time(DISPATCH_TIME_NOW, delta)) == 0; 59 | } 60 | 61 | @end 62 | -------------------------------------------------------------------------------- /GCD/GCD/GCDTimer.h: -------------------------------------------------------------------------------- 1 | // 2 | // GCDTimer.h 3 | // GCD 4 | // 5 | // http://home.cnblogs.com/u/YouXianMing/ 6 | // https://github.com/YouXianMing 7 | // 8 | // Created by XianMingYou on 15/3/15. 9 | // Copyright (c) 2015年 XianMingYou. All rights reserved. 10 | // 11 | 12 | #import 13 | 14 | @class GCDQueue; 15 | 16 | @interface GCDTimer : NSObject 17 | 18 | @property (strong, readonly, nonatomic) dispatch_source_t dispatchSource; 19 | 20 | #pragma 初始化 21 | - (instancetype)init; 22 | - (instancetype)initInQueue:(GCDQueue *)queue; 23 | 24 | #pragma mark - 用法 25 | - (void)event:(dispatch_block_t)block timeInterval:(uint64_t)interval; 26 | - (void)event:(dispatch_block_t)block cancelEvent:(dispatch_block_t)cancelEvent timeInterval:(uint64_t)interval; 27 | 28 | - (void)event:(dispatch_block_t)block timeInterval:(uint64_t)interval delay:(uint64_t)delay; 29 | - (void)event:(dispatch_block_t)block cancelEvent:(dispatch_block_t)cancelEvent timeInterval:(uint64_t)interval delay:(uint64_t)delay; 30 | 31 | - (void)event:(dispatch_block_t)block timeIntervalWithSecs:(float)secs; 32 | - (void)event:(dispatch_block_t)block cancelEvent:(dispatch_block_t)cancelEvent timeIntervalWithSecs:(float)secs; 33 | 34 | - (void)event:(dispatch_block_t)block timeIntervalWithSecs:(float)secs delaySecs:(float)delaySecs; 35 | - (void)event:(dispatch_block_t)block cancelEvent:(dispatch_block_t)cancelEvent timeIntervalWithSecs:(float)secs delaySecs:(float)delaySecs; 36 | 37 | - (void)start; 38 | - (void)destroy; 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /GCD/GCD/GCDTimer.m: -------------------------------------------------------------------------------- 1 | // 2 | // GCDTimer.m 3 | // GCD 4 | // 5 | // http://home.cnblogs.com/u/YouXianMing/ 6 | // https://github.com/YouXianMing 7 | // 8 | // Created by XianMingYou on 15/3/15. 9 | // Copyright (c) 2015年 XianMingYou. All rights reserved. 10 | // 11 | 12 | #import "GCDTimer.h" 13 | #import "GCDQueue.h" 14 | 15 | @interface GCDTimer () 16 | 17 | @property (strong, readwrite, nonatomic) dispatch_source_t dispatchSource; 18 | 19 | @end 20 | 21 | @implementation GCDTimer 22 | 23 | - (instancetype)init { 24 | 25 | self = [super init]; 26 | 27 | if (self) { 28 | 29 | self.dispatchSource = \ 30 | dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)); 31 | } 32 | 33 | return self; 34 | } 35 | 36 | - (instancetype)initInQueue:(GCDQueue *)queue { 37 | 38 | self = [super init]; 39 | 40 | if (self) { 41 | 42 | self.dispatchSource = \ 43 | dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue.dispatchQueue); 44 | } 45 | 46 | return self; 47 | } 48 | 49 | - (void)event:(dispatch_block_t)block timeInterval:(uint64_t)interval { 50 | 51 | NSParameterAssert(block); 52 | dispatch_source_set_timer(self.dispatchSource, dispatch_time(DISPATCH_TIME_NOW, 0), interval, 0); 53 | dispatch_source_set_event_handler(self.dispatchSource, block); 54 | } 55 | 56 | - (void)event:(dispatch_block_t)block cancelEvent:(dispatch_block_t)cancelEvent timeInterval:(uint64_t)interval { 57 | 58 | NSParameterAssert(block); 59 | dispatch_source_set_timer(self.dispatchSource, dispatch_time(DISPATCH_TIME_NOW, 0), interval, 0); 60 | dispatch_source_set_event_handler(self.dispatchSource, block); 61 | dispatch_source_set_cancel_handler(self.dispatchSource, cancelEvent); 62 | } 63 | 64 | - (void)event:(dispatch_block_t)block timeInterval:(uint64_t)interval delay:(uint64_t)delay { 65 | 66 | NSParameterAssert(block); 67 | dispatch_source_set_timer(self.dispatchSource, dispatch_time(DISPATCH_TIME_NOW, delay), interval, 0); 68 | dispatch_source_set_event_handler(self.dispatchSource, block); 69 | } 70 | 71 | - (void)event:(dispatch_block_t)block cancelEvent:(dispatch_block_t)cancelEvent timeInterval:(uint64_t)interval delay:(uint64_t)delay { 72 | 73 | NSParameterAssert(block); 74 | dispatch_source_set_timer(self.dispatchSource, dispatch_time(DISPATCH_TIME_NOW, delay), interval, 0); 75 | dispatch_source_set_event_handler(self.dispatchSource, block); 76 | dispatch_source_set_cancel_handler(self.dispatchSource, cancelEvent); 77 | } 78 | 79 | - (void)event:(dispatch_block_t)block timeIntervalWithSecs:(float)secs { 80 | 81 | NSParameterAssert(block); 82 | dispatch_source_set_timer(self.dispatchSource, dispatch_time(DISPATCH_TIME_NOW, 0), secs * NSEC_PER_SEC, 0); 83 | dispatch_source_set_event_handler(self.dispatchSource, block); 84 | } 85 | 86 | - (void)event:(dispatch_block_t)block cancelEvent:(dispatch_block_t)cancelEvent timeIntervalWithSecs:(float)secs { 87 | 88 | NSParameterAssert(block); 89 | dispatch_source_set_timer(self.dispatchSource, dispatch_time(DISPATCH_TIME_NOW, 0), secs * NSEC_PER_SEC, 0); 90 | dispatch_source_set_event_handler(self.dispatchSource, block); 91 | dispatch_source_set_cancel_handler(self.dispatchSource, cancelEvent); 92 | } 93 | 94 | - (void)event:(dispatch_block_t)block timeIntervalWithSecs:(float)secs delaySecs:(float)delaySecs { 95 | 96 | NSParameterAssert(block); 97 | dispatch_source_set_timer(self.dispatchSource, dispatch_time(DISPATCH_TIME_NOW, delaySecs * NSEC_PER_SEC), secs * NSEC_PER_SEC, 0); 98 | dispatch_source_set_event_handler(self.dispatchSource, block); 99 | } 100 | 101 | - (void)event:(dispatch_block_t)block cancelEvent:(dispatch_block_t)cancelEvent timeIntervalWithSecs:(float)secs delaySecs:(float)delaySecs { 102 | 103 | NSParameterAssert(block); 104 | dispatch_source_set_timer(self.dispatchSource, dispatch_time(DISPATCH_TIME_NOW, delaySecs * NSEC_PER_SEC), secs * NSEC_PER_SEC, 0); 105 | dispatch_source_set_event_handler(self.dispatchSource, block); 106 | dispatch_source_set_cancel_handler(self.dispatchSource, cancelEvent); 107 | } 108 | 109 | - (void)start { 110 | 111 | dispatch_resume(self.dispatchSource); 112 | } 113 | 114 | - (void)destroy { 115 | 116 | dispatch_source_cancel(self.dispatchSource); 117 | } 118 | 119 | @end 120 | -------------------------------------------------------------------------------- /GCD/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /GCD/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // GCD 4 | // 5 | // Created by YouXianMing on 15/10/19. 6 | // Copyright © 2015年 ZiPeiYi. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /GCD/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // GCD 4 | // 5 | // Created by YouXianMing on 15/10/19. 6 | // Copyright © 2015年 ZiPeiYi. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "GCD.h" 11 | 12 | @interface ViewController () 13 | 14 | @property (nonatomic, strong) GCDTimer *timer; 15 | 16 | @end 17 | 18 | @implementation ViewController 19 | 20 | - (void)viewDidLoad { 21 | 22 | [super viewDidLoad]; 23 | 24 | [GCDQueue executeInGlobalQueue:^{ 25 | 26 | // download task, etc 27 | 28 | [GCDQueue executeInMainQueue:^{ 29 | 30 | // update UI 31 | }]; 32 | }]; 33 | 34 | 35 | 36 | 37 | // init group 38 | GCDGroup *group = [GCDGroup new]; 39 | 40 | // add to group 41 | [[GCDQueue globalQueue] execute:^{ 42 | 43 | // task one 44 | 45 | } inGroup:group]; 46 | 47 | // add to group 48 | [[GCDQueue globalQueue] execute:^{ 49 | 50 | // task two 51 | 52 | } inGroup:group]; 53 | 54 | // notify in mainQueue 55 | [[GCDQueue mainQueue] notify:^{ 56 | 57 | // task three 58 | 59 | } inGroup:group]; 60 | 61 | 62 | 63 | 64 | // init timer 65 | self.timer = [[GCDTimer alloc] initInQueue:[GCDQueue mainQueue]]; 66 | 67 | // timer event 68 | [self.timer event:^{ 69 | 70 | // task 71 | 72 | } timeInterval:NSEC_PER_SEC * 3 delay:NSEC_PER_SEC * 3]; 73 | 74 | // start timer 75 | [self.timer start]; 76 | 77 | 78 | 79 | 80 | // init semaphore 81 | GCDSemaphore *semaphore = [GCDSemaphore new]; 82 | 83 | // wait 84 | [GCDQueue executeInGlobalQueue:^{ 85 | 86 | [semaphore wait]; 87 | 88 | // todo sth else 89 | }]; 90 | 91 | // signal 92 | [GCDQueue executeInGlobalQueue:^{ 93 | 94 | // do sth 95 | [semaphore signal]; 96 | }]; 97 | } 98 | 99 | @end 100 | -------------------------------------------------------------------------------- /GCD/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // GCD 4 | // 5 | // Created by YouXianMing on 15/10/19. 6 | // Copyright © 2015年 ZiPeiYi. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GCD-Program 2 | 3 | > 需要swift版本GCD的请移步-[swift版本GCD](https://github.com/YouXianMing/Swift-GCD) 4 | 5 | ``` 6 | // 7 | // ViewController.m 8 | // GCD 9 | // 10 | // Created by YouXianMing on 15/10/19. 11 | // Copyright © 2015年 ZiPeiYi. All rights reserved. 12 | // 13 | 14 | #import "ViewController.h" 15 | #import "GCD.h" 16 | 17 | @interface ViewController () 18 | 19 | @property (nonatomic, strong) GCDTimer *timer; 20 | 21 | @end 22 | 23 | @implementation ViewController 24 | 25 | - (void)viewDidLoad { 26 | 27 | [super viewDidLoad]; 28 | 29 | [GCDQueue executeInGlobalQueue:^{ 30 | 31 | // download task, etc 32 | 33 | [GCDQueue executeInMainQueue:^{ 34 | 35 | // update UI 36 | }]; 37 | }]; 38 | 39 | 40 | 41 | 42 | // init group 43 | GCDGroup *group = [GCDGroup new]; 44 | 45 | // add to group 46 | [[GCDQueue globalQueue] execute:^{ 47 | // task one 48 | } inGroup:group]; 49 | 50 | // add to group 51 | [[GCDQueue globalQueue] execute:^{ 52 | // task two 53 | } inGroup:group]; 54 | 55 | // notify in mainQueue 56 | [[GCDQueue mainQueue] notify:^{ 57 | // task three 58 | } inGroup:group]; 59 | 60 | 61 | 62 | 63 | // init timer 64 | self.timer = [[GCDTimer alloc] initInQueue:[GCDQueue mainQueue]]; 65 | 66 | // timer event 67 | [self.timer event:^{ 68 | // task 69 | } timeInterval:NSEC_PER_SEC * 3]; 70 | 71 | // start timer 72 | [self.timer start]; 73 | 74 | 75 | 76 | 77 | // init semaphore 78 | GCDSemaphore *semaphore = [GCDSemaphore new]; 79 | 80 | // wait 81 | [GCDQueue executeInGlobalQueue:^{ 82 | 83 | [semaphore wait]; 84 | // todo sth else 85 | }]; 86 | 87 | // signal 88 | [GCDQueue executeInGlobalQueue:^{ 89 | 90 | // do sth 91 | [semaphore signal]; 92 | }]; 93 | } 94 | 95 | @end 96 | ``` 97 | 98 | --------------------------------------------------------------------------------