File tree Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Original file line number Diff line number Diff line change @@ -170,6 +170,7 @@ type Seat struct {
170170}
171171
172172type Seats struct {
173+ mu * sync.Mutex
173174 // counter count atomically seats of a session.
174175 counter * atomic.Int32
175176 // Items represents the individual seat of a session.
@@ -179,13 +180,17 @@ type Seats struct {
179180// NewSeats creates a new [Seats] defining initial values for internal properties.
180181func NewSeats () Seats {
181182 return Seats {
183+ mu : new (sync.Mutex ),
182184 counter : new (atomic.Int32 ),
183185 Items : new (sync.Map ),
184186 }
185187}
186188
187189// NewSeat creates a new seat inside seats.
188190func (s * Seats ) NewSeat () (int , error ) {
191+ s .mu .Lock ()
192+ defer s .mu .Unlock ()
193+
189194 id := int (s .counter .Load ())
190195 defer s .counter .Add (1 )
191196
@@ -213,6 +218,9 @@ func (s *Seats) Get(seat int) (*Seat, bool) {
213218
214219// SetPty sets a pty status to a seat from their id.
215220func (s * Seats ) SetPty (seat int , status bool ) {
221+ s .mu .Lock ()
222+ defer s .mu .Unlock ()
223+
216224 item , ok := s .Get (seat )
217225 if ! ok {
218226 log .Warn ("failed to set pty because no seat was created before" )
You can’t perform that action at this time.
0 commit comments