Esempio n. 1
0
//
// Purpose: event manager - register tls destructor
//
void SB_Ms_Event_Mgr::register_tls_dtor(int    pv_inx,
                                        void (*pp_dtor)(void *pp_data),
                                        void  *pp_data) {
    const char *WHERE = "SB_Ms_Event_Mgr::register_tls_dtor";

    SB_util_assert_peq(ia_tls_dtor[pv_inx].ip_dtor, NULL);
    ia_tls_dtor[pv_inx].iv_dtor = pp_dtor;
    ia_tls_dtor_data[pv_inx] = pp_data;
    if (gv_ms_trace_events)
        trace_where_printf(WHERE, "inx=%d, data=%p\n", pv_inx, pp_data);
}
Esempio n. 2
0
//
// timer-module shutdown
//
void sb_timer_shutdown() {
    const char *WHERE = "sb_timer_shutdown";
    enum      { MAX_TIMER_NODES = 10 };
    long        la_node[MAX_TIMER_NODES];
    void       *lp_result;
    int         lv_inx;
    int         lv_max;

    if (gv_ms_trace_params || gv_ms_trace_timer)
        trace_where_printf(WHERE, "ENTER\n");
    if (gp_timer_thr != NULL) {
        gp_timer_thr->shutdown();
        gp_timer_thr->join(&lp_result);
        SB_util_assert_peq(lp_result, NULL); // sw fault
        delete gp_timer_thr;
        gp_timer_thr = NULL;
    }
    delete [] gp_timer_tles;

    // remove
    while (gv_timer_tpop_map.size()) {
        SB_Lmap_Enum *lp_enum = gv_timer_tpop_map.keys();
        for (lv_max = 0;
             lp_enum->more() && (lv_max < MAX_TIMER_NODES);
             lv_max++)
            la_node[lv_max] = lp_enum->next()->iv_id.l;
        for (lv_inx = 0; lv_inx < lv_max; lv_inx++) {
            Timer_TQ_Node *lp_node =
              static_cast<Timer_TQ_Node *>(gv_timer_tpop_map.remove(la_node[lv_inx]));
            delete lp_node;
        }
        delete lp_enum;
    }
    while (gv_timer_tpop_tid_map.size()) {
        SB_Lmap_Enum *lp_enum = gv_timer_tpop_tid_map.keys();
        for (lv_max = 0;
             lp_enum->more() && (lv_max < MAX_TIMER_NODES);
             lv_max++)
            la_node[lv_max] = lp_enum->next()->iv_id.l;
        for (lv_inx = 0; lv_inx < lv_max; lv_inx++) {
            Timer_TQ_Node *lp_node =
              static_cast<Timer_TQ_Node *>(gv_timer_tpop_tid_map.remove(la_node[lv_inx]));
            delete lp_node;
        }
        delete lp_enum;
    }
    if (gv_ms_trace_params || gv_ms_trace_timer)
        trace_where_printf(WHERE, "EXIT\n");
}
Esempio n. 3
0
//
// Purpose: destructor event-manager
//
SB_Ms_Event_Mgr::~SB_Ms_Event_Mgr() {
    const char *WHERE = "SB_Ms_Event_Mgr::~SB_Ms_Event_Mgr";
    int         lv_status;

    if (gv_ms_trace_events)
        trace_where_printf(WHERE, "ENTER id=%ld, mgr=%p\n",
                           iv_id, pfp(this));
    if (!iv_mutex_locked) {
        lv_status = cv_sl_map.lock();
        SB_util_assert_ieq(lv_status, 0);
    }
    cv_all_list.remove_list(&iv_all_list_entry.iv_link);
    cv_all_map.remove(iv_all_map_entry.iv_link.iv_id.l);
    if (!iv_mutex_locked) {
        lv_status = cv_sl_map.unlock();
        SB_util_assert_ieq(lv_status, 0);
    }
    for (int lv_event = 0; lv_event < EVENT_MAX; lv_event++)
        ca_reg_map[lv_event].remove(ia_reg_entry[lv_event].iv_link.iv_id.l);
    if (iv_pin >= 0) {
        Map_Pin_Entry_Type *lp_entry =
          static_cast<Map_Pin_Entry_Type *>(cv_pin_map.remove(iv_pin));
        SB_util_assert_peq(lp_entry, &iv_pin_entry); // sw fault
        lp_entry = lp_entry; // touch (in case assert disabled)
        if (gv_ms_trace_events)
            trace_where_printf(WHERE, "id=%ld, mgr=%p, deleting pin=%d\n",
                               iv_id, pfp(this), iv_pin);
    }
    if (iv_group_entry.ip_map != NULL)
        delete iv_group_entry.ip_map;
    // Clear TLS
    if (iv_tls_inx >= 0) {
        lv_status = SB_Thread::Sthr::specific_set(iv_tls_inx, NULL);
        SB_util_assert_ieq(lv_status, 0);
    }

    // destroy CV
    do {
        lv_status = iv_cv.destroy();
        if (lv_status == EBUSY)
            usleep(100);
    } while (lv_status);

    if (gv_ms_trace_events)
        trace_where_printf(WHERE, "EXIT id=%ld, mgr=%p\n",
                           iv_id, pfp(this));
}
Esempio n. 4
0
//
// print timer list
//
void sb_timer_timer_list_print() {
    char            la_info[50];
    char            la_to[40];
    Timer_TLE_Type *lp_tle;
    Timer_TLE_Type *lp_tle_prev;

    lp_tle = gp_timer_head;
    lp_tle_prev = NULL;
    if (lp_tle != NULL)
        trace_printf("TIMER timer list\n");
    while (lp_tle != NULL) {
        sb_timer_to_fmt(la_to, lp_tle->iv_to);
        switch (lp_tle->iv_kind) {
        case TIMER_TLE_KIND_CB:
            sprintf(la_info, "cb=%p", SB_CB_TO_PTR(lp_tle->iv_cb));
            break;
        case TIMER_TLE_KIND_COMPQ:
            sprintf(la_info, "q=%p", pfp(lp_tle->ip_comp_q));
            break;
        default:
            strcpy(la_info, "?");
            SB_util_abort("invalid iv_kind"); // sw fault
            break;
        }
        trace_printf("tle id=%d, addr=%p, p=%p, n=%p, %s, stid=%d, ttid=%d, mgr=%p, to=%s, toval=%d, p1=%d(0x%x), p2=%ld(0x%lx)\n",
                     lp_tle->iv_tleid,
                     pfp(lp_tle),
                     pfp(lp_tle->ip_prev),
                     pfp(lp_tle->ip_next),
                     la_info,
                     lp_tle->iv_stid,
                     lp_tle->iv_ttid,
                     pfp(lp_tle->ip_mgr),
                     la_to,
                     lp_tle->iv_toval,
                     lp_tle->iv_parm1,
                     lp_tle->iv_parm1,
                     lp_tle->iv_parm2,
                     lp_tle->iv_parm2);
        SB_util_assert_peq(lp_tle->ip_prev, lp_tle_prev);
        lp_tle_prev = lp_tle;
        lp_tle = lp_tle->ip_next;
    }
}
Esempio n. 5
0
//
// Purpose: constructor event-manager
//
SB_Ms_Event_Mgr::SB_Ms_Event_Mgr(long pv_id, int pv_tls_inx)
: ip_waiter_next(NULL), ip_waiter_prev(NULL),
  iv_awake(0), iv_awake_event(0), iv_mutex_locked(false), iv_replies(0),
  iv_tls_inx(pv_tls_inx),
  iv_wait_start_time(0), iv_wait_us(0) {
    const char *WHERE = "SB_Ms_Event_Mgr::SB_Ms_Event_Mgr";
    int         lv_inx;
    int         lv_status;

    iv_cv.setname("cv-SB_Ms_Event_Mgr::iv_cv");
    iv_event_mutex.setname("mutex-SB_Ms_Event_Mgr::iv_event_mutex");
    for (lv_inx = 0; lv_inx < TLS_DTOR_MAX; lv_inx++) {
        ia_tls_dtor[lv_inx].ip_dtor = NULL;
        ia_tls_dtor_data[lv_inx] = NULL;
    }

    iv_group = -1;
    iv_pin = -1;
    if (pv_id < 0)
        iv_id = SB_Thread::Sthr::self_id();
    else
        iv_id = pv_id;
    iv_all_list_entry.iv_link.iv_id.l = iv_id;
    iv_all_list_entry.ip_mgr = this;
    iv_all_map_entry.iv_link.iv_id.l = iv_id;
    iv_all_map_entry.ip_mgr = this;
    for (int lv_event = 0; lv_event < EVENT_MAX; lv_event++)
        memset(&ia_reg_entry[lv_event], 0, sizeof(ia_reg_entry[lv_event]));
    lv_status = cv_sl_map.lock();
    SB_util_assert_ieq(lv_status, 0);
    cv_all_list.add(&iv_all_list_entry.iv_link);
    SB_util_assert_peq(cv_all_map.get(iv_id), NULL);
    cv_all_map.put(reinterpret_cast<SB_LML_Type *>(&iv_all_map_entry.iv_link));
    lv_status = cv_sl_map.unlock();
    SB_util_assert_ieq(lv_status, 0);
    iv_group_entry.ip_map = NULL;
    if (gv_ms_trace_events)
        trace_where_printf(WHERE, "id=%ld, mgr=%p\n", iv_id, pfp(this));
}