-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
138 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,59 @@ | ||
//go:build !mutex_debug | ||
// +build !mutex_debug | ||
|
||
package nebula | ||
|
||
import ( | ||
"sync" | ||
) | ||
|
||
type syncRWMutex = sync.RWMutex | ||
import "fmt" | ||
|
||
type mutexKeyType string | ||
|
||
const ( | ||
mutexKeyTypeHostMap mutexKeyType = "hostmap" | ||
mutexKeyTypeHostInfo = "hostinfo" | ||
mutexKeyTypeHandshakeManager = "handshake-manager" | ||
mutexKeyTypeHostMap mutexKeyType = "hostmap" | ||
|
||
mutexKeyTypeLightHouse = "lighthouse" | ||
mutexKeyTypeFirewallConntrack = "firewall-conntrack" | ||
mutexKeyTypeHostInfo = "hostinfo" | ||
mutexKeyTypeHandshakeHostInfo = "handshake-hostinfo" | ||
mutexKeyTypeHandshakeManager = "handshake-manager" | ||
mutexKeyTypeConnectionStateWrite = "connection-state-write-lock" | ||
|
||
mutexKeyTypeConnectionManagerIn = "connection-manager-in-lock" | ||
mutexKeyTypeConnectionManagerOut = "connection-manager-out-lock" | ||
mutexKeyTypeConnectionManagerRelayUsed = "connection-manager-relay-used-lock" | ||
) | ||
|
||
func newSyncRWMutex(mutexKey) syncRWMutex { | ||
return sync.RWMutex{} | ||
// For each Key in this map, the Value is a list of lock types you can already have | ||
// when you want to grab that Key. This ensures that locks are always fetched | ||
// in the same order, to prevent deadlocks. | ||
var allowedConcurrentLocks = map[mutexKeyType][]mutexKeyType{ | ||
mutexKeyTypeHostMap: {mutexKeyTypeHandshakeHostInfo}, | ||
mutexKeyTypeFirewallConntrack: {mutexKeyTypeHandshakeHostInfo}, | ||
|
||
mutexKeyTypeHandshakeManager: {mutexKeyTypeHostMap}, | ||
mutexKeyTypeConnectionStateWrite: {mutexKeyTypeHostMap}, | ||
|
||
mutexKeyTypeLightHouse: {mutexKeyTypeHandshakeManager}, | ||
|
||
mutexKeyTypeConnectionManagerIn: {mutexKeyTypeHostMap}, | ||
mutexKeyTypeConnectionManagerOut: {mutexKeyTypeConnectionStateWrite, mutexKeyTypeConnectionManagerIn}, | ||
mutexKeyTypeConnectionManagerRelayUsed: {mutexKeyTypeHandshakeHostInfo}, | ||
} | ||
|
||
type mutexKey struct { | ||
Type mutexKeyType | ||
ID uint32 | ||
} | ||
|
||
type mutexValue struct { | ||
file string | ||
line int | ||
} | ||
|
||
func (m mutexKey) String() string { | ||
if m.ID == 0 { | ||
return fmt.Sprintf("%s", m.Type) | ||
} else { | ||
return fmt.Sprintf("%s(%d)", m.Type, m.ID) | ||
} | ||
} | ||
|
||
func (m mutexValue) String() string { | ||
return fmt.Sprintf("%s:%d", m.file, m.line) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
//go:build !mutex_debug | ||
// +build !mutex_debug | ||
|
||
package nebula | ||
|
||
import ( | ||
"sync" | ||
) | ||
|
||
type syncRWMutex = sync.RWMutex | ||
type syncMutex = sync.Mutex | ||
|
||
func newSyncRWMutex(mutexKey) syncRWMutex { | ||
return sync.RWMutex{} | ||
} | ||
|
||
func newSyncMutex(mutexKey) syncMutex { | ||
return sync.Mutex{} | ||
} |