YYDispatchQueuePool.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. //
  2. // YYDispatchQueueManager.h
  3. // YYKit <https://github.com/ibireme/YYKit>
  4. //
  5. // Created by ibireme on 15/7/18.
  6. // Copyright (c) 2015 ibireme.
  7. //
  8. // This source code is licensed under the MIT-style license found in the
  9. // LICENSE file in the root directory of this source tree.
  10. //
  11. #import <Foundation/Foundation.h>
  12. #ifndef YYDispatchQueuePool_h
  13. #define YYDispatchQueuePool_h
  14. NS_ASSUME_NONNULL_BEGIN
  15. /**
  16. A dispatch queue pool holds multiple serial queues.
  17. Use this class to control queue's thread count (instead of concurrent queue).
  18. */
  19. @interface YYDispatchQueuePool : NSObject
  20. - (instancetype)init UNAVAILABLE_ATTRIBUTE;
  21. + (instancetype)new UNAVAILABLE_ATTRIBUTE;
  22. /**
  23. Creates and returns a dispatch queue pool.
  24. @param name The name of the pool.
  25. @param queueCount Maxmium queue count, should in range (1, 32).
  26. @param qos Queue quality of service (QOS).
  27. @return A new pool, or nil if an error occurs.
  28. */
  29. - (instancetype)initWithName:(nullable NSString *)name queueCount:(NSUInteger)queueCount qos:(NSQualityOfService)qos;
  30. /// Pool's name.
  31. @property (nullable, nonatomic, readonly) NSString *name;
  32. /// Get a serial queue from pool.
  33. - (dispatch_queue_t)queue;
  34. + (instancetype)defaultPoolForQOS:(NSQualityOfService)qos;
  35. @end
  36. /// Get a serial queue from global queue pool with a specified qos.
  37. extern dispatch_queue_t YYDispatchQueueGetForQOS(NSQualityOfService qos);
  38. NS_ASSUME_NONNULL_END
  39. #endif