Skip to content
This repository has been archived by the owner on Jun 19, 2019. It is now read-only.

Commit

Permalink
Now builds on Ubuntu
Browse files Browse the repository at this point in the history
  • Loading branch information
ssoper committed Jan 7, 2016
1 parent 0381710 commit 5be3df3
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -46,3 +46,6 @@ xcuserdata
# Carthage/Checkouts

Carthage/Build

# Swift
.build
1 change: 1 addition & 0 deletions .swift-version
@@ -0,0 +1 @@
swift-2.2-SNAPSHOT-2015-12-31-a
7 changes: 7 additions & 0 deletions Dockerfile
@@ -0,0 +1,7 @@
FROM swiftdocker/swift

# Build the app
ADD Package.swift /data/app/
ADD Source/*.swift /data/app/Source/
WORKDIR /data/app/
RUN swift build -c release
7 changes: 7 additions & 0 deletions Package.swift
@@ -0,0 +1,7 @@
import PackageDescription

let package = Package(
name: "Safe",
targets: [],
dependencies: []
)
8 changes: 5 additions & 3 deletions Source/chan.swift
Expand Up @@ -42,7 +42,8 @@ public class Chan<T> : SequenceType {
public init(_ capacity: Int = 0){
cap = capacity
idMutex.lock()
id = ++idCounter
idCounter += 1
id = idCounter
idMutex.unlock()
}
/// The number of elements queued (unread) in the channel buffer
Expand Down Expand Up @@ -81,7 +82,8 @@ public class Chan<T> : SequenceType {
cond.mutex.lock()
defer { cond.mutex.unlock() }
if closed {
NSException.raise("Exception", format: "send on closed channel", arguments: getVaList([]))
assertionFailure("Send on closed channel")
// NSException.raise("Exception", format: "send on closed channel", arguments: getVaList([]))
}
msgs.append(msg)
broadcast()
Expand Down Expand Up @@ -109,7 +111,7 @@ public class Chan<T> : SequenceType {
}
public typealias Generator = AnyGenerator<T>
public func generate() -> Generator {
return anyGenerator {
return AnyGenerator {
return <-self
}
}
Expand Down
4 changes: 4 additions & 0 deletions Source/dispatch.swift
Expand Up @@ -14,6 +14,10 @@
* http://golang.org/ref/spec
*/

#if os(Linux)
import Glibc
#endif

import Foundation

private let pt_entry: @convention(c) (UnsafeMutablePointer<Void>) -> UnsafeMutablePointer<Void> = { (ctx) in
Expand Down
15 changes: 12 additions & 3 deletions Source/select.swift
Expand Up @@ -8,6 +8,10 @@
* of the MIT license. See the LICENSE file for details.
*/

#if os(Linux)
import Glibc
#endif

import Foundation

private protocol ItemAny {
Expand Down Expand Up @@ -37,7 +41,7 @@ private class Item<T> : ItemAny {
if let chan = chan {
chan.cond.mutex.lock()
defer { chan.cond.mutex.unlock() }
for var i = 0; i < chan.gconds.count; i++ {
for i in 0...chan.gconds.count {
if chan.gconds[i] === cond {
chan.gconds.removeAtIndex(i)
return
Expand Down Expand Up @@ -121,11 +125,16 @@ private class ChanGroup {
}
func randomInts(count : Int) -> [Int]{
var ints = [Int](count: count, repeatedValue:0)
for var i = 0; i < count; i++ {
for i in 0...count {
ints[i] = i
}
for var i = 0; i < count; i++ {
for i in 0...count {
#if os(Linux)
let r = Int(random()) % count
#else
let r = Int(arc4random()) % count
#endif

let t = ints[i]
ints[i] = ints[r]
ints[r] = t
Expand Down
7 changes: 6 additions & 1 deletion Source/sync.swift
Expand Up @@ -14,6 +14,10 @@
* http://golang.org/pkg/sync/
*/

#if os(Linux)
import Glibc
#endif

import Foundation

/// The WaitResult enum is used as a return value by Mutex.wait()
Expand Down Expand Up @@ -178,7 +182,8 @@ public class WaitGroup {
defer { cond.mutex.unlock() }
count += delta
if count < 0 {
NSException.raise("Exception", format: "negative WaitGroup counter", arguments: getVaList([]))
assertionFailure("negative WaitGroup counter")
// NSException.raise("Exception", format: "negative WaitGroup counter", arguments: getVaList([]))
}
cond.broadcast()
}
Expand Down

0 comments on commit 5be3df3

Please sign in to comment.