Skip to content

Commit e460120

Browse files
Updated code based on suggestions.
1 parent 4b5d77b commit e460120

2 files changed

Lines changed: 5 additions & 8 deletions

File tree

‎chapter6/patterns/pool/pool.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
//
33
// Package pool manages a user defined set of resources.
44
// Based on the work by Fatih Arslan with his pool package.
5+
//
56
// https://github.com/fatih/pool/tree/v1.0.0
67
package pool
78

‎chapter6/patterns/semaphore/semaphore.go‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,8 @@ import (
2020
)
2121

2222
type (
23-
// empty type represents the message the semaphore channel uses to control access.
24-
// This is a structure that requires no memory, it is truly empty.
25-
empty struct{}
26-
2723
// semaphore type represents a channel that implements the semaphore pattern.
28-
semaphore chan empty
24+
semaphore chan struct{}
2925
)
3026

3127
type (
@@ -43,7 +39,7 @@ type (
4339
readerControl semaphore
4440

4541
// shutdown is used to signal to running goroutines to shutdown.
46-
shutdown chan empty
42+
shutdown chan struct{}
4743

4844
// reportShutdown is used by the goroutines to report they are shutdown.
4945
reportShutdown sync.WaitGroup
@@ -94,7 +90,7 @@ func start(name string, maxReads int, maxReaders int) *readerWriter {
9490
// Create a value of readerWriter and initialize.
9591
rw := readerWriter{
9692
name: name,
97-
shutdown: make(chan empty),
93+
shutdown: make(chan struct{}),
9894
maxReads: maxReads,
9995
maxReaders: maxReaders,
10096
readerControl: make(semaphore, maxReads),
@@ -257,7 +253,7 @@ func (rw *readerWriter) WriteUnlock() {
257253
// Acquire attempts to secure the specified number of buffers from the
258254
// semaphore channel.
259255
func (s semaphore) Acquire(buffers int) {
260-
var e empty
256+
var e struct{}
261257

262258
// Write data to secure each buffer.
263259
for buffer := 0; buffer < buffers; buffer++ {

0 commit comments

Comments
 (0)