code / tomo-http-server

Lines215 Tomo159 HTML21 Markdown14 CSS11 INI9
1 others 1
Text1
(25 lines)
1 use pthreads
3 func _assert_success(name:Text, val:Int32; inline)
4 fail("$name() failed!") if val < 0
6 struct ConnectionQueue(_connections:@[Int32]=@[], _mutex=Mutex.new(), _cond=Condition.new())
7 func enqueue(queue:ConnectionQueue, connection:Int32)
8 queue._mutex.lock()
9 queue._connections.insert(connection)
10 queue._mutex.unlock()
11 queue._cond.signal()
14 func dequeue(queue:ConnectionQueue -> Int32)
15 conn : Int32?
17 queue._mutex.lock()
19 while queue._connections.length == 0
20 queue._cond.wait(queue._mutex)
22 conn = queue._connections.pop(1)
23 queue._mutex.unlock()
24 queue._cond.signal()
25 return conn!