aboutsummaryrefslogtreecommitdiff
path: root/src/lib/util/test_scheduler_hogging_priority.c
blob: 217a39ce7640aada87cd8663158863fa8b3be387 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "gnunet_util_lib.h"
#include <unistd.h>

static int count = 0;
static int final_count;

static void end (void *cls)
{
  final_count = count;
  count = 5000;
  GNUNET_SCHEDULER_shutdown ();
}

static void self_rescheduling (void *cls)
{
  if (count == 0)
  {
    GNUNET_SCHEDULER_add_delayed_with_priority (GNUNET_TIME_UNIT_MILLISECONDS,
                                                GNUNET_SCHEDULER_PRIORITY_URGENT,
                                                &end,
                                                NULL);
    sleep(1);
    /* end should be added to ready queue on next scheduler pass for certain
       now */
  }
  if (++count < 5000)
  {
    GNUNET_SCHEDULER_add_now (&self_rescheduling, NULL);
  }
}


static void noop (void *cls)
{
}

static void indirection (void *cls)
{
  GNUNET_SCHEDULER_add_with_reason_and_priority (&self_rescheduling, NULL,
                                                 GNUNET_SCHEDULER_REASON_STARTUP,
                                                 GNUNET_SCHEDULER_PRIORITY_HIGH);
}

static void init (void *cls)
{
  GNUNET_SCHEDULER_add_now (&indirection, NULL);
  GNUNET_SCHEDULER_add_now (&noop, NULL);
}


int main (int argc, char **argv)
{
  GNUNET_SCHEDULER_run (&init, NULL);
  return final_count < 5000 ? 0 : 1;
}