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
f6ad04c8
Commit
f6ad04c8
authored
Nov 18, 2012
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Converted the timer component into two single implementation components.
These are the timer and timer_heavy objects now.
parent
52dae74c
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
84 additions
and
105 deletions
+84
-105
timer.h
dlib/timer.h
+0
-27
timer_kernel_1.h
dlib/timer/timer_kernel_1.h
+22
-22
timer_kernel_2.cpp
dlib/timer/timer_kernel_2.cpp
+21
-21
timer_kernel_2.h
dlib/timer/timer_kernel_2.h
+41
-35
No files found.
dlib/timer.h
View file @
f6ad04c8
...
...
@@ -5,33 +5,6 @@
#include "timer/timer_kernel_1.h"
#include "timer/timer_kernel_2.h"
#include "uintn.h"
namespace
dlib
{
template
<
typename
T
>
class
timer
{
timer
()
{}
public
:
//----------- kernels ---------------
// kernel_1a
typedef
timer_kernel_1
<
T
>
kernel_1a
;
// kernel_2a
typedef
timer_kernel_2
<
T
>
kernel_2a
;
};
}
#endif // DLIB_TIMEr_
dlib/timer/timer_kernel_1.h
View file @
f6ad04c8
...
...
@@ -14,7 +14,7 @@ namespace dlib
template
<
typename
T
>
class
timer_
kernel_1
class
timer_
heavy
{
/*!
INITIAL VALUE
...
...
@@ -46,12 +46,12 @@ namespace dlib
typedef
void
(
T
::*
af_type
)();
timer_
kernel_1
(
timer_
heavy
(
T
&
ao_
,
af_type
af_
);
virtual
~
timer_
kernel_1
(
virtual
~
timer_
heavy
(
);
void
clear
(
...
...
@@ -110,8 +110,8 @@ namespace dlib
uint64
next_time_to_run
;
// restricted functions
timer_
kernel_1
(
const
timer_kernel_1
<
T
>&
);
// copy constructor
timer_
kernel_1
<
T
>&
operator
=
(
const
timer_kernel_1
<
T
>&
);
// assignment operator
timer_
heavy
(
const
timer_heavy
<
T
>&
);
// copy constructor
timer_
heavy
<
T
>&
operator
=
(
const
timer_heavy
<
T
>&
);
// assignment operator
};
...
...
@@ -124,8 +124,8 @@ namespace dlib
template
<
typename
T
>
timer_
kernel_1
<
T
>::
timer_
kernel_1
(
timer_
heavy
<
T
>::
timer_
heavy
(
T
&
ao_
,
af_type
af_
)
:
...
...
@@ -143,8 +143,8 @@ namespace dlib
template
<
typename
T
>
timer_
kernel_1
<
T
>::
~
timer_
kernel_1
(
timer_
heavy
<
T
>::
~
timer_
heavy
(
)
{
stop_and_wait
();
...
...
@@ -155,7 +155,7 @@ namespace dlib
template
<
typename
T
>
void
timer_
kernel_1
<
T
>::
void
timer_
heavy
<
T
>::
clear
(
)
{
...
...
@@ -171,7 +171,7 @@ namespace dlib
template
<
typename
T
>
typename
timer_
kernel_1
<
T
>::
af_type
timer_kernel_1
<
T
>::
typename
timer_
heavy
<
T
>::
af_type
timer_heavy
<
T
>::
action_function
(
)
const
{
...
...
@@ -183,7 +183,7 @@ namespace dlib
template
<
typename
T
>
const
T
&
timer_
kernel_1
<
T
>::
const
T
&
timer_
heavy
<
T
>::
action_object
(
)
const
{
...
...
@@ -195,7 +195,7 @@ namespace dlib
template
<
typename
T
>
T
&
timer_
kernel_1
<
T
>::
T
&
timer_
heavy
<
T
>::
action_object
(
)
{
...
...
@@ -207,7 +207,7 @@ namespace dlib
template
<
typename
T
>
bool
timer_
kernel_1
<
T
>::
bool
timer_
heavy
<
T
>::
is_running
(
)
const
{
...
...
@@ -220,7 +220,7 @@ namespace dlib
template
<
typename
T
>
unsigned
long
timer_
kernel_1
<
T
>::
unsigned
long
timer_
heavy
<
T
>::
delay_time
(
)
const
{
...
...
@@ -233,7 +233,7 @@ namespace dlib
template
<
typename
T
>
void
timer_
kernel_1
<
T
>::
void
timer_
heavy
<
T
>::
set_delay_time
(
unsigned
long
milliseconds
)
...
...
@@ -257,7 +257,7 @@ namespace dlib
template
<
typename
T
>
void
timer_
kernel_1
<
T
>::
void
timer_
heavy
<
T
>::
start
(
)
{
...
...
@@ -274,10 +274,10 @@ namespace dlib
running
=
true
;
// start the thread
if
(
create_new_thread
<
timer_
kernel_1
,
&
timer_kernel_1
::
thread
>
(
*
this
)
==
false
)
if
(
create_new_thread
<
timer_
heavy
,
&
timer_heavy
::
thread
>
(
*
this
)
==
false
)
{
running
=
false
;
throw
dlib
::
thread_error
(
"error creating new thread in timer_
kernel_1
::start"
);
throw
dlib
::
thread_error
(
"error creating new thread in timer_
heavy
::start"
);
}
}
}
...
...
@@ -287,7 +287,7 @@ namespace dlib
template
<
typename
T
>
void
timer_
kernel_1
<
T
>::
void
timer_
heavy
<
T
>::
stop
(
)
{
...
...
@@ -302,7 +302,7 @@ namespace dlib
template
<
typename
T
>
void
timer_
kernel_1
<
T
>::
void
timer_
heavy
<
T
>::
thread
(
)
{
...
...
@@ -354,7 +354,7 @@ namespace dlib
template
<
typename
T
>
void
timer_
kernel_1
<
T
>::
void
timer_
heavy
<
T
>::
stop_and_wait
(
)
{
...
...
dlib/timer/timer_kernel_2.cpp
View file @
f6ad04c8
...
...
@@ -10,8 +10,8 @@ namespace dlib
// ----------------------------------------------------------------------------------------
timer_
kernel_2_
global_clock
::
timer_
kernel_2_
global_clock
(
timer_global_clock
::
timer_global_clock
(
)
:
s
(
m
),
shutdown
(
false
),
...
...
@@ -21,8 +21,8 @@ namespace dlib
// ----------------------------------------------------------------------------------------
timer_
kernel_2_
global_clock
::
~
timer_
kernel_2_
global_clock
()
timer_global_clock
::
~
timer_global_clock
()
{
m
.
lock
();
shutdown
=
true
;
...
...
@@ -33,9 +33,9 @@ namespace dlib
// ----------------------------------------------------------------------------------------
void
timer_
kernel_2_
global_clock
::
void
timer_global_clock
::
add
(
timer_
kernel_2_
base
*
r
timer_base
*
r
)
{
if
(
r
->
in_global_clock
==
false
)
...
...
@@ -56,7 +56,7 @@ namespace dlib
// next event in tm
s
.
signal
();
}
timer_
kernel_2_
base
*
rtemp
=
r
;
timer_base
*
rtemp
=
r
;
uint64
ttemp
=
t
;
tm
.
add
(
ttemp
,
rtemp
);
r
->
next_time_to_run
=
t
;
...
...
@@ -66,9 +66,9 @@ namespace dlib
// ----------------------------------------------------------------------------------------
void
timer_
kernel_2_
global_clock
::
void
timer_global_clock
::
remove
(
timer_
kernel_2_
base
*
r
timer_base
*
r
)
{
if
(
r
->
in_global_clock
)
...
...
@@ -79,7 +79,7 @@ namespace dlib
if
(
tm
.
element
().
value
()
==
r
)
{
uint64
t
;
timer_
kernel_2_
base
*
rtemp
;
timer_base
*
rtemp
;
tm
.
remove_current_element
(
t
,
rtemp
);
r
->
in_global_clock
=
false
;
break
;
...
...
@@ -90,9 +90,9 @@ namespace dlib
// ----------------------------------------------------------------------------------------
void
timer_
kernel_2_
global_clock
::
void
timer_global_clock
::
adjust_delay
(
timer_
kernel_2_
base
*
r
,
timer_base
*
r
,
unsigned
long
new_delay
)
{
...
...
@@ -117,7 +117,7 @@ namespace dlib
r
->
running
=
false
;
r
->
delay
=
new_delay
;
timer_
kernel_2_
base
*
rtemp
=
r
;
timer_base
*
rtemp
=
r
;
uint64
ttemp
=
t
;
tm
.
add
(
ttemp
,
rtemp
);
r
->
next_time_to_run
=
t
;
...
...
@@ -135,7 +135,7 @@ namespace dlib
// ----------------------------------------------------------------------------------------
void
timer_
kernel_2_
global_clock
::
void
timer_global_clock
::
thread
()
{
auto_mutex
M
(
m
);
...
...
@@ -155,8 +155,8 @@ namespace dlib
if
(
t
<=
cur_time
+
999
)
{
// remove this event from the tm map
timer_
kernel_2_
base
*
r
=
tm
.
element
().
value
();
timer_
kernel_2_
base
*
rtemp
;
timer_base
*
r
=
tm
.
element
().
value
();
timer_base
*
rtemp
;
tm
.
remove_current_element
(
t
,
rtemp
);
r
->
in_global_clock
=
false
;
...
...
@@ -181,24 +181,24 @@ namespace dlib
// ----------------------------------------------------------------------------------------
shared_ptr_thread_safe
<
timer_
kernel_2_
global_clock
>
get_global_clock
()
shared_ptr_thread_safe
<
timer_global_clock
>
get_global_clock
()
{
static
shared_ptr_thread_safe
<
timer_
kernel_2_global_clock
>
d
(
new
timer_kernel_2
_global_clock
);
static
shared_ptr_thread_safe
<
timer_
global_clock
>
d
(
new
timer
_global_clock
);
return
d
;
}
// ----------------------------------------------------------------------------------------
// do this just to make sure get_global_clock() gets called at program startup
class
timer_
kernel_2_
global_clock_helper
class
timer_global_clock_helper
{
public
:
timer_
kernel_2_
global_clock_helper
()
timer_global_clock_helper
()
{
get_global_clock
();
}
};
static
timer_
kernel_2_
global_clock_helper
call_get_global_clock
;
static
timer_global_clock_helper
call_get_global_clock
;
// ----------------------------------------------------------------------------------------
...
...
dlib/timer/timer_kernel_2.h
View file @
f6ad04c8
...
...
@@ -10,15 +10,16 @@
#include "../uintn.h"
#include "../binary_search_tree.h"
#include "../smart_pointers_thread_safe.h"
#include "timer_kernel_1.h"
namespace
dlib
{
struct
timer_
kernel_2_
base
:
public
threaded_object
struct
timer_base
:
public
threaded_object
{
/*!
WHAT THIS OBJECT REPRESENTS
This object contains the base members of the timer
_kernel_2
object.
This object contains the base members of the timer object.
It exists so that we can access them from outside any templated functions.
!*/
...
...
@@ -32,11 +33,11 @@ namespace dlib
// ----------------------------------------------------------------------------------------
class
timer_
kernel_2_
global_clock
:
private
threaded_object
class
timer_global_clock
:
private
threaded_object
{
/*!
This object sets up a timer that triggers the action function
for timer
_kernel_2
objects that are tracked inside this object.
for timer objects that are tracked inside this object.
INITIAL VALUE
- shutdown == false
- running == false
...
...
@@ -47,15 +48,15 @@ namespace dlib
- else (running) then
- thread() is running
- tm[time] == pointer to a timer_
kernel_2_
base object
- tm[time] == pointer to a timer_base object
!*/
typedef
binary_search_tree
<
uint64
,
timer_
kernel_2_
base
*
,
memory_manager
<
char
>::
kernel_2b
>::
kernel_2a_c
time_map
;
typedef
binary_search_tree
<
uint64
,
timer_base
*
,
memory_manager
<
char
>::
kernel_2b
>::
kernel_2a_c
time_map
;
public
:
~
timer_
kernel_2_
global_clock
();
~
timer_global_clock
();
void
add
(
timer_
kernel_2_
base
*
r
timer_base
*
r
);
/*!
requires
...
...
@@ -69,7 +70,7 @@ namespace dlib
!*/
void
remove
(
timer_
kernel_2_
base
*
r
timer_base
*
r
);
/*!
requires
...
...
@@ -81,7 +82,7 @@ namespace dlib
!*/
void
adjust_delay
(
timer_
kernel_2_
base
*
r
,
timer_base
*
r
,
unsigned
long
new_delay
);
/*!
...
...
@@ -95,10 +96,10 @@ namespace dlib
mutex
m
;
friend
shared_ptr_thread_safe
<
timer_
kernel_2_
global_clock
>
get_global_clock
();
friend
shared_ptr_thread_safe
<
timer_global_clock
>
get_global_clock
();
private
:
timer_
kernel_2_
global_clock
();
timer_global_clock
();
time_map
tm
;
signaler
s
;
...
...
@@ -112,10 +113,10 @@ namespace dlib
- spawns timer tasks as is appropriate
!*/
};
shared_ptr_thread_safe
<
timer_
kernel_2_
global_clock
>
get_global_clock
();
shared_ptr_thread_safe
<
timer_global_clock
>
get_global_clock
();
/*!
ensures
- returns the global instance of the timer_
kernel_2_
global_clock object
- returns the global instance of the timer_global_clock object
!*/
// ----------------------------------------------------------------------------------------
...
...
@@ -123,7 +124,7 @@ namespace dlib
template
<
typename
T
>
class
timer
_kernel_2
:
private
timer_kernel_2
_base
class
timer
:
private
timer
_base
{
/*!
INITIAL VALUE
...
...
@@ -150,14 +151,19 @@ namespace dlib
public
:
// These typedefs are here for backwards compatibility with previous versions of
// dlib.
typedef
timer_heavy
<
T
>
kernel_1a
;
typedef
timer
kernel_2a
;
typedef
void
(
T
::*
af_type
)();
timer
_kernel_2
(
timer
(
T
&
ao_
,
af_type
af_
);
virtual
~
timer
_kernel_2
(
virtual
~
timer
(
);
void
clear
(
...
...
@@ -203,11 +209,11 @@ namespace dlib
// data members
T
&
ao
;
const
af_type
af
;
shared_ptr_thread_safe
<
timer_
kernel_2_
global_clock
>
gc
;
shared_ptr_thread_safe
<
timer_global_clock
>
gc
;
// restricted functions
timer
_kernel_2
(
const
timer_kernel_2
&
);
// copy constructor
timer
_kernel_2
&
operator
=
(
const
timer_kernel_2
&
);
// assignment operator
timer
(
const
timer
&
);
// copy constructor
timer
&
operator
=
(
const
timer
&
);
// assignment operator
};
...
...
@@ -220,8 +226,8 @@ namespace dlib
template
<
typename
T
>
timer
_kernel_2
<
T
>::
timer
_kernel_2
(
timer
<
T
>::
timer
(
T
&
ao_
,
af_type
af_
)
:
...
...
@@ -240,8 +246,8 @@ namespace dlib
template
<
typename
T
>
timer
_kernel_2
<
T
>::
~
timer
_kernel_2
(
timer
<
T
>::
~
timer
(
)
{
clear
();
...
...
@@ -253,7 +259,7 @@ namespace dlib
template
<
typename
T
>
void
timer
_kernel_2
<
T
>::
void
timer
<
T
>::
clear
(
)
{
...
...
@@ -269,7 +275,7 @@ namespace dlib
template
<
typename
T
>
typename
timer
_kernel_2
<
T
>::
af_type
timer_kernel_2
<
T
>::
typename
timer
<
T
>::
af_type
timer
<
T
>::
action_function
(
)
const
{
...
...
@@ -281,7 +287,7 @@ namespace dlib
template
<
typename
T
>
const
T
&
timer
_kernel_2
<
T
>::
const
T
&
timer
<
T
>::
action_object
(
)
const
{
...
...
@@ -293,7 +299,7 @@ namespace dlib
template
<
typename
T
>
T
&
timer
_kernel_2
<
T
>::
T
&
timer
<
T
>::
action_object
(
)
{
...
...
@@ -305,7 +311,7 @@ namespace dlib
template
<
typename
T
>
bool
timer
_kernel_2
<
T
>::
bool
timer
<
T
>::
is_running
(
)
const
{
...
...
@@ -318,7 +324,7 @@ namespace dlib
template
<
typename
T
>
unsigned
long
timer
_kernel_2
<
T
>::
unsigned
long
timer
<
T
>::
delay_time
(
)
const
{
...
...
@@ -331,7 +337,7 @@ namespace dlib
template
<
typename
T
>
void
timer
_kernel_2
<
T
>::
void
timer
<
T
>::
set_delay_time
(
unsigned
long
milliseconds
)
...
...
@@ -345,7 +351,7 @@ namespace dlib
template
<
typename
T
>
void
timer
_kernel_2
<
T
>::
void
timer
<
T
>::
start
(
)
{
...
...
@@ -362,7 +368,7 @@ namespace dlib
template
<
typename
T
>
void
timer
_kernel_2
<
T
>::
void
timer
<
T
>::
stop
(
)
{
...
...
@@ -377,7 +383,7 @@ namespace dlib
template
<
typename
T
>
void
timer
_kernel_2
<
T
>::
void
timer
<
T
>::
thread
(
)
{
...
...
@@ -396,7 +402,7 @@ namespace dlib
template
<
typename
T
>
void
timer
_kernel_2
<
T
>::
void
timer
<
T
>::
stop_and_wait
(
)
{
...
...
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