Commit 0fd3c1a3 authored by Brian Tiger Chow's avatar Brian Tiger Chow Committed by 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: default avatarBrian Tiger Chow <brian@perfmode.com>
parent ee31c518
......@@ -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 is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment