Skip to content

Commit

Permalink
Change SNTP cache mutating methods to be synchronized (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
arturdryomov authored Nov 23, 2020
1 parent 21fa5b8 commit 789936c
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ internal interface SntpResponseCache {
fun clear()
}

internal class SntpResponseCacheImpl(private val syncResponseCache: SyncResponseCache, private val deviceClock: Clock) : SntpResponseCache {
internal class SntpResponseCacheImpl(
private val syncResponseCache: SyncResponseCache,
private val deviceClock: Clock,
) : SntpResponseCache {

override fun get(): SntpClient.Response? {
val currentTime = syncResponseCache.currentTime
Expand All @@ -26,12 +29,16 @@ internal class SntpResponseCacheImpl(private val syncResponseCache: SyncResponse
}

override fun update(response: SntpClient.Response) {
syncResponseCache.currentTime = response.deviceCurrentTimestampMs
syncResponseCache.elapsedTime = response.deviceElapsedTimestampMs
syncResponseCache.currentOffset = response.offsetMs
synchronized(this) {
syncResponseCache.currentTime = response.deviceCurrentTimestampMs
syncResponseCache.elapsedTime = response.deviceElapsedTimestampMs
syncResponseCache.currentOffset = response.offsetMs
}
}

override fun clear() {
syncResponseCache.clear()
synchronized(this) {
syncResponseCache.clear()
}
}
}

0 comments on commit 789936c

Please sign in to comment.