Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
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
e7888cff
Commit
e7888cff
authored
Nov 18, 2020
by
watermelon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
opt: impl simple task poll
parent
2a672f6b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
4 deletions
+7
-4
options.go
sync/options.go
+4
-3
task_pool.go
sync/task_pool.go
+3
-1
No files found.
sync/options.go
View file @
e7888cff
...
...
@@ -13,6 +13,7 @@ const (
// Task Pool Options
/////////////////////////////////////////
// TaskPoolOption is optional settings for task pool
type
TaskPoolOptions
struct
{
tQLen
int
// task queue length. buffer size per queue
tQNumber
int
// task queue number. number of queue
...
...
@@ -39,21 +40,21 @@ func (o *TaskPoolOptions) validate() {
type
TaskPoolOption
func
(
*
TaskPoolOptions
)
//
@size is
the task queue pool size
//
WithTaskPoolTaskQueueLength set @size of
the task queue pool size
func
WithTaskPoolTaskPoolSize
(
size
int
)
TaskPoolOption
{
return
func
(
o
*
TaskPoolOptions
)
{
o
.
tQPoolSize
=
size
}
}
//
@length is
the task queue length
//
WithTaskPoolTaskQueueLength set @length of
the task queue length
func
WithTaskPoolTaskQueueLength
(
length
int
)
TaskPoolOption
{
return
func
(
o
*
TaskPoolOptions
)
{
o
.
tQLen
=
length
}
}
//
@number is
the task queue number
//
WithTaskPoolTaskQueueNumber set @number of
the task queue number
func
WithTaskPoolTaskQueueNumber
(
number
int
)
TaskPoolOption
{
return
func
(
o
*
TaskPoolOptions
)
{
o
.
tQNumber
=
number
...
...
sync/task_pool.go
View file @
e7888cff
...
...
@@ -35,6 +35,7 @@ import (
type
task
func
()
// GenericTaskPool represents an generic task pool.
type
GenericTaskPool
interface
{
// AddTask wait idle worker add task
AddTask
(
t
task
)
bool
...
...
@@ -64,7 +65,7 @@ type TaskPool struct {
done
chan
struct
{}
}
// build a task pool
//
NewTaskPool
build a task pool
func
NewTaskPool
(
opts
...
TaskPoolOption
)
GenericTaskPool
{
var
tOpts
TaskPoolOptions
for
_
,
opt
:=
range
opts
{
...
...
@@ -226,6 +227,7 @@ type taskPoolSimple struct {
sem
chan
struct
{}
}
// NewTaskPoolSimple build a simple task pool
func
NewTaskPoolSimple
(
size
int
)
GenericTaskPool
{
if
size
<
1
{
size
=
runtime
.
NumCPU
()
*
100
...
...
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