Skip to content

Commit 2653e6a

Browse files
committed
dispatch: Add CreateQueue, Main
1 parent 53e6adf commit 2653e6a

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

dispatch/queue.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ package dispatch
99
// void Dispatch_Release(void* queue);
1010
// void Dispatch_Async(void* queue, uintptr_t task);
1111
// void Dispatch_Sync(void* queue, uintptr_t task);
12-
// void* Dispatch_Create_Queue(const char* label, void* attr);
12+
// void* Dispatch_Create_Queue(const char* label, int type);
13+
// void Dispatch_Main();
1314
import "C"
1415
import (
1516
"math"
@@ -31,6 +32,13 @@ const (
3132
QueuePriorityBackground QueuePriority = math.MinInt16
3233
)
3334

35+
type QueueType int
36+
37+
const (
38+
QueueTypeSerial QueueType = 0
39+
QueueTypeConcurrent QueueType = 1
40+
)
41+
3442
// Returns the serial dispatch queue associated with the application’s main thread. [Full Topic]
3543
//
3644
// [Full Topic]: https://developer.apple.com/documentation/dispatch/1452921-dispatch_get_main_queue?language=objc
@@ -75,11 +83,16 @@ func runQueueTask(p C.uintptr_t) {
7583
h.Delete()
7684
}
7785

86+
// Main executes blocks submitted to the main queue.
87+
func Main() {
88+
C.Dispatch_Main()
89+
}
90+
7891
// Creates a new dispatch queue to which blocks can be submitted.
7992
//
8093
// [Full Topic]: https://developer.apple.com/documentation/dispatch/1453030-dispatch_queue_create?language=objc
81-
func CreateQueue(label string, attr uintptr) Queue {
94+
func CreateQueue(label string, queueType QueueType) Queue {
8295
cLabel := C.CString(label)
83-
p := C.Dispatch_Create_Queue(cLabel, unsafe.Pointer(attr))
96+
p := C.Dispatch_Create_Queue(cLabel, C.int(queueType))
8497
return Queue{p}
8598
}

dispatch/queue.m

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,13 @@ void Dispatch_Sync(void* queue, uintptr_t task) {
3333
});
3434
}
3535

36-
void* Dispatch_Create_Queue(const char* label, void* attr) {
37-
dispatch_queue_t queue = dispatch_queue_create(label, attr);
38-
return queue;
36+
void Dispatch_Main() {
37+
dispatch_main();
38+
}
39+
40+
void* Dispatch_Create_Queue(const char* label, int type) {
41+
if (type == 0) {
42+
return dispatch_queue_create(label, DISPATCH_QUEUE_SERIAL);
43+
}
44+
return dispatch_queue_create(label, DISPATCH_QUEUE_CONCURRENT);
3945
}

0 commit comments

Comments
 (0)