git.fiddlerwoaroof.com
Browse code

Add GCD functions

Ed Langley authored on 14/08/2018 01:21:10
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,38 @@
1
+(defpackage :objc-runtime.gcd
2
+  (:use :cl :cffi)
3
+  (:export ))
4
+(in-package :objc-runtime.gcd)
5
+
6
+(serapeum:eval-always
7
+  (pushnew #p"/usr/lib/system/"
8
+           cffi:*foreign-library-directories*
9
+           :test 'equal))
10
+
11
+(serapeum:eval-always
12
+  (define-foreign-library dispatch
13
+    (:darwin "libdispatch.dylib")))
14
+
15
+(defcfun
16
+    (get-global-queue "dispatch_get_global_queue" :library dispatch)
17
+    :pointer
18
+  (id :long)
19
+  (flags :unsigned-long))
20
+
21
+(defun get-main-queue ()
22
+  (cffi:foreign-symbol-pointer "_dispatch_main_q"))
23
+
24
+(defcfun (dispatch-async "dispatch_async_f" :library dispatch)
25
+    :pointer
26
+  (queue :pointer)
27
+  (context :pointer)
28
+  (block :pointer))
29
+
30
+(defmacro def-gcd-callback (name (context-sym) &body body)
31
+  `(progn
32
+     (defcallback ,name :void ((,context-sym :pointer))
33
+       (declare (ignorable ,context-sym))
34
+       ,@body)
35
+     (define-symbol-macro ,name (callback ,name))))
36
+
37
+(def-gcd-callback foo-callback (context)
38
+  (demo-app::show-alert "Uh-oh"))