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
8a3ff4ff
Commit
8a3ff4ff
authored
Jun 07, 2011
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added an add_task_by_value() function to the thread_pool.
parent
cf6f55c2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
149 additions
and
4 deletions
+149
-4
thread_pool_extension.cpp
dlib/threads/thread_pool_extension.cpp
+3
-1
thread_pool_extension.h
dlib/threads/thread_pool_extension.h
+146
-3
thread_pool_extension_abstract.h
dlib/threads/thread_pool_extension_abstract.h
+0
-0
No files found.
dlib/threads/thread_pool_extension.cpp
View file @
8a3ff4ff
...
...
@@ -260,7 +260,8 @@ namespace dlib
uint64
thread_pool_implementation
::
add_task_internal
(
const
bfp_type
&
bfp
const
bfp_type
&
bfp
,
shared_ptr
<
function_object_copy
>&
item
)
{
auto_mutex
M
(
m
);
...
...
@@ -293,6 +294,7 @@ namespace dlib
tasks
[
idx
].
thread_id
=
my_thread_id
;
tasks
[
idx
].
task_id
=
make_next_task_id
(
idx
);
tasks
[
idx
].
bfp
=
bfp
;
tasks
[
idx
].
function_copy
.
swap
(
item
);
task_ready_signaler
.
signal
();
...
...
dlib/threads/thread_pool_extension.h
View file @
8a3ff4ff
...
...
@@ -12,6 +12,7 @@
#include "../uintn.h"
#include "../array.h"
#include "../smart_pointers_thread_safe.h"
#include "../smart_pointers.h"
namespace
dlib
{
...
...
@@ -296,9 +297,34 @@ namespace dlib
return
tasks
[
idx
].
task_id
;
}
struct
function_object_copy
{
virtual
~
function_object_copy
(){}
};
template
<
typename
T
>
struct
function_object_copy_instance
:
function_object_copy
{
function_object_copy_instance
(
const
T
&
item_
)
:
item
(
item_
)
{}
T
item
;
virtual
~
function_object_copy_instance
(){}
};
uint64
add_task_internal
(
const
bfp_type
&
bfp
const
bfp_type
&
bfp
,
shared_ptr
<
function_object_copy
>&
item
);
/*!
ensures
- adds a task to call the given bfp object.
- swaps item into the internal task object which will have a lifetime
at least as long as the running task.
- returns the task id for this new task
!*/
uint64
add_task_internal
(
const
bfp_type
&
bfp
)
{
shared_ptr
<
function_object_copy
>
temp
;
return
add_task_internal
(
bfp
,
temp
);
}
/*!
ensures
- adds a task to call the given bfp object.
...
...
@@ -424,10 +450,12 @@ namespace dlib
member_function_pointer
<
long
,
long
>::
kernel_1a
mfp2
;
bfp_type
bfp
;
shared_ptr
<
function_object_copy
>
function_copy
;
};
array
<
task_state_type
>::
expand_1d
_c
tasks
;
array
<
thread_id_type
>::
expand_1d
_c
worker_thread_ids
;
array
<
task_state_type
>::
expand_1d
tasks
;
array
<
thread_id_type
>::
expand_1d
worker_thread_ids
;
mutex
m
;
signaler
task_done_signaler
;
...
...
@@ -528,6 +556,23 @@ namespace dlib
return
id
;
}
template
<
typename
F
>
uint64
add_task_by_value
(
const
F
&
function_object
)
{
thread_pool_implementation
::
function_object_copy_instance
<
F
>*
ptr
=
0
;
ptr
=
new
thread_pool_implementation
::
function_object_copy_instance
<
F
>
(
function_object
);
shared_ptr
<
thread_pool_implementation
::
function_object_copy
>
function_copy
(
ptr
);
bfp_type
temp
;
temp
.
set
(
ptr
->
item
);
uint64
id
=
impl
->
add_task_internal
(
temp
,
function_copy
);
return
id
;
}
template
<
typename
T
>
uint64
add_task
(
const
T
&
obj
,
...
...
@@ -573,6 +618,26 @@ namespace dlib
return
id
;
}
template
<
typename
F
,
typename
A1
>
uint64
add_task_by_value
(
const
F
&
function_object
,
future
<
A1
>&
arg1
)
{
thread_pool_implementation
::
function_object_copy_instance
<
F
>*
ptr
=
0
;
ptr
=
new
thread_pool_implementation
::
function_object_copy_instance
<
F
>
(
function_object
);
shared_ptr
<
thread_pool_implementation
::
function_object_copy
>
function_copy
(
ptr
);
bfp_type
temp
;
temp
.
set
(
ptr
->
item
,
arg1
.
get
());
uint64
id
=
impl
->
add_task_internal
(
temp
,
function_copy
);
// tie the future to this task
arg1
.
task_id
=
id
;
arg1
.
tp
=
impl
;
return
id
;
}
template
<
typename
T
,
typename
T1
,
typename
A1
>
uint64
add_task
(
T
&
obj
,
...
...
@@ -647,6 +712,29 @@ namespace dlib
return
id
;
}
template
<
typename
F
,
typename
A1
,
typename
A2
>
uint64
add_task_by_value
(
const
F
&
function_object
,
future
<
A1
>&
arg1
,
future
<
A2
>&
arg2
)
{
thread_pool_implementation
::
function_object_copy_instance
<
F
>*
ptr
=
0
;
ptr
=
new
thread_pool_implementation
::
function_object_copy_instance
<
F
>
(
function_object
);
shared_ptr
<
thread_pool_implementation
::
function_object_copy
>
function_copy
(
ptr
);
bfp_type
temp
;
temp
.
set
(
ptr
->
item
,
arg1
.
get
(),
arg2
.
get
());
uint64
id
=
impl
->
add_task_internal
(
temp
,
function_copy
);
// tie the future to this task
arg1
.
task_id
=
id
;
arg1
.
tp
=
impl
;
arg2
.
task_id
=
id
;
arg2
.
tp
=
impl
;
return
id
;
}
template
<
typename
T
,
typename
T1
,
typename
A1
,
typename
T2
,
typename
A2
>
uint64
add_task
(
...
...
@@ -736,6 +824,32 @@ namespace dlib
return
id
;
}
template
<
typename
F
,
typename
A1
,
typename
A2
,
typename
A3
>
uint64
add_task_by_value
(
const
F
&
function_object
,
future
<
A1
>&
arg1
,
future
<
A2
>&
arg2
,
future
<
A3
>&
arg3
)
{
thread_pool_implementation
::
function_object_copy_instance
<
F
>*
ptr
=
0
;
ptr
=
new
thread_pool_implementation
::
function_object_copy_instance
<
F
>
(
function_object
);
shared_ptr
<
thread_pool_implementation
::
function_object_copy
>
function_copy
(
ptr
);
bfp_type
temp
;
temp
.
set
(
ptr
->
item
,
arg1
.
get
(),
arg2
.
get
(),
arg3
.
get
());
uint64
id
=
impl
->
add_task_internal
(
temp
,
function_copy
);
// tie the future to this task
arg1
.
task_id
=
id
;
arg1
.
tp
=
impl
;
arg2
.
task_id
=
id
;
arg2
.
tp
=
impl
;
arg3
.
task_id
=
id
;
arg3
.
tp
=
impl
;
return
id
;
}
template
<
typename
T
,
typename
T1
,
typename
A1
,
typename
T2
,
typename
A2
,
typename
T3
,
typename
A3
>
...
...
@@ -840,6 +954,35 @@ namespace dlib
return
id
;
}
template
<
typename
F
,
typename
A1
,
typename
A2
,
typename
A3
,
typename
A4
>
uint64
add_task_by_value
(
const
F
&
function_object
,
future
<
A1
>&
arg1
,
future
<
A2
>&
arg2
,
future
<
A3
>&
arg3
,
future
<
A4
>&
arg4
)
{
thread_pool_implementation
::
function_object_copy_instance
<
F
>*
ptr
=
0
;
ptr
=
new
thread_pool_implementation
::
function_object_copy_instance
<
F
>
(
function_object
);
shared_ptr
<
thread_pool_implementation
::
function_object_copy
>
function_copy
(
ptr
);
bfp_type
temp
;
temp
.
set
(
ptr
->
item
,
arg1
.
get
(),
arg2
.
get
(),
arg3
.
get
(),
arg4
.
get
());
uint64
id
=
impl
->
add_task_internal
(
temp
,
function_copy
);
// tie the future to this task
arg1
.
task_id
=
id
;
arg1
.
tp
=
impl
;
arg2
.
task_id
=
id
;
arg2
.
tp
=
impl
;
arg3
.
task_id
=
id
;
arg3
.
tp
=
impl
;
arg4
.
task_id
=
id
;
arg4
.
tp
=
impl
;
return
id
;
}
template
<
typename
T
,
typename
T1
,
typename
A1
,
typename
T2
,
typename
A2
,
typename
T3
,
typename
A3
,
...
...
dlib/threads/thread_pool_extension_abstract.h
View file @
8a3ff4ff
This diff is collapsed.
Click to expand it.
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