Add time constants representing +/- infinity, don't schedule an alarm that will never run

This commit is contained in:
Jeremy Lakeman 2013-12-04 15:07:14 +10:30
parent 3b14543750
commit 68b8f94b01
2 changed files with 6 additions and 0 deletions

View File

@ -103,6 +103,10 @@ int _schedule(struct __sourceloc __whence, struct sched_ent *alarm)
if (!alarm->function)
return WHY("Can't schedule if you haven't set the function pointer");
// don't bother to schedule an alarm that will (by definition) never run
if (alarm->alarm == TIME_NEVER_WILL)
return 0;
if (alarm->deadline < alarm->alarm)
alarm->deadline = alarm->alarm;

2
os.h
View File

@ -55,6 +55,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
typedef int64_t time_ms_t;
#define PRItime_ms_t PRId64
#define TIME_NEVER_WILL INT64_MAX
#define TIME_NEVER_HAS INT64_MIN
time_ms_t gettime_ms();
time_ms_t sleep_ms(time_ms_t milliseconds);