Repository navigation
Expand file tree
/
Copy pathqueuehook.go
More file actions
57 lines (49 loc) · 1.46 KB
/
Copy pathqueuehook.go
File metadata and controls
57 lines (49 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright (c) 2026 The liustack/sqlite Authors.
// SPDX-License-Identifier: MIT
// Use of this source code is governed by the MIT license in LICENSE at the
// root of this repository.
//go:build ((linux || darwin) && (amd64 || arm64)) || (windows && (amd64 || arm64))
package sqlite
import (
"errors"
"os"
"github.com/liustack/sqlite/internal/queuehook"
)
func init() {
queuehook.Of = signalOfConn
queuehook.Register = registerQueue
}
// registerQueue is queuehook.Register.
func registerQueue(driverConn any, table, name string) (*queuehook.Queue, error) {
c, ok := driverConn.(*conn)
if !ok {
return nil, errors.New("sqlite: not a connection of github.com/liustack/sqlite")
}
return c.queues.Of(table, name), nil
}
// signalOfConn is queuehook.Of.
func signalOfConn(driverConn any) (*queuehook.Signal, error) {
c, ok := driverConn.(*conn)
if !ok {
return nil, errors.New("sqlite: not a connection of github.com/liustack/sqlite")
}
if c.wl == nil {
return nil, errors.New("sqlite: the database has no file")
}
writeLocks.Lock()
defer writeLocks.Unlock()
return signalOfFile(c.wl.file), nil
}
// signalOfFile is the signal of file, made when first asked for and given to
// the write lock the file has now. writeLocks is held.
func signalOfFile(file os.FileInfo) *queuehook.Signal {
if s := findSignal(file); s != nil {
return s
}
s := &queuehook.Signal{}
addSignal(file, s)
if l := findWriteLock(file); l != nil {
l.signal.Store(s)
}
return s
}