Skip to content

Commit 9157958

Browse files
committed
Some further updates for the layered cache.
1 parent 9723b16 commit 9157958

File tree

10 files changed

+149
-131
lines changed

10 files changed

+149
-131
lines changed

serialization/api/serialization.api

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public final class nl/adaptivity/xmlutil/serialization/AnnotationsKt {
1313
public final class nl/adaptivity/xmlutil/serialization/DefaultFormatCache : nl/adaptivity/xmlutil/serialization/FormatCache, nl/adaptivity/xmlutil/serialization/DelegatableFormatCache {
1414
public fun <init> ()V
1515
public fun <init> (I)V
16+
public synthetic fun appendFrom (Lnl/adaptivity/xmlutil/serialization/DefaultFormatCache;)Lnl/adaptivity/xmlutil/serialization/DelegatableFormatCache;
1617
public fun copy ()Lnl/adaptivity/xmlutil/serialization/DefaultFormatCache;
1718
public synthetic fun copy ()Lnl/adaptivity/xmlutil/serialization/DelegatableFormatCache;
1819
public synthetic fun copy$serialization ()Lnl/adaptivity/xmlutil/serialization/FormatCache;
@@ -125,9 +126,13 @@ public abstract class nl/adaptivity/xmlutil/serialization/InputKind : java/lang/
125126
}
126127

127128
public final class nl/adaptivity/xmlutil/serialization/LayeredCache : nl/adaptivity/xmlutil/serialization/FormatCache {
129+
public static final field Companion Lnl/adaptivity/xmlutil/serialization/LayeredCache$Companion;
128130
public fun <init> ()V
129131
}
130132

133+
public final class nl/adaptivity/xmlutil/serialization/LayeredCache$Companion {
134+
}
135+
131136
public class nl/adaptivity/xmlutil/serialization/OutputKind : java/lang/Enum {
132137
public static final field Attribute Lnl/adaptivity/xmlutil/serialization/OutputKind;
133138
public static final field Element Lnl/adaptivity/xmlutil/serialization/OutputKind;

serialization/api/serialization.klib.api

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,8 @@ final class nl.adaptivity.xmlutil.serialization/DefaultFormatCache : nl.adaptivi
622622

623623
final class nl.adaptivity.xmlutil.serialization/LayeredCache : nl.adaptivity.xmlutil.serialization/FormatCache { // nl.adaptivity.xmlutil.serialization/LayeredCache|null[0]
624624
constructor <init>() // nl.adaptivity.xmlutil.serialization/LayeredCache.<init>|<init>(){}[0]
625+
626+
final object Companion // nl.adaptivity.xmlutil.serialization/LayeredCache.Companion|null[0]
625627
}
626628

627629
final class nl.adaptivity.xmlutil.serialization/PolyInfo { // nl.adaptivity.xmlutil.serialization/PolyInfo|null[0]

serialization/src/commonMain/kotlin/nl/adaptivity/xmlutil/serialization/LayeredCache.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import nl.adaptivity.xmlutil.Namespace
2626
import nl.adaptivity.xmlutil.QName
2727
import nl.adaptivity.xmlutil.namespaceURI
2828
import nl.adaptivity.xmlutil.serialization.impl.CompatLock
29+
import nl.adaptivity.xmlutil.serialization.impl.invoke
2930
import nl.adaptivity.xmlutil.serialization.structure.*
3031

3132
public class LayeredCache private constructor(
@@ -235,4 +236,8 @@ public class LayeredCache private constructor(
235236
}
236237

237238
}
239+
240+
public companion object {
241+
private val MULTI_TREAD_MARKER: Any = Any()
242+
}
238243
}
Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
/*
2-
* Copyright (c) 2022.
2+
* Copyright (c) 2022-2025.
33
*
44
* This file is part of xmlutil.
55
*
6-
* This file is licenced to you under the Apache License, Version 2.0 (the
7-
* "License"); you may not use this file except in compliance
8-
* with the License. You should have received a copy of the license with the source distribution.
9-
* Alternatively, you may obtain a copy of the License at
6+
* This file is licenced to you under the Apache License, Version 2.0
7+
* (the "License"); you may not use this file except in compliance
8+
* with the License. You should have received a copy of the license
9+
* with the source distribution. Alternatively, you may obtain a copy
10+
* of the License at
1011
*
1112
* http://www.apache.org/licenses/LICENSE-2.0
1213
*
13-
* Unless required by applicable law or agreed to in writing,
14-
* software distributed under the License is distributed on an
15-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16-
* KIND, either express or implied. See the License for the
17-
* specific language governing permissions and limitations
18-
* under the License.
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
17+
* implied. See the License for the specific language governing
18+
* permissions and limitations under the License.
1919
*/
2020

2121
package nl.adaptivity.xmlutil.serialization.impl
@@ -24,6 +24,8 @@ import kotlin.reflect.KClass
2424

2525
internal expect val KClass<*>.maybeSerialName: String?
2626

27-
internal expect class CompatLock() {
28-
internal operator fun <R> invoke(action: () -> R): R
29-
}
27+
internal expect class CompatLock()
28+
29+
internal expect inline fun <R> CompatLock.invoke(action: () -> R): R
30+
31+
internal expect fun currentThreadId(): Any
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
/*
2-
* Copyright (c) 2022.
2+
* Copyright (c) 2022-2025.
33
*
44
* This file is part of xmlutil.
55
*
6-
* This file is licenced to you under the Apache License, Version 2.0 (the
7-
* "License"); you may not use this file except in compliance
8-
* with the License. You should have received a copy of the license with the source distribution.
9-
* Alternatively, you may obtain a copy of the License at
6+
* This file is licenced to you under the Apache License, Version 2.0
7+
* (the "License"); you may not use this file except in compliance
8+
* with the License. You should have received a copy of the license
9+
* with the source distribution. Alternatively, you may obtain a copy
10+
* of the License at
1011
*
1112
* http://www.apache.org/licenses/LICENSE-2.0
1213
*
13-
* Unless required by applicable law or agreed to in writing,
14-
* software distributed under the License is distributed on an
15-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16-
* KIND, either express or implied. See the License for the
17-
* specific language governing permissions and limitations
18-
* under the License.
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
17+
* implied. See the License for the specific language governing
18+
* permissions and limitations under the License.
1919
*/
2020

2121
package nl.adaptivity.xmlutil.serialization.impl
@@ -33,7 +33,7 @@ internal actual val KClass<*>.maybeSerialName: String?
3333
?: name.replace('$', '.')
3434

3535
/** Dummy implementation as there are no locks in Javascript */
36-
internal actual class CompatLock {
37-
internal actual operator fun <R> invoke(action: () -> R): R = action()
38-
}
36+
internal actual class CompatLock
3937

38+
internal actual inline fun <R> CompatLock.invoke(action: () -> R): R = action()
39+
internal actual fun currentThreadId(): Any = 1
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright (c) 2025.
3+
*
4+
* This file is part of xmlutil.
5+
*
6+
* This file is licenced to you under the Apache License, Version 2.0
7+
* (the "License"); you may not use this file except in compliance
8+
* with the License. You should have received a copy of the license
9+
* with the source distribution. Alternatively, you may obtain a copy
10+
* of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
17+
* implied. See the License for the specific language governing
18+
* permissions and limitations under the License.
19+
*/
20+
21+
package nl.adaptivity.xmlutil.serialization.impl
22+
23+
import kotlinx.serialization.ExperimentalSerializationApi
24+
import kotlinx.serialization.InternalSerializationApi
25+
import kotlinx.serialization.serializerOrNull
26+
import java.util.concurrent.locks.ReentrantLock
27+
import kotlin.reflect.KClass
28+
29+
@OptIn(InternalSerializationApi::class, ExperimentalSerializationApi::class)
30+
internal actual val KClass<*>.maybeSerialName: String?
31+
get() = this.serializerOrNull()
32+
?.run { descriptor.serialName }
33+
?: qualifiedName
34+
35+
internal actual class CompatLock {
36+
internal val lock = ReentrantLock()
37+
}
38+
39+
internal actual inline fun <R> CompatLock.invoke(action: () -> R): R {
40+
lock.lock()
41+
try {
42+
return action()
43+
} finally {
44+
lock.unlock()
45+
}
46+
}
47+
48+
internal actual fun currentThreadId(): Any = Thread.currentThread().threadId()

serialization/src/jvmMain/kotlin/nl/adaptivity/xmlutil/serialization/impl/compatJava.kt

Lines changed: 0 additions & 47 deletions
This file was deleted.
Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
/*
2-
* Copyright (c) 2022.
2+
* Copyright (c) 2022-2025.
33
*
44
* This file is part of xmlutil.
55
*
6-
* This file is licenced to you under the Apache License, Version 2.0 (the
7-
* "License"); you may not use this file except in compliance
8-
* with the License. You should have received a copy of the license with the source distribution.
9-
* Alternatively, you may obtain a copy of the License at
6+
* This file is licenced to you under the Apache License, Version 2.0
7+
* (the "License"); you may not use this file except in compliance
8+
* with the License. You should have received a copy of the license
9+
* with the source distribution. Alternatively, you may obtain a copy
10+
* of the License at
1011
*
1112
* http://www.apache.org/licenses/LICENSE-2.0
1213
*
13-
* Unless required by applicable law or agreed to in writing,
14-
* software distributed under the License is distributed on an
15-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16-
* KIND, either express or implied. See the License for the
17-
* specific language governing permissions and limitations
18-
* under the License.
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
17+
* implied. See the License for the specific language governing
18+
* permissions and limitations under the License.
1919
*/
2020

2121
package nl.adaptivity.xmlutil.serialization.impl
@@ -24,6 +24,7 @@ import kotlinx.atomicfu.locks.ReentrantLock
2424
import kotlinx.serialization.ExperimentalSerializationApi
2525
import kotlinx.serialization.InternalSerializationApi
2626
import kotlinx.serialization.serializerOrNull
27+
import platform.posix.pthread_self
2728
import kotlin.reflect.KClass
2829

2930
@OptIn(InternalSerializationApi::class, ExperimentalSerializationApi::class)
@@ -33,14 +34,16 @@ internal actual val KClass<*>.maybeSerialName: String?
3334
?: qualifiedName
3435

3536
internal actual class CompatLock {
36-
private val lock = ReentrantLock()
37-
internal actual operator fun <R> invoke(action: () -> R): R {
38-
lock.lock()
39-
try {
40-
return action()
41-
} finally {
42-
lock.unlock()
43-
}
37+
internal val lock = ReentrantLock()
38+
}
39+
40+
internal actual inline fun <R> CompatLock.invoke(action: () -> R): R {
41+
lock.lock()
42+
try {
43+
return action()
44+
} finally {
45+
lock.unlock()
4446
}
4547
}
4648

49+
internal actual fun currentThreadId(): Any = pthread_self()
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (c) 2025.
3+
*
4+
* This file is part of xmlutil.
5+
*
6+
* This file is licenced to you under the Apache License, Version 2.0
7+
* (the "License"); you may not use this file except in compliance
8+
* with the License. You should have received a copy of the license
9+
* with the source distribution. Alternatively, you may obtain a copy
10+
* of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
17+
* implied. See the License for the specific language governing
18+
* permissions and limitations under the License.
19+
*/
20+
21+
package nl.adaptivity.xmlutil.serialization.impl
22+
23+
import kotlinx.serialization.ExperimentalSerializationApi
24+
import kotlinx.serialization.InternalSerializationApi
25+
import kotlinx.serialization.serializerOrNull
26+
import kotlin.reflect.KClass
27+
28+
// TODO note that wasm doesn't yet support reflection so names are not available
29+
@OptIn(InternalSerializationApi::class, ExperimentalSerializationApi::class)
30+
internal actual val KClass<*>.maybeSerialName: String?
31+
get() = serializerOrNull()
32+
?.run { descriptor.serialName }
33+
34+
internal actual class CompatLock
35+
36+
internal actual inline fun <R> CompatLock.invoke(action: () -> R): R = action()
37+
internal actual fun currentThreadId(): Any = 1

serialization/src/wasmCommonMain/kotlin/nl/adaptivity/xmlutil/serialization/impl/compat.wasmJs.kt

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)