Commit 00662b4b authored by Davis King's avatar Davis King

Added a bunch of overloads for add_task_by_value()

parent 97cf9ba1
......@@ -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);
}
......
This diff is collapsed.
......@@ -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)()
);
......
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