@@ -35,29 +35,29 @@ private let pt_entry: @objc_block (UnsafeMutablePointer<Void>) -> UnsafeMutableP
35
35
}
36
36
private var pt_entry_imp = imp_implementationWithBlock ( unsafeBitCast ( pt_entry, AnyObject . self) )
37
37
private let pt_entry_fp = CFunctionPointer < ( UnsafeMutablePointer < Void > ) -> UnsafeMutablePointer < Void > > ( pt_entry_imp)
38
- func dispatch_thread( block : ( ) -> ( ) ) {
38
+ public func dispatch_thread( block : ( ) -> ( ) ) {
39
39
let p = UnsafeMutablePointer < ( ) -> ( ) > . alloc ( 1 )
40
40
p. initialize ( block)
41
41
var t = pthread_t ( )
42
42
pthread_create ( & t, nil , pt_entry_fp, p)
43
43
pthread_detach ( t)
44
44
}
45
- protocol Locker {
45
+ public protocol Locker {
46
46
func lock( )
47
47
func unlock( )
48
48
}
49
- class Mutex : Locker {
49
+ public class Mutex : Locker {
50
50
private var mutex = pthread_mutex_t ( )
51
51
init ( ) {
52
52
pthread_mutex_init ( & mutex, nil )
53
53
}
54
54
deinit {
55
55
pthread_mutex_destroy ( & mutex)
56
56
}
57
- func lock( ) {
57
+ public func lock( ) {
58
58
pthread_mutex_lock ( & mutex)
59
59
}
60
- func unlock( ) {
60
+ public func unlock( ) {
61
61
pthread_mutex_unlock ( & mutex)
62
62
}
63
63
func lock( closure: ( ) -> ( ) ) {
@@ -66,7 +66,7 @@ class Mutex : Locker {
66
66
unlock ( )
67
67
}
68
68
}
69
- class Cond {
69
+ public class Cond {
70
70
private var cond = pthread_cond_t ( )
71
71
private var mutex : Mutex
72
72
init ( locker : Locker ) {
@@ -94,7 +94,7 @@ class Cond {
94
94
pthread_cond_wait ( & cond, & mutex. mutex)
95
95
}
96
96
}
97
- class Once {
97
+ public class Once {
98
98
private var mutex = Mutex ( )
99
99
private var oncer = false
100
100
func doit( closure: ( ) -> ( ) ) {
@@ -108,7 +108,7 @@ class Once {
108
108
mutex. unlock ( )
109
109
}
110
110
}
111
- class WaitGroup {
111
+ public class WaitGroup {
112
112
private var cond = Cond ( locker: Mutex ( ) )
113
113
private var count = 0
114
114
func add( delta : Int ) {
@@ -131,15 +131,15 @@ class WaitGroup {
131
131
cond. locker. unlock ( )
132
132
}
133
133
}
134
- protocol ChanAny {
134
+ public protocol ChanAny {
135
135
func receive( wait : Bool , mutex : Mutex ? , inout flag : Bool ) -> ( msg : Any ? , ok : Bool , ready : Bool )
136
136
func send( msg : Any ? )
137
137
func close( )
138
138
func signal( )
139
139
func count( ) -> Int
140
140
func capacity( ) -> Int
141
141
}
142
- class Chan < T> : ChanAny {
142
+ public class Chan < T> : ChanAny {
143
143
private var msgs = [ Any? ] ( )
144
144
private var cap = 0
145
145
private var cond = Cond ( locker: Mutex ( ) )
@@ -151,24 +151,24 @@ class Chan<T> : ChanAny {
151
151
init ( buffer: Int ) {
152
152
cap = buffer
153
153
}
154
- func count( ) -> Int {
154
+ public func count( ) -> Int {
155
155
if cap == 0 {
156
156
return 0
157
157
}
158
158
return msgs. count
159
159
}
160
- func capacity( ) -> Int {
160
+ public func capacity( ) -> Int {
161
161
return cap
162
162
}
163
- func close( ) {
163
+ public func close( ) {
164
164
cond. locker. lock ( )
165
165
if !closed {
166
166
closed = true
167
167
cond. broadcast ( )
168
168
}
169
169
cond. locker. unlock ( )
170
170
}
171
- func send( msg: Any ? ) {
171
+ public func send( msg: Any ? ) {
172
172
cond. locker. lock ( )
173
173
if closed {
174
174
cond. locker. unlock ( )
@@ -181,7 +181,7 @@ class Chan<T> : ChanAny {
181
181
}
182
182
cond. locker. unlock ( )
183
183
}
184
- func receive( wait : Bool , mutex : Mutex ? , inout flag : Bool ) -> ( msg : Any ? , ok : Bool , ready : Bool ) {
184
+ public func receive( wait : Bool , mutex : Mutex ? , inout flag : Bool ) -> ( msg : Any ? , ok : Bool , ready : Bool ) {
185
185
// Peek
186
186
if !wait {
187
187
cond. locker. lock ( )
@@ -242,33 +242,33 @@ class Chan<T> : ChanAny {
242
242
cond. wait ( )
243
243
}
244
244
}
245
- func signal( ) {
245
+ public func signal( ) {
246
246
cond. broadcast ( )
247
247
}
248
248
}
249
249
infix operator <- { associativity right precedence 155 }
250
250
prefix operator <- { }
251
251
prefix operator <? { }
252
- func <- < T> ( l: Chan < T > , r: T ? ) {
252
+ public func <- < T> ( l: Chan < T > , r: T ? ) {
253
253
l. send ( r)
254
254
}
255
- prefix func <? < T> ( r: Chan < T > ) -> ( T ? , Bool ) {
255
+ public prefix func <? < T> ( r: Chan < T > ) -> ( T ? , Bool ) {
256
256
var flag = false
257
257
let ( v, ok, ready) = r. receive ( true , mutex: nil , flag: & flag)
258
258
return ( v as? T , ok)
259
259
}
260
- prefix func <- < T> ( r: Chan < T > ) -> T ? {
260
+ public prefix func <- < T> ( r: Chan < T > ) -> T ? {
261
261
var flag = false
262
262
let ( v, ok, ready) = r. receive ( true , mutex: nil , flag: & flag)
263
263
return v as? T
264
264
}
265
- func close< T> ( chan : Chan < T > ) {
265
+ public func close< T> ( chan : Chan < T > ) {
266
266
chan. close ( )
267
267
}
268
- func len< T> ( chan : Chan < T > ) -> Int {
268
+ public func len< T> ( chan : Chan < T > ) -> Int {
269
269
return chan. count ( )
270
270
}
271
- func cap< T> ( chan : Chan < T > ) -> Int {
271
+ public func cap< T> ( chan : Chan < T > ) -> Int {
272
272
return chan. capacity ( )
273
273
}
274
274
private struct GoPanicError {
@@ -489,27 +489,27 @@ private class GoApp {
489
489
}
490
490
}
491
491
private let goapp = GoApp ( )
492
- func $( closure: ( ) - > ( ) ) {
492
+ public func $( closure: ( ) - > ( ) ) {
493
493
goapp. routine ( ) . $( closure)
494
494
}
495
- func go( closure: ( ) -> ( ) ) {
495
+ public func go( closure: ( ) -> ( ) ) {
496
496
goapp. go ( closure)
497
497
}
498
- func defer( file : StaticString = __FILE__, line : UWord = __LINE__, closure: ( ) -> ( ) ) {
498
+ public func defer( file : StaticString = __FILE__, line : UWord = __LINE__, closure: ( ) -> ( ) ) {
499
499
goapp. routine ( ) . defer ( file: file, line: line, closure: closure)
500
500
}
501
- func panic( what : AnyObject , file : StaticString = __FILE__, line : UWord = __LINE__) {
501
+ public func panic( what : AnyObject , file : StaticString = __FILE__, line : UWord = __LINE__) {
502
502
goapp. routine ( ) . panic ( what, file: file, line: line)
503
503
}
504
- func recover( file : StaticString = __FILE__, line : UWord = __LINE__) -> AnyObject ? {
504
+ public func recover( file : StaticString = __FILE__, line : UWord = __LINE__) -> AnyObject ? {
505
505
return goapp. routine ( ) . recover ( file: file, line: line)
506
506
}
507
- func select( file : StaticString = __FILE__, line : UWord = __LINE__, closure: ( ) -> ( ) ) {
507
+ public func select( file : StaticString = __FILE__, line : UWord = __LINE__, closure: ( ) -> ( ) ) {
508
508
goapp. routine ( ) . select ( file: file, line: line, closure: closure)
509
509
}
510
- func _case< T> ( l : Chan < T > , file : StaticString = __FILE__, line : UWord = __LINE__, closure: ( msg : T ? , ok : Bool ) -> ( ) ) {
510
+ public func _case< T> ( l : Chan < T > , file : StaticString = __FILE__, line : UWord = __LINE__, closure: ( msg : T ? , ok : Bool ) -> ( ) ) {
511
511
goapp. routine ( ) . case_ ( l, file: file, line: line, closure: { ( msg, ok) in closure ( msg: msg as? T , ok: ok) } )
512
512
}
513
- func _default( file : StaticString = __FILE__, line : UWord = __LINE__, closure: ( ) -> ( ) ) {
513
+ public func _default( file : StaticString = __FILE__, line : UWord = __LINE__, closure: ( ) -> ( ) ) {
514
514
goapp. routine ( ) . default_ ( file: file, line: line, closure: closure)
515
515
}
0 commit comments