root/orte/test/system/opal-evpri-test.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. cbfunc
  2. die
  3. t1func
  4. main

   1 #include <stdio.h>
   2 #include <stdlib.h>
   3 #include <signal.h>
   4 #include <stdbool.h>
   5 
   6 #include "opal/runtime/opal.h"
   7 #include "opal/mca/event/event.h"
   8 #include "orte/mca/state/state_types.h"
   9 
  10 #define SIGPRI 0
  11 #define TERMPRI 1
  12 
  13 static bool run=true;
  14 static int loops=0;
  15 
  16 static void
  17 cbfunc(evutil_socket_t fd, short what, void *arg)
  18 {
  19     fprintf(stderr, "CAUGHT SIGNAL\n");
  20     fflush(stderr);
  21 #if 0
  22     event_base_loopbreak(base);
  23 #endif
  24     run = false;
  25 }
  26 
  27 static void
  28 die(const char *msg)
  29 {
  30     fprintf(stderr, "%s\n", msg);
  31     fflush(stderr);
  32     exit(1);
  33 }
  34 
  35 static void
  36 t1func(evutil_socket_t fd, short what, void *arg)
  37 {
  38     orte_state_caddy_t *caddy = (orte_state_caddy_t*)arg;
  39     orte_state_caddy_t *c2;
  40 
  41     fprintf(stderr, "CAUGHT EVENT\n");
  42     fflush(stderr);
  43     loops++;
  44     if (loops < 10) {
  45         c2 = OBJ_NEW(orte_state_caddy_t);
  46         opal_event_set(orte_event_base, &c2->ev, -1, OPAL_EV_READ, t1func, c2);
  47         opal_event_set_priority(&c2->ev, ORTE_SYS_PRI);
  48 
  49         fprintf(stderr, "EVENT %d DEFINED\n", loops);
  50         fflush(stderr);
  51         opal_event_active(&c2->ev, OPAL_EV_WRITE, 1);
  52         fprintf(stderr, "EVENT %d ACTIVATED\n", loops);
  53         fflush(stderr);
  54     }
  55 
  56     OBJ_RELEASE(caddy);
  57 }
  58 
  59 int
  60 main(int argc, char **argv)
  61 {
  62     opal_event_t ev1, ev2;
  63     orte_state_caddy_t *caddy;
  64 
  65     opal_init(&argc, &argv);
  66 
  67     /* assign some signal traps */
  68     if (opal_event_signal_set(orte_event_base, &ev1, SIGTERM, cbfunc, &ev1) < 0) {
  69         die("event_assign");
  70     }
  71     if (opal_event_set_priority(&ev1, ORTE_ERROR_PRI) < 0) {
  72         die("event_set_pri");
  73     }
  74     if (opal_event_signal_add(&ev1, NULL) < 0) {
  75         die("event_add");
  76     }
  77     if (opal_event_signal_set(orte_event_base, &ev2, SIGPIPE, cbfunc, &ev2) < 0) {
  78         die("event_assign");
  79     }
  80     if (opal_event_set_priority(&ev2, ORTE_ERROR_PRI) < 0) {
  81         die("event_assign");
  82     }
  83     if (opal_event_signal_add(&ev2, NULL) < 0) {
  84         die("event_assign");
  85     }
  86     fprintf(stderr, "SIGNAL EVENTS DEFINED\n");
  87     fflush(stderr);
  88 
  89     /* assign a state event */
  90     caddy = OBJ_NEW(orte_state_caddy_t);
  91     opal_event_set(orte_event_base, &caddy->ev, -1, OPAL_EV_READ, t1func, caddy);
  92     opal_event_set_priority(&caddy->ev, ORTE_SYS_PRI);
  93     opal_event_active(&caddy->ev, OPAL_EV_WRITE, 1);
  94     fprintf(stderr, "FIRST EVENT DEFINED AND ACTIVATED\n");
  95     fflush(stderr);
  96 
  97     /*    event_dispatch(base); */
  98 
  99     while (run) {
 100         opal_event_loop(orte_event_base, OPAL_EVLOOP_ONCE);
 101     }
 102 
 103     fprintf(stderr, "EXITED LOOP - FINALIZING\n");
 104     fflush(stderr);
 105     opal_finalize();
 106     return 0;
 107 }

/* [<][>][^][v][top][bottom][index][help] */