Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dlib
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
钟尚武
dlib
Commits
00662b4b
Commit
00662b4b
authored
Jun 10, 2011
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added a bunch of overloads for add_task_by_value()
parent
97cf9ba1
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
227 additions
and
3 deletions
+227
-3
thread_pool.cpp
dlib/test/thread_pool.cpp
+85
-0
thread_pool_extension.h
dlib/threads/thread_pool_extension.h
+0
-0
thread_pool_extension_abstract.h
dlib/threads/thread_pool_extension_abstract.h
+142
-3
No files found.
dlib/test/thread_pool.cpp
View file @
00662b4b
...
...
@@ -43,6 +43,11 @@ namespace
void
set_global_var
()
{
global_var
=
9
;
}
void
set_global_var_const
()
const
{
global_var
=
9
;
}
void
set_global_var_arg1
(
int
val
)
{
global_var
=
val
;
}
void
set_global_var_const_arg1
(
int
val
)
const
{
global_var
=
val
;
}
void
set_global_var_arg2
(
int
val
,
int
val2
)
{
global_var
=
val
+
val2
;
}
void
set_global_var_const_arg2
(
int
val
,
int
val2
)
const
{
global_var
=
val
+
val2
;
}
void
operator
()()
{
global_var
=
9
;
...
...
@@ -242,6 +247,79 @@ namespace
tp
.
wait_for_task
(
id
);
DLIB_TEST
(
global_var
==
9
);
global_var
=
0
;
a
=
4
;
DLIB_TEST
(
global_var
==
0
);
id
=
tp
.
add_task
(
f
,
&
add_functor
::
set_global_var_arg1
,
a
);
tp
.
wait_for_task
(
id
);
DLIB_TEST
(
global_var
==
4
);
global_var
=
0
;
a
=
4
;
DLIB_TEST
(
global_var
==
0
);
id
=
tp
.
add_task_by_value
(
f
,
&
add_functor
::
set_global_var_arg1
,
a
);
tp
.
wait_for_task
(
id
);
DLIB_TEST
(
global_var
==
4
);
global_var
=
0
;
a
=
4
;
b
=
3
;
DLIB_TEST
(
global_var
==
0
);
id
=
tp
.
add_task
(
f
,
&
add_functor
::
set_global_var_arg2
,
a
,
b
);
tp
.
wait_for_task
(
id
);
DLIB_TEST
(
global_var
==
7
);
global_var
=
0
;
a
=
4
;
b
=
3
;
DLIB_TEST
(
global_var
==
0
);
id
=
tp
.
add_task_by_value
(
f
,
&
add_functor
::
set_global_var_arg2
,
a
,
b
);
tp
.
wait_for_task
(
id
);
DLIB_TEST
(
global_var
==
7
);
global_var
=
0
;
a
=
4
;
b
=
3
;
DLIB_TEST
(
global_var
==
0
);
id
=
tp
.
add_task
(
f
,
&
add_functor
::
set_global_var_const_arg2
,
a
,
b
);
tp
.
wait_for_task
(
id
);
DLIB_TEST
(
global_var
==
7
);
global_var
=
0
;
a
=
4
;
b
=
3
;
DLIB_TEST
(
global_var
==
0
);
id
=
tp
.
add_task_by_value
(
f
,
&
add_functor
::
set_global_var_const_arg2
,
a
,
b
);
tp
.
wait_for_task
(
id
);
DLIB_TEST
(
global_var
==
7
);
global_var
=
0
;
a
=
4
;
DLIB_TEST
(
global_var
==
0
);
id
=
tp
.
add_task
(
f
,
&
add_functor
::
set_global_var_const_arg1
,
a
);
tp
.
wait_for_task
(
id
);
DLIB_TEST
(
global_var
==
4
);
global_var
=
0
;
a
=
4
;
DLIB_TEST
(
global_var
==
0
);
id
=
tp
.
add_task_by_value
(
f
,
&
add_functor
::
set_global_var_const_arg1
,
a
);
tp
.
wait_for_task
(
id
);
DLIB_TEST
(
global_var
==
4
);
global_var
=
0
;
DLIB_TEST
(
global_var
==
0
);
id
=
tp
.
add_task_by_value
(
f
,
&
add_functor
::
set_global_var
);
tp
.
wait_for_task
(
id
);
DLIB_TEST
(
global_var
==
9
);
global_var
=
0
;
DLIB_TEST
(
global_var
==
0
);
...
...
@@ -250,6 +328,13 @@ namespace
DLIB_TEST
(
global_var
==
9
);
global_var
=
0
;
DLIB_TEST
(
global_var
==
0
);
id
=
tp
.
add_task_by_value
(
f
,
&
add_functor
::
set_global_var_const
);
tp
.
wait_for_task
(
id
);
DLIB_TEST
(
global_var
==
9
);
}
...
...
dlib/threads/thread_pool_extension.h
View file @
00662b4b
This diff is collapsed.
Click to expand it.
dlib/threads/thread_pool_extension_abstract.h
View file @
00662b4b
...
...
@@ -303,7 +303,7 @@ namespace dlib
ensures
- if (is_task_thread() == true and there aren't any free threads available) then
- calls (obj.*funct)() within the calling thread and returns
when it finishes
when it finishes
.
- else
- the call to this function blocks until there is a free thread in the pool
to process this new task. Once a free thread is available the task
...
...
@@ -312,6 +312,27 @@ namespace dlib
for the submitted task to finish.
!*/
template
<
typename
T
>
uint64
add_task_by_value
(
const
T
&
obj
,
void
(
T
::*
funct
)()
);
/*!
requires
- funct == a valid member function pointer for class T
ensures
- makes a copy of obj, call it OBJ_COPY.
- if (is_task_thread() == true and there aren't any free threads available) then
- calls (OBJ_COPY.*funct)() within the calling thread and returns
when it finishes.
- else
- the call to this function blocks until there is a free thread in the pool
to process this new task. Once a free thread is available the task
is handed off to that thread which then calls (OBJ_COPY.*funct)().
- returns a task id that can be used by this->wait_for_task() to wait
for the submitted task to finish.
!*/
template
<
typename
T
>
uint64
add_task
(
T
&
obj
,
...
...
@@ -457,6 +478,30 @@ namespace dlib
for the submitted task to finish.
!*/
template
<
typename
T
,
typename
T1
,
typename
A1
>
uint64
add_task_by_value
(
const
T
&
obj
,
void
(
T
::*
funct
)(
T1
),
future
<
A1
>&
arg1
);
/*!
requires
- funct == a valid member function pointer for class T
- (obj.*funct)(arg1.get()) must be a valid expression.
(i.e. The A1 type stored in the future must be a type that can be passed into the given function)
ensures
- makes a copy of obj, call it OBJ_COPY.
- if (is_task_thread() == true and there aren't any free threads available) then
- calls (OBJ_COPY.*funct)(arg1.get()) within the calling thread and returns
when it finishes.
- else
- the call to this function blocks until there is a free thread in the pool
to process this new task. Once a free thread is available the task
is handed off to that thread which then calls (OBJ_COPY.*funct)(arg1.get()).
- returns a task id that can be used by this->wait_for_task() to wait
for the submitted task to finish.
!*/
template
<
typename
T
,
typename
T1
,
typename
A1
>
uint64
add_task
(
const
T
&
obj
,
...
...
@@ -484,6 +529,30 @@ namespace dlib
for the submitted task to finish.
!*/
template
<
typename
T
,
typename
T1
,
typename
A1
>
uint64
add_task_by_value
(
const
T
&
obj
,
void
(
T
::*
funct
)(
T1
)
const
,
future
<
A1
>&
arg1
);
/*!
requires
- funct == a valid member function pointer for class T
- (obj.*funct)(arg1.get()) must be a valid expression.
(i.e. The A1 type stored in the future must be a type that can be passed into the given function)
ensures
- makes a copy of obj, call it OBJ_COPY.
- if (is_task_thread() == true and there aren't any free threads available) then
- calls (OBJ_COPY.*funct)(arg1.get()) within the calling thread and returns
when it finishes.
- else
- the call to this function blocks until there is a free thread in the pool
to process this new task. Once a free thread is available the task
is handed off to that thread which then calls (OBJ_COPY.*funct)(arg1.get()).
- returns a task id that can be used by this->wait_for_task() to wait
for the submitted task to finish.
!*/
template
<
typename
T1
,
typename
A1
>
uint64
add_task
(
void
(
*
funct
)(
T1
),
...
...
@@ -536,6 +605,13 @@ namespace dlib
future
<
A2
>&
arg2
);
uint64
add_task_by_value
(
const
T
&
obj
,
void
(
T
::*
funct
)(
T1
,
T2
),
future
<
A1
>&
arg1
,
future
<
A2
>&
arg2
);
template
<
typename
T
,
typename
T1
,
typename
A1
,
typename
T2
,
typename
A2
>
uint64
add_task
(
...
...
@@ -545,6 +621,15 @@ namespace dlib
future
<
A2
>&
arg2
);
template
<
typename
T
,
typename
T1
,
typename
A1
,
typename
T2
,
typename
A2
>
uint64
add_task_by_value
(
const
T
&
obj
,
void
(
T
::*
funct
)(
T1
,
T2
)
const
,
future
<
A1
>&
arg1
,
future
<
A2
>&
arg2
);
template
<
typename
T1
,
typename
A1
,
typename
T2
,
typename
A2
>
uint64
add_task
(
...
...
@@ -564,7 +649,7 @@ namespace dlib
);
template
<
typename
F
,
typename
A1
,
typename
A2
,
typename
A3
>
uint64
add_task
(
uint64
add_task
_by_value
(
const
F
&
function_object
,
future
<
A1
>&
arg1
,
future
<
A2
>&
arg2
,
...
...
@@ -581,6 +666,17 @@ namespace dlib
future
<
A2
>&
arg2
,
future
<
A3
>&
arg3
);
template
<
typename
T
,
typename
T1
,
typename
A1
,
typename
T2
,
typename
A2
,
typename
T3
,
typename
A3
>
uint64
add_task_by_value
(
const
T
&
obj
,
void
(
T
::*
funct
)(
T1
,
T2
,
T3
),
future
<
A1
>&
arg1
,
future
<
A2
>&
arg2
,
future
<
A3
>&
arg3
);
template
<
typename
T
,
typename
T1
,
typename
A1
,
typename
T2
,
typename
A2
,
...
...
@@ -592,6 +688,17 @@ namespace dlib
future
<
A2
>&
arg2
,
future
<
A3
>&
arg3
);
template
<
typename
T
,
typename
T1
,
typename
A1
,
typename
T2
,
typename
A2
,
typename
T3
,
typename
A3
>
uint64
add_task_by_value
(
const
T
&
obj
,
void
(
T
::*
funct
)(
T1
,
T2
,
T3
)
const
,
future
<
A1
>&
arg1
,
future
<
A2
>&
arg2
,
future
<
A3
>&
arg3
);
template
<
typename
T1
,
typename
A1
,
typename
T2
,
typename
A2
,
...
...
@@ -615,7 +722,7 @@ namespace dlib
);
template
<
typename
F
,
typename
A1
,
typename
A2
,
typename
A3
,
typename
A4
>
uint64
add_task
(
uint64
add_task
_by_value
(
const
F
&
function_object
,
future
<
A1
>&
arg1
,
future
<
A2
>&
arg2
,
...
...
@@ -635,6 +742,19 @@ namespace dlib
future
<
A3
>&
arg3
,
future
<
A4
>&
arg4
);
template
<
typename
T
,
typename
T1
,
typename
A1
,
typename
T2
,
typename
A2
,
typename
T3
,
typename
A3
,
typename
T4
,
typename
A4
>
uint64
add_task_by_value
(
const
T
&
obj
,
void
(
T
::*
funct
)(
T1
,
T2
,
T3
,
T4
),
future
<
A1
>&
arg1
,
future
<
A2
>&
arg2
,
future
<
A3
>&
arg3
,
future
<
A4
>&
arg4
);
template
<
typename
T
,
typename
T1
,
typename
A1
,
typename
T2
,
typename
A2
,
...
...
@@ -648,6 +768,19 @@ namespace dlib
future
<
A3
>&
arg3
,
future
<
A4
>&
arg4
);
template
<
typename
T
,
typename
T1
,
typename
A1
,
typename
T2
,
typename
A2
,
typename
T3
,
typename
A3
,
typename
T4
,
typename
A4
>
uint64
add_task_by_value
(
const
T
&
obj
,
void
(
T
::*
funct
)(
T1
,
T2
,
T3
,
T4
)
const
,
future
<
A1
>&
arg1
,
future
<
A2
>&
arg2
,
future
<
A3
>&
arg3
,
future
<
A4
>&
arg4
);
template
<
typename
T1
,
typename
A1
,
typename
T2
,
typename
A2
,
...
...
@@ -674,6 +807,12 @@ namespace dlib
void
(
T
::*
funct
)()
const
,
);
template
<
typename
T
>
uint64
add_task_by_value
(
const
T
&
obj
,
void
(
T
::*
funct
)()
const
);
uint64
add_task
(
void
(
*
funct
)()
);
...
...
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