diff --git a/File/YBTaskSchedulerP0.png b/File/YBTaskSchedulerP0.png new file mode 100644 index 0000000..2937a00 Binary files /dev/null and b/File/YBTaskSchedulerP0.png differ diff --git a/File/YBTaskSchedulerUML.jpg b/File/YBTaskSchedulerUML.jpg new file mode 100644 index 0000000..70d39c7 Binary files /dev/null and b/File/YBTaskSchedulerUML.jpg differ diff --git a/YBTaskScheduler.podspec b/YBTaskScheduler.podspec index dcc8292..2793e33 100644 --- a/YBTaskScheduler.podspec +++ b/YBTaskScheduler.podspec @@ -4,7 +4,7 @@ Pod::Spec.new do |s| s.name = "YBTaskScheduler" - s.version = "1.0" + s.version = "1.0.1" s.summary = "iOS 任务调度器,为 CPU 和内存减负" s.description = <<-DESC 主要用途:拆分主线程任务、删除无意义任务减轻 CPU 和内存的负担,任务的优先级调度实现特殊需求。 @@ -20,9 +20,9 @@ Pod::Spec.new do |s| s.source = { :git => "https://github.com/indulgeIn/YBTaskScheduler.git", :tag => "#{s.version}" } - s.source_files = "YBTaskScheduler/**/*.{h,m}" + s.source_files = "YBTaskScheduler/**/*.{h,m,mm}" - s.frameworks = "Foundation" + s.libraries = 'c++.1' s.requires_arc = true diff --git a/YBTaskScheduler/YBTSPriorityQueue.mm b/YBTaskScheduler/YBTSPriorityQueue.mm index 8521ebf..70ff3f4 100644 --- a/YBTaskScheduler/YBTSPriorityQueue.mm +++ b/YBTaskScheduler/YBTSPriorityQueue.mm @@ -42,6 +42,11 @@ @implementation YBTSPriorityQueue { #pragma mark - life cycle +- (void)dealloc { + [self clearTasks]; + pthread_mutex_destroy(&_lock); +} + - (instancetype)init { self = [super init]; if (self) { @@ -54,6 +59,16 @@ - (instancetype)init { return self; } +#pragma mark - private + +- (void)clearTasks { + pthread_mutex_lock(&_lock); + while (!_queue.empty()) { + _queue.pop(); + } + pthread_mutex_unlock(&_lock); +} + #pragma mark - - (BOOL)ybts_empty { @@ -83,11 +98,7 @@ - (void)ybts_executeTask { } - (void)ybts_clearTasks { - pthread_mutex_lock(&_lock); - while (!_queue.empty()) { - _queue.pop(); - } - pthread_mutex_unlock(&_lock); + [self clearTasks]; } diff --git a/YBTaskScheduler/YBTaskScheduler.h b/YBTaskScheduler/YBTaskScheduler.h index bb70095..14c3199 100644 --- a/YBTaskScheduler/YBTaskScheduler.h +++ b/YBTaskScheduler/YBTaskScheduler.h @@ -54,7 +54,7 @@ NS_ASSUME_NONNULL_BEGIN @param task 包裹任务的 block @param priority 优先级 */ -- (void)addTask:(YBTaskBlock)task priority:(YBTaskPriority)priority;; +- (void)addTask:(YBTaskBlock)task priority:(YBTaskPriority)priority; /** 清空所有任务 diff --git a/YBTaskSchedulerDemo.xcodeproj/project.pbxproj b/YBTaskSchedulerDemo.xcodeproj/project.pbxproj index de20e4e..08f1a97 100644 --- a/YBTaskSchedulerDemo.xcodeproj/project.pbxproj +++ b/YBTaskSchedulerDemo.xcodeproj/project.pbxproj @@ -117,9 +117,9 @@ 233C712F21E08D6900D2AE95 /* YBTaskScheduler */ = { isa = PBXGroup; children = ( - 233C713021E08D6900D2AE95 /* YBTaskScheduler+Internal.h */, 233C713121E08D6900D2AE95 /* YBTaskScheduler.h */, 233C713221E08D6900D2AE95 /* YBTaskScheduler.m */, + 233C713021E08D6900D2AE95 /* YBTaskScheduler+Internal.h */, 233C713321E08D6900D2AE95 /* YBTaskSchedulerStrategyProtocol.h */, 233C713421E08D6900D2AE95 /* YBTaskSchedulerTypedef.h */, 233C713521E08D6900D2AE95 /* YBTSPriorityQueue.h */, @@ -401,7 +401,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - ONLY_ACTIVE_ARCH = YES; + ONLY_ACTIVE_ARCH = NO; PRODUCT_BUNDLE_IDENTIFIER = yangbo.YBTaskSchedulerDemo; PRODUCT_NAME = "$(TARGET_NAME)"; TARGETED_DEVICE_FAMILY = "1,2";