Commit f17fd664 authored by wangwx's avatar wangwx

change new function name and implement

parent 6e1354ec
...@@ -205,8 +205,8 @@ func (d *poolDequeue) PopTail() (interface{}, bool) { ...@@ -205,8 +205,8 @@ func (d *poolDequeue) PopTail() (interface{}, bool) {
return val, true return val, true
} }
// NewPoolDequeue new a poolDequeue instance. // NewSPMCLockFreeQ new a poolDequeue instance.
func NewPoolDequeue(n int) (*poolDequeue, error) { func NewSPMCLockFreeQ(n int) (SPMCLockFreeQ, error) {
if n&(n-1) != 0 { if n&(n-1) != 0 {
return nil, errors.New("the size of pool must be a power of 2") return nil, errors.New("the size of pool must be a power of 2")
} }
......
...@@ -23,27 +23,25 @@ import ( ...@@ -23,27 +23,25 @@ import (
"sync" "sync"
"sync/atomic" "sync/atomic"
"testing" "testing"
)
import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func TestCreatePoolDequeue(t *testing.T) { func TestCreatePoolDequeue(t *testing.T) {
_, err := NewPoolDequeue(15) _, err := NewSPMCLockFreeQ(15)
assert.EqualError(t, err, "the size of pool must be a power of 2") assert.EqualError(t, err, "the size of pool must be a power of 2")
_, err = NewPoolDequeue(18) _, err = NewSPMCLockFreeQ(18)
assert.EqualError(t, err, "the size of pool must be a power of 2") assert.EqualError(t, err, "the size of pool must be a power of 2")
_, err = NewPoolDequeue(24) _, err = NewSPMCLockFreeQ(24)
assert.EqualError(t, err, "the size of pool must be a power of 2") assert.EqualError(t, err, "the size of pool must be a power of 2")
_, err = NewPoolDequeue(8) _, err = NewSPMCLockFreeQ(8)
assert.NoError(t, err) assert.NoError(t, err)
} }
func TestPoolDequeue(t *testing.T) { func TestPoolDequeue(t *testing.T) {
const P = 10 const P = 10
var N int = 2e6 var N int = 2e6
d, err := NewPoolDequeue(16) d, err := NewSPMCLockFreeQ(16)
if err != nil { if err != nil {
t.Errorf("create poolDequeue fail") t.Errorf("create poolDequeue fail")
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment