2012-03-20 16:57:58 +01:00
|
|
|
/*
|
|
|
|
* \brief C-library back end
|
|
|
|
* \author Christian Prochaska
|
|
|
|
* \date 2012-03-20
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 13:23:52 +01:00
|
|
|
* Copyright (C) 2008-2017 Genode Labs GmbH
|
2012-03-20 16:57:58 +01:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
2017-02-20 13:23:52 +01:00
|
|
|
* under the terms of the GNU Affero General Public License version 3.
|
2012-03-20 16:57:58 +01:00
|
|
|
*/
|
|
|
|
|
2017-02-10 22:38:37 +01:00
|
|
|
/* Libc includes */
|
2012-03-20 16:57:58 +01:00
|
|
|
#include <sys/time.h>
|
|
|
|
|
2017-02-10 22:38:37 +01:00
|
|
|
#include "task.h"
|
|
|
|
|
2012-03-20 16:57:58 +01:00
|
|
|
extern "C" __attribute__((weak))
|
|
|
|
int _nanosleep(const struct timespec *req, struct timespec *rem)
|
|
|
|
{
|
2018-12-03 14:37:54 +01:00
|
|
|
unsigned long sleep_ms = req->tv_sec*1000 + req->tv_nsec/1000000;
|
2012-03-20 16:57:58 +01:00
|
|
|
|
2018-12-03 14:37:54 +01:00
|
|
|
if (!sleep_ms) return 0;
|
2018-01-08 14:50:56 +01:00
|
|
|
|
2017-02-20 13:30:36 +01:00
|
|
|
struct Check : Libc::Suspend_functor { bool suspend() override { return true; } } check;
|
2018-12-03 14:37:54 +01:00
|
|
|
do { sleep_ms = Libc::suspend(check, sleep_ms); } while (sleep_ms);
|
2012-03-20 16:57:58 +01:00
|
|
|
|
|
|
|
if (rem) {
|
|
|
|
rem->tv_sec = 0;
|
|
|
|
rem->tv_nsec = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2016-08-16 15:44:42 +02:00
|
|
|
|
|
|
|
|
|
|
|
extern "C" __attribute__((weak))
|
|
|
|
int nanosleep(const struct timespec *req, struct timespec *rem)
|
|
|
|
{
|
|
|
|
return _nanosleep(req, rem);
|
|
|
|
}
|