shm.go

 1//go:build ((linux || darwin || windows || freebsd || openbsd || netbsd || dragonfly || illumos) && (386 || arm || amd64 || arm64 || riscv64 || ppc64le)) || sqlite3_flock || sqlite3_dotlk
 2
 3package vfs
 4
 5// SupportsSharedMemory is false on platforms that do not support shared memory.
 6// To use [WAL without shared-memory], you need to set [EXCLUSIVE locking mode].
 7//
 8// [WAL without shared-memory]: https://sqlite.org/wal.html#noshm
 9// [EXCLUSIVE locking mode]: https://sqlite.org/pragma.html#pragma_locking_mode
10const SupportsSharedMemory = true
11
12func (f *vfsFile) SharedMemory() SharedMemory { return f.shm }
13
14// NewSharedMemory returns a shared-memory WAL-index
15// backed by a file with the given path.
16// It will return nil if shared-memory is not supported,
17// or not appropriate for the given flags.
18// Only [OPEN_MAIN_DB] databases may need a WAL-index.
19// You must ensure all concurrent accesses to a database
20// use shared-memory instances created with the same path.
21func NewSharedMemory(path string, flags OpenFlag) SharedMemory {
22	if flags&OPEN_MAIN_DB == 0 || flags&(OPEN_DELETEONCLOSE|OPEN_MEMORY) != 0 {
23		return nil
24	}
25	return &vfsShm{path: path}
26}