Skip to content

Commit

Permalink
Add back DurationTimer to fix camera.msm8960 load
Browse files Browse the repository at this point in the history
cannot locate symbol "_ZN7android13DurationTimer5startEv"

Change-Id: I29d3283b644c773e6d798d17b2ef139a470048da
  • Loading branch information
dhacker29 authored and broodplank committed Nov 9, 2013
1 parent c48921b commit 0b37987
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 0 deletions.
39 changes: 39 additions & 0 deletions include/utils/Timers.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,43 @@ int toMillisecondTimeoutDelay(nsecs_t referenceTime, nsecs_t timeoutTime);
} // extern "C"
#endif

// ------------------------------------------------------------------
// C++ API

#ifdef __cplusplus

namespace android {
/*
* Time the duration of something.
*
* Includes some timeval manipulation functions.
*/
class DurationTimer {
public:
DurationTimer() {}
~DurationTimer() {}

// Start the timer.
void start();
// Stop the timer.
void stop();
// Get the duration in microseconds.
long long durationUsecs() const;

// Subtract two timevals. Returns the difference (ptv1-ptv2) in
// microseconds.
static long long subtractTimevals(const struct timeval* ptv1,
const struct timeval* ptv2);

// Add the specified amount of time to the timeval.
static void addToTimeval(struct timeval* ptv, long usec);

private:
struct timeval mStartWhen;
struct timeval mStopWhen;
};

}; // android
#endif // def __cplusplus

#endif // _LIBS_UTILS_TIMERS_H
62 changes: 62 additions & 0 deletions libutils/Timers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,65 @@ int toMillisecondTimeoutDelay(nsecs_t referenceTime, nsecs_t timeoutTime)
}
return timeoutDelayMillis;
}


/*
* ===========================================================================
* DurationTimer
* ===========================================================================
*/

using namespace android;

// Start the timer.
void DurationTimer::start(void)
{
gettimeofday(&mStartWhen, NULL);
}

// Stop the timer.
void DurationTimer::stop(void)
{
gettimeofday(&mStopWhen, NULL);
}

// Get the duration in microseconds.
long long DurationTimer::durationUsecs(void) const
{
return (long) subtractTimevals(&mStopWhen, &mStartWhen);
}

// Subtract two timevals. Returns the difference (ptv1-ptv2) in
// microseconds.
/*static*/ long long DurationTimer::subtractTimevals(const struct timeval* ptv1,
const struct timeval* ptv2)
{
long long stop = ((long long) ptv1->tv_sec) * 1000000LL +
((long long) ptv1->tv_usec);
long long start = ((long long) ptv2->tv_sec) * 1000000LL +
((long long) ptv2->tv_usec);
return stop - start;
}

// Add the specified amount of time to the timeval.
/*static*/ void DurationTimer::addToTimeval(struct timeval* ptv, long usec)
{
if (usec < 0) {
ALOG(LOG_WARN, "", "Negative values not supported in addToTimeval\n");
return;
}

// normalize tv_usec if necessary
if (ptv->tv_usec >= 1000000) {
ptv->tv_sec += ptv->tv_usec / 1000000;
ptv->tv_usec %= 1000000;
}

ptv->tv_usec += usec % 1000000;
if (ptv->tv_usec >= 1000000) {
ptv->tv_usec -= 1000000;
ptv->tv_sec++;
}
ptv->tv_sec += usec / 1000000;
}

0 comments on commit 0b37987

Please sign in to comment.