move uint64s to beginning of struct to ensure they are 64-bit aligned

See https://golang.org/pkg/sync/atomic/#pkg-note-BUG for reference:
"The first word in (...) an allocated struct (...) can be relied up to
be 64-bit aligned"

This fixes an "unaligned 64-bit atomic operation" panic on 32-bit ARM,
(in my case a Raspberry Pi 4, running 32-bit Raspbian). The panic
happens (at least) during the first login after a service (re)start.
This commit is contained in:
Wilko Nienhaus
2021-04-02 10:35:29 +03:00
parent f6ad814332
commit 011c6b76ee
2 changed files with 10 additions and 2 deletions
@@ -0,0 +1,7 @@
Bugfix: Fixes "unaligned 64-bit atomic operation" panic on 32-bit ARM
sync/cache had uint64s that were not 64-bit aligned causing panics
on 32-bit systems during atomic access
https://github.com/owncloud/ocis/pull/1888
https://github.com/owncloud/ocis/issues/1887
+3 -2
View File
@@ -8,10 +8,11 @@ import (
// Cache is a barebones cache implementation.
type Cache struct {
// capacity and length have to be the first words
// in order to be 64-aligned on 32-bit architectures.
capacity, length uint64 // access atomically
entries sync.Map
pool sync.Pool
capacity uint64
length uint64
}
// CacheEntry represents an entry on the cache. You can type assert on V.