Skip to content

Commit

Permalink
Merge branch 'hotfix/v3.2.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
mplatvoet committed Mar 30, 2016
2 parents b294bfa + e891a61 commit 437800e
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 20 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ task { "world" } and task { "Hello" } success {
Please refer to the [Kovenant](http://kovenant.komponents.nl) site for API usage and more.

## Getting started
Build against Kotlin: `1.0.1`.
Build against Kotlin: `1.0.1-1`.
Source and target compatibility is `1.6`

###Gradle
```groovy
dependencies {
compile 'nl.komponents.kovenant:kovenant:3.2.0'
compile 'nl.komponents.kovenant:kovenant:3.2.1'
}
```

Expand All @@ -32,7 +32,7 @@ dependencies {
<dependency>
<groupId>nl.komponents.kovenant</groupId>
<artifactId>kovenant</artifactId>
<version>3.2.0</version>
<version>3.2.1</version>
</dependency>
```

Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/

buildscript {
ext.kotlinVersion = '1.0.1'
ext.kotlinVersion = '1.0.1-1'
ext.extraConfVersion = '2.2.+'

repositories {
Expand All @@ -39,7 +39,7 @@ buildscript {

allprojects {
ext {
appVersion = '3.2.0'
appVersion = '3.2.1'
appGroup = 'nl.komponents.kovenant'


Expand Down
6 changes: 6 additions & 0 deletions docs/docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
Changelog of Kovenant. Complying to [Semantic Versioning](http://semver.org).
Please refer to [roadmap](roadmap.md) for upcoming releases.

##v3.2.1

**core**

* [KOV-78](http://issues.komponents.nl/youtrack/issue/KOV-78) Support android with api level set to 15

##v3.2.0

**core**
Expand Down
6 changes: 3 additions & 3 deletions docs/docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ Developed with the following [goals](misc/goals.md) in mind.
* **Dependency free**: when not counting kotlin std

## Getting started
Build against Kotlin: `1.0.1`.
Build against Kotlin: `1.0.1-1`.
Source and target compatibility is `1.6`

###Gradle
```groovy
dependencies {
compile 'nl.komponents.kovenant:kovenant:3.2.0'
compile 'nl.komponents.kovenant:kovenant:3.2.1'
}
```

Expand All @@ -40,7 +40,7 @@ dependencies {
<dependency>
<groupId>nl.komponents.kovenant</groupId>
<artifactId>kovenant</artifactId>
<version>3.2.0</version>
<version>3.2.1</version>
</dependency>
```

Expand Down
73 changes: 62 additions & 11 deletions projects/core/src/main/kotlin/cas-jvm.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
/*
* Copyright (c) 2016 Mark Platvoet<[email protected]>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* THE SOFTWARE.
*/

package nl.komponents.kovenant.unsafe

import sun.misc.Unsafe
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater
import kotlin.reflect.KClass

Expand Down Expand Up @@ -29,23 +49,54 @@ class UnsafeAtomicReferenceFieldUpdater<C : Any, V : Any>(targetClass: KClass<C>
override fun weakCompareAndSet(target: C, expected: V?, update: V?): Boolean = compareAndSet(target, expected, update)
}

private val noUnsafeMarker = Any()
private @Volatile var unsafeInstance: Any? = null

fun hasUnsafe(): Boolean {
try {
Class.forName("sun.misc.Unsafe")
return true
} catch(e: ClassNotFoundException) {
return false
if (unsafeInstance == null) {
loadUnsafe()
}
return unsafeInstance != noUnsafeMarker
}

private fun getUnsafe(): Unsafe {
private fun loadUnsafe() {
try {
val field = Unsafe::class.java.getDeclaredField("theUnsafe");
field.isAccessible = true;
return field.get(null) as Unsafe;
val clazz = Class.forName("sun.misc.Unsafe")

clazz.tryGetStaticField("theUnsafe") {
unsafeInstance = it ?: noUnsafeMarker
return
}

//KOV-78: Name on old dalvik implementations
clazz.tryGetStaticField("THE_ONE") {
unsafeInstance = it ?: noUnsafeMarker
return
}
} catch(e: Exception) {
//ignore
}
unsafeInstance = noUnsafeMarker
}

private inline fun Class<*>.tryGetStaticField(name: String, onFound: (Any?) -> Unit) {
try {
val field = getDeclaredField(name)
field.isAccessible = true
val fieldValue = field.get(null)
onFound(fieldValue)
} catch (e: Exception) {
throw RuntimeException("unsafe doesn't exist or is not accessible")
//ignore
}
}

private fun getUnsafe(): sun.misc.Unsafe {
if (unsafeInstance == null) {
loadUnsafe()
}
if (unsafeInstance != noUnsafeMarker) {
return unsafeInstance as sun.misc.Unsafe
}

throw RuntimeException("unsafe doesn't exist or is not accessible")
}
2 changes: 1 addition & 1 deletion projects/rx/rx.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ project.description = "Add Promise support to Rx"

dependencies {
compile project(':kovenant-core')
compile 'io.reactivex:rxjava:1.1.1'
compile 'io.reactivex:rxjava:1.1.2'
}

0 comments on commit 437800e

Please sign in to comment.