【发布时间】:2014-05-03 17:25:16
【问题描述】:
ualarm() 未在 Android 版本的 libc、bionic 中实现(检查 Bionic unistd.h)。此外,ualarm() 已过时。
我在 Android NDK 上移植一个应用程序,所以我需要一个等效的 ualarm(999999,999999),即会定期发送 SIGALRM(每秒)的东西.
也许timer_create() ?好像是implemented in Bionic。但是man page中的例子真的不简单……
我愿意移植到 Android (NDK) 的代码:
/*
* Set a recurring 1 second timer that will call sigalrm() and switch to
* a new channel.
*/
act.sa_handler = sigalrm_handler;
sigaction (SIGALRM, &act, 0);
ualarm(CHANNEL_INTERVAL, CHANNEL_INTERVAL);
change_channel(1);
/* Whenever a SIGALRM is thrown, go to the next 802.11 channel */
void sigalrm_handler(int x)
{
next_channel();
}
【问题讨论】:
-
答案在 Linux ualarm() 手册页中:
This function is obsolete. Use setitimer(2) or POSIX interval timers (timer_create(2), etc.) instead. -
谢谢,但这就是我在这个问题中想到的原因。我刚刚花了 1 个小时来完成相关代码的工作。还有 1 个小时来创建删除计时器代码,因为 ualarm(0, 0) 等效项需要计时器参考...(将更新答案)。
标签: android linux android-ndk libc bionic