1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-26 15:13:27 +01:00

Merge pull request #374 from quininer/master

sleep use tox_iteration_interval
This commit is contained in:
JFreegman 2016-01-11 04:09:56 -05:00
commit 88e74224ed

View File

@ -1177,25 +1177,6 @@ static void init_default_data_files(void)
free(user_config_dir);
}
#define REC_TOX_DO_LOOPS_PER_SEC 25
/* Adjusts usleep value so that tox_do runs close to the recommended number of times per second */
static useconds_t optimal_msleepval(uint64_t *looptimer, uint64_t *loopcount, uint64_t cur_time, useconds_t msleepval)
{
useconds_t new_sleep = MAX(msleepval, 3);
++(*loopcount);
if (*looptimer == cur_time)
return new_sleep;
if (*loopcount != REC_TOX_DO_LOOPS_PER_SEC)
new_sleep *= (double) *loopcount / REC_TOX_DO_LOOPS_PER_SEC;
*looptimer = cur_time;
*loopcount = 0;
return new_sleep;
}
// this doesn't do anything (yet)
#ifdef X11
void DnD_callback(const char* asdv, DropType dt)
@ -1327,9 +1308,6 @@ int main(int argc, char **argv)
execute(prompt->chatwin->history, prompt, m, avatarstr, GLOBAL_COMMAND_MODE);
uint64_t last_save = (uint64_t) time(NULL);
uint64_t looptimer = last_save;
useconds_t msleepval = 40000;
uint64_t loopcount = 0;
while (true) {
do_toxic(m, prompt);
@ -1345,8 +1323,7 @@ int main(int argc, char **argv)
last_save = cur_time;
}
msleepval = optimal_msleepval(&looptimer, &loopcount, cur_time, msleepval);
usleep(msleepval);
usleep(tox_iteration_interval(m) * 1000);
}
return 0;