mirror of
https://github.com/genodelabs/genode.git
synced 2025-01-31 16:35:28 +00:00
netperf: 'times_up' mechanism based on pthread
This commit is contained in:
parent
9e9614af13
commit
afc95e36e1
@ -11,14 +11,68 @@
|
|||||||
* under the terms of the GNU Affero General Public License version 3.
|
* under the terms of the GNU Affero General Public License version 3.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include <base/log.h>
|
#include <base/log.h>
|
||||||
|
|
||||||
/* defined in "ports/contrib/netperf/src/netlib.c" */
|
/* defined in "ports/contrib/netperf/src/netlib.c" */
|
||||||
extern "C" int times_up;
|
extern "C" int times_up;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
struct Timer_thread
|
||||||
|
{
|
||||||
|
pthread_t _pthread { };
|
||||||
|
pthread_attr_t _attr { };
|
||||||
|
pthread_mutex_t _mutex { PTHREAD_MUTEX_INITIALIZER };
|
||||||
|
|
||||||
|
int _seconds_left = 0;
|
||||||
|
|
||||||
|
void _entry()
|
||||||
|
{
|
||||||
|
for (;;) {
|
||||||
|
sleep(1);
|
||||||
|
|
||||||
|
pthread_mutex_lock(&_mutex);
|
||||||
|
if (_seconds_left) {
|
||||||
|
--_seconds_left;
|
||||||
|
if (_seconds_left == 0) {
|
||||||
|
times_up = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pthread_mutex_unlock(&_mutex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void *_entry(void *arg)
|
||||||
|
{
|
||||||
|
Timer_thread &myself = *(Timer_thread *)arg;
|
||||||
|
myself._entry();
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
Timer_thread()
|
||||||
|
{
|
||||||
|
pthread_mutex_init(&_mutex, nullptr);
|
||||||
|
pthread_create(&_pthread, &_attr, _entry, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void schedule_timeout(int seconds)
|
||||||
|
{
|
||||||
|
pthread_mutex_lock(&_mutex);
|
||||||
|
times_up = false;
|
||||||
|
_seconds_left = seconds;
|
||||||
|
pthread_mutex_unlock(&_mutex);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
extern "C" void
|
extern "C" void
|
||||||
start_timer(int time)
|
start_timer(int time)
|
||||||
{
|
{
|
||||||
Genode::warning(__func__, " not implemented, 'times_up' is never updated");
|
static Timer_thread timer_thread { };
|
||||||
|
|
||||||
|
timer_thread.schedule_timeout(time);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user