Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gostnops
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wei.xuan
gostnops
Commits
f17fd664
Commit
f17fd664
authored
Nov 14, 2020
by
wangwx
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change new function name and implement
parent
6e1354ec
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
9 deletions
+7
-9
poolqueue.go
container/queue/poolqueue.go
+2
-2
poolqueue_test.go
container/queue/poolqueue_test.go
+5
-7
No files found.
container/queue/poolqueue.go
View file @
f17fd664
...
@@ -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
}
}
// New
PoolDequeue
new a poolDequeue instance.
// New
SPMCLockFreeQ
new a poolDequeue instance.
func
New
PoolDequeue
(
n
int
)
(
*
poolDequeue
,
error
)
{
func
New
SPMCLockFreeQ
(
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"
)
}
}
...
...
container/queue/poolqueue_test.go
View file @
f17fd664
...
@@ -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
:=
New
PoolDequeue
(
15
)
_
,
err
:=
New
SPMCLockFreeQ
(
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
=
New
PoolDequeue
(
18
)
_
,
err
=
New
SPMCLockFreeQ
(
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
=
New
PoolDequeue
(
24
)
_
,
err
=
New
SPMCLockFreeQ
(
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
=
New
PoolDequeue
(
8
)
_
,
err
=
New
SPMCLockFreeQ
(
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
:=
New
PoolDequeue
(
16
)
d
,
err
:=
New
SPMCLockFreeQ
(
16
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"create poolDequeue fail"
)
t
.
Errorf
(
"create poolDequeue fail"
)
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment