提交 d069ae11 作者: Brian Tiger Chow 提交者: Juan Batiz-Benet

refactor: put mutex next to the things it protects

If we put the lock next to the fields it protects, it can sometimes make
it easier to reason about threadsafety.

In this case, it reveals that the task queue (not threadsafe) isn't protected by the
mutex, yet shared between the worker and callers.

@whyrusleeping

License: MIT
Signed-off-by: 's avatarBrian Tiger Chow <brian@perfmode.com>
上级 962a9477
......@@ -22,15 +22,19 @@ type Envelope struct {
}
type LedgerManager struct {
lock sync.RWMutex
// ledgerMap lists Ledgers by their Partner key.
ledgerMap map[u.Key]*ledger
bs bstore.Blockstore
// FIXME taskqueue isn't threadsafe nor is it protected by a mutex. consider
// a way to avoid sharing the taskqueue between the worker and the receiver
taskqueue *taskQueue
outbox chan Envelope
taskqueue *taskQueue
workSignal chan struct{}
outbox chan Envelope
bs bstore.Blockstore
lock sync.RWMutex
// ledgerMap lists Ledgers by their Partner key.
ledgerMap map[u.Key]*ledger
}
func NewLedgerManager(ctx context.Context, bs bstore.Blockstore) *LedgerManager {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论