added macro that takes care of boilerplate "check for timeout and return progress" code.

This was SVN commit r2242.
This commit is contained in:
janwas 2005-05-04 23:10:11 +00:00
parent 216eb8d2fe
commit 1bcf156680
2 changed files with 18 additions and 2 deletions

View File

@ -88,4 +88,20 @@ extern int LDR_ProgressiveLoad(double time_budget, wchar_t* next_description,
// immediately process all queued load requests.
// returns 0 on success, something else on failure.
extern int LDR_NonprogressiveLoad();
extern int LDR_NonprogressiveLoad();
// boilerplate check-if-timed-out and return-progress-percent code.
// completed_jobs and total_jobs are ints and must be updated by caller.
// assumes presence of a local variable (double)<end_time>
// (as returned by get_time()) that indicates the time at which to abort.
#define LDR_CHECK_TIMEOUT(completed_jobs, total_jobs)\
if(get_time() > end_time)\
{\
int progress_percent = (completed_jobs*100 / total_jobs);\
/* 0 means "finished", so don't return that! */\
if(progress_percent == 0)\
progress_percent = 1;\
assert2(0 < progress_percent && progress_percent <= 100);\
return progress_percent;\
}

View File

@ -58,4 +58,4 @@ template<class T, class Arg> void RegMemFun1(T* this_, int(T::*func)(Arg), Arg a
{
void* param = new MemFun1_t<T, Arg>(this_, func, arg);
THROW_ERR(LDR_Register(MemFun1Thunk<T, Arg>, param, description, estimated_duration_ms));
}
}