Page Menu
Home
Phabricator (Chris)
Search
Configure Global Search
Log In
Files
F619460
timer.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None
timer.cpp
View Options
#include
<time.h>
#include
"r-tech1/timer.h"
#include
"r-tech1/init.h"
#include
"r-tech1/funcs.h"
#include
"r-tech1/thread.h"
namespace
Util
{
void
*
do_wait
(
void
*
timer_
){
Timer
*
timer
=
(
Timer
*
)
timer_
;
unsigned
int
now
=
Global
::
second_counter
;
/* add 1 because the current time is in between X and X+1 */
while
(
Global
::
second_counter
-
now
<
timer
->
wait
+
1
){
Util
::
rest
(
50
);
bool
do_stop
=
false
;
Thread
::
acquireLock
(
&
timer
->
lock
);
do_stop
=
timer
->
stopped
;
Thread
::
releaseLock
(
&
timer
->
lock
);
if
(
do_stop
){
return
NULL
;
}
}
timer
->
func
(
timer
->
arg
);
return
NULL
;
}
Timer
::
Timer
(
unsigned
int
seconds_to_wait
,
timeout
func
,
void
*
arg
)
:
wait
(
seconds_to_wait
),
func
(
func
),
arg
(
arg
),
stopped
(
false
){
Thread
::
initializeLock
(
&
lock
);
Thread
::
createThread
(
&
timer
,
NULL
,
(
Util
::
Thread
::
ThreadFunction
)
do_wait
,
this
);
}
void
Timer
::
stop
(){
Thread
::
acquireLock
(
&
lock
);
stopped
=
true
;
Thread
::
releaseLock
(
&
lock
);
Thread
::
joinThread
(
timer
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-c++
Expires
Sat, Nov 14, 4:46 PM (9 h, 34 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
111979
Default Alt Text
timer.cpp (1 KB)
Attached To
Mode
R75 R-Tech1
Attached
Detach File
Event Timeline