mirror of
https://github.com/Mezeporta/Erupe.git
synced 2026-03-26 17:43:21 +01:00
refactor(channelserver): replace global stagesLock with sync.Map-backed StageMap
The global stagesLock sync.RWMutex protected map[string]*Stage, causing all stage operations to contend on a single lock even for unrelated stages. Any stage creation or deletion blocked all reads server-wide. Replace with a typed StageMap wrapper around sync.Map which provides lock-free reads and allows concurrent writes to disjoint keys. Per-stage sync.RWMutex remains unchanged for protecting individual stage state. StageMap exposes Get, GetOrCreate, StoreIfAbsent, Store, Delete, and Range methods. Updated ~50 call sites across 6 production files and 9 test files.
This commit is contained in:
@@ -600,9 +600,8 @@ func TestHandleMsgSysLockGlobalSema_WithChannel(t *testing.T) {
|
||||
// Create a mock channel with stages
|
||||
channel := &Server{
|
||||
GlobalID: "other-server",
|
||||
stages: make(map[string]*Stage),
|
||||
}
|
||||
channel.stages["stage_user123"] = NewStage("stage_user123")
|
||||
channel.stages.Store("stage_user123", NewStage("stage_user123"))
|
||||
server.Channels = []*Server{channel}
|
||||
|
||||
session := createMockSession(1, server)
|
||||
@@ -632,9 +631,8 @@ func TestHandleMsgSysLockGlobalSema_SameServer(t *testing.T) {
|
||||
// Create a mock channel with same GlobalID
|
||||
channel := &Server{
|
||||
GlobalID: "test-server",
|
||||
stages: make(map[string]*Stage),
|
||||
}
|
||||
channel.stages["stage_user456"] = NewStage("stage_user456")
|
||||
channel.stages.Store("stage_user456", NewStage("stage_user456"))
|
||||
server.Channels = []*Server{channel}
|
||||
|
||||
session := createMockSession(1, server)
|
||||
|
||||
Reference in New Issue
Block a user