Skip to content

Commit

Permalink
fix(COCoroutine.m): fix get dispatch bug
Browse files Browse the repository at this point in the history
fix get dispatch bug
  • Loading branch information
pengyutang125 committed Mar 29, 2019
1 parent 7cd46f6 commit f6c689a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
16 changes: 14 additions & 2 deletions cocore/CODispatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,19 @@
// CODispatch.h
// cocore
//
// Created by 彭 玉堂 on 2019/3/28.
// Copyright © 2019 Alibaba lnc. All rights reserved.
// Copyright © 2018 Alibaba Group Holding Limited All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#import <Foundation/Foundation.h>

Expand All @@ -23,6 +33,8 @@ NS_ASSUME_NONNULL_BEGIN

@interface CODispatch : NSObject

+ (instancetype)dispatchWithQueue:(dispatch_queue_t)q;

+ (instancetype)currentDispatch;

- (BOOL)isCurrentDispatch;
Expand Down
20 changes: 18 additions & 2 deletions cocore/CODispatch.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,19 @@
// CODispatch.m
// cocore
//
// Created by 彭 玉堂 on 2019/3/28.
// Copyright © 2019 Alibaba lnc. All rights reserved.
// Copyright © 2018 Alibaba Group Holding Limited All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#import "CODispatch.h"
#import "co_queue.h"
Expand Down Expand Up @@ -72,6 +82,12 @@ @interface CODispatch ()

@implementation CODispatch

+ (instancetype)dispatchWithQueue:(dispatch_queue_t)q{
CODispatch *dispatch = [[CODispatch alloc] init];
dispatch.queue = q;
return dispatch;
}

+ (instancetype)currentDispatch{
CODispatch *dispatch = [[CODispatch alloc] init];
dispatch_queue_t q = co_get_current_queue();
Expand Down
2 changes: 1 addition & 1 deletion coobjc/co/COCoroutine.m
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ - (instancetype)initWithBlock:(void (^)(void))block onQueue:(dispatch_queue_t)qu
self = [super init];
if (self) {
_execBlock = [block copy];
_dispatch = [CODispatch currentDispatch];
_dispatch = queue ? [CODispatch dispatchWithQueue:queue] : [CODispatch currentDispatch];
//_queue = queue ?: co_get_current_queue();

coroutine_t *co = coroutine_create((void (*)(void *))co_exec);
Expand Down

0 comments on commit f6c689a

Please sign in to comment.