Skip to content

Commit

Permalink
update comments
Browse files Browse the repository at this point in the history
  • Loading branch information
alphadose committed Aug 12, 2022
1 parent 9961469 commit 2894aea
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
3 changes: 2 additions & 1 deletion selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ type Selectable interface {
}

// Select selects a single element out of multiple ZenQs
// the second parameter tells if all ZenQs were closed or not before reading, in which case the data returned is nil
// A maximum of 127 ZenQs can be selected from at a time owing to the size of int8 type
// `nil` is returned if all streams are closed or if a stream gets closed during the selection process
func Select(streams ...Selectable) (data any) {
numStreams := int8(len(streams) - 1)
filter:
Expand All @@ -61,6 +61,7 @@ filter:
}
}
if numStreams < 0 {
data = nil
return
}

Expand Down
12 changes: 7 additions & 5 deletions zenq.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ type (
ZenQ[T any] struct {
// The padding members 0 to 4 below are here to ensure each item is on a separate cache line.
// This prevents false sharing and hence improves performance.
_p0 cacheLinePadding
_ cacheLinePadding
writerIndex atomic.Uint32
_p1 [constants.CacheLinePadSize - unsafe.Sizeof(atomic.Uint32{})]byte
_ [constants.CacheLinePadSize - unsafe.Sizeof(atomic.Uint32{})]byte
readerIndex atomic.Uint32
_p2 [constants.CacheLinePadSize - unsafe.Sizeof(atomic.Uint32{})]byte
_ [constants.CacheLinePadSize - unsafe.Sizeof(atomic.Uint32{})]byte
metaQ
_p3 [constants.CacheLinePadSize - unsafe.Sizeof(metaQ{})]byte
_ [constants.CacheLinePadSize - unsafe.Sizeof(metaQ{})]byte
selectFactory[T]
_p4 [constants.CacheLinePadSize - unsafe.Sizeof(selectFactory[T]{})]byte
_ [constants.CacheLinePadSize - unsafe.Sizeof(selectFactory[T]{})]byte
}
)

Expand Down Expand Up @@ -147,6 +147,7 @@ direct_send:
// direct send to selector
*sel.Data = value
} else {
// send nil from closed channel
*sel.Data = nil
}
// notify selector
Expand Down Expand Up @@ -342,6 +343,7 @@ func (self *ZenQ[T]) selectSender() {
// write to the selector
*sel.Data = data
} else {
// send nil from closed channel
*sel.Data = nil
}
// notify selector
Expand Down

0 comments on commit 2894aea

Please sign in to comment.