// // Purpose: vprintf with where // void SB_Trace::trace_where_vprintf(void *pp_ra, const char *pp_where, const char *pp_format, va_list pv_ap) { int lv_err; fpos64_t lv_pos; sigset_t lv_set_old; if (ip_trace_file == NULL) { // don't bother, if not initialized if (iv_trace_assert_no_trace) SB_util_assert_pne(ip_trace_file, NULL); } else { if (iv_trace_sig_hdlr) gv_trace_sig.lock(&lv_set_old); if (iv_trace_lock) gv_trace_mutex.lock(); if (iv_trace_max_size && (iv_trace_max_size != INT_MAX)) { lv_err = fgetpos64(ip_trace_file, &lv_pos); if (!lv_err && (lv_pos.__pos > iv_trace_max_size)) abort(); // can't use SB_util_abort } trace_print_time_id(); trace_print_ra(pp_ra, pp_where); trace_print_format(pp_format, pv_ap); if (iv_trace_lock) gv_trace_mutex.unlock(); if (iv_trace_sig_hdlr) gv_trace_sig.unlock(&lv_set_old); } }
void SB_Smap::putv(Key_Type pp_key, void *pp_value) { SML_Type *lp_item; int lv_hash; int lv_len; SB_util_assert_cpne(pp_key, NULL); // sw fault SB_util_assert_pne(pp_value, NULL); // sw fault SB_Smap::removev(pp_key); lv_hash = hash(pp_key, iv_buckets); lp_item = new SML_Type; lp_item->iv_link.ip_next = reinterpret_cast<SB_QL_Type *>(ipp_HT[lv_hash]); lv_len = static_cast<int>(strlen(pp_key)); lp_item->ip_key = new char[lv_len+1]; strcpy(lp_item->ip_key, pp_key); lp_item->ip_value = NULL; lp_item->ip_vvalue = pp_value; lp_item->iv_use_vvalue = true; ipp_HT[lv_hash] = lp_item; iv_count++; iv_mod++; #ifdef USE_SB_MAP_STATS ip_stats->chain_add(lv_hash); // putv #endif #ifdef SMAP_CHECK check_integrity(); #endif // SMAP_CHECK if (iv_count > iv_buckets_threshold) SB_Smap::resize(iv_buckets_resize); }
SB_Timer::Timer::Timer(TH *pp_th, long pv_user_param, Tics pv_interval, bool pv_start) { const char *WHERE = "Timer::Timer"; SB_util_assert_pne(pp_th, NULL); ip_th = pp_th; iv_user_param = pv_user_param; if (pv_interval > ((MAX_SLOTS-1) * TICS_PER_SLOT)) // Don't allow interval that would cause a wrap-around of // the timer slots array. pv_interval = (MAX_SLOTS-1) * TICS_PER_SLOT; else if (pv_interval < 0) pv_interval = 0; iv_interval = pv_interval; ip_next = NULL; iv_running = false; if (cv_trace_enabled) trace_where_printf(WHERE, "timer=%p, user-param=%ld, interval=" PF64 ", start=%d\n", pfp(this), iv_user_param, iv_interval, pv_start); if (pv_start) start(); }
SB_Timer_Comp_Queue *sb_timer_comp_q_get_tid(int pv_tid) { Timer_TQ_Node *lp_node; lp_node = static_cast<Timer_TQ_Node *>(gv_timer_tpop_tid_map.get(pv_tid)); SB_util_assert_pne(lp_node, NULL); // sw fault return lp_node->ip_comp_q; }
// // Purpose: event manager - de-register TLS destructor // void SB_Ms_Event_Mgr::deregister_tls_dtor(int pv_inx) { const char *WHERE = "SB_Ms_Event_Mgr::deregister_tls_dtor"; SB_util_assert_pne(ia_tls_dtor[pv_inx].ip_dtor, NULL); ia_tls_dtor[pv_inx].ip_dtor = NULL; if (gv_ms_trace_events) trace_printf(WHERE, "inx=%d\n", pv_inx); }
// // Purpose: unlock // void SB_Trace::trace_unlock() { sigset_t *lp_set_old; if (iv_trace_lock) gv_trace_mutex.unlock(); if (iv_trace_sig_hdlr) { lp_set_old = static_cast<sigset_t *>(pthread_getspecific(gv_otrace_tls_inx)); SB_util_assert_pne(lp_set_old, NULL); gv_trace_sig.unlock(lp_set_old); } }
// // Purpose: nolock-vprintf // void SB_Trace::trace_nolock_vprintf(void *pp_ra, const char *pp_format, va_list pv_ap) { if (ip_trace_file == NULL) { // don't bother, if not initialized if (iv_trace_assert_no_trace) SB_util_assert_pne(ip_trace_file, NULL); } else { trace_print_time_id(); trace_print_ra(pp_ra, NULL); trace_print_format(pp_format, pv_ap); } }
void SB_Thread::Thread::start() { if (ip_id == NULL) { // allow multiple starts #ifdef SB_THREAD_PRINT_THREAD_CALLS trace_printf("Thread::start() ENTRY, name=%s\n", ip_name); #endif ip_id = Sthr::create(ip_name, thread_fun, this); if (iv_daemon & (ip_id != NULL)) { int lv_ret = Sthr::detach(ip_id); SB_util_assert_ieq(lv_ret, 0); // sw fault lv_ret = lv_ret; // touch (in case assert disabled) } #ifdef SB_THREAD_PRINT_THREAD_CALLS trace_printf("Thread::start() EXIT, ret=%p\n", ip_id); #endif } SB_util_assert_pne(ip_id, NULL); // sw fault }
// // Purpose: print data // void SB_Trace::trace_print_data(void *pp_buf, int pv_count, int pv_max_count) { enum { MAX_LINE_LEN = 132 }; enum { HEX_DIGIT_OFFSET = 10 }; enum { ASCII_OFFSET = HEX_DIGIT_OFFSET + 52 }; char la_line[MAX_LINE_LEN]; char *lp_ascii; char *lp_buf; char *lp_hex; long lv_addr; int lv_byte; int lv_inx; int lv_max; sigset_t lv_set_old; if (ip_trace_file == NULL) { // don't bother, if not initialized if (iv_trace_assert_no_trace) SB_util_assert_pne(ip_trace_file, NULL); } else { if (iv_trace_sig_hdlr) gv_trace_sig.lock(&lv_set_old); if (iv_trace_lock) gv_trace_mutex.lock(); if ((pv_max_count > 0) && (pv_count > pv_max_count)) { trace_print_fprintf("count=%d exceeds %d, TRUNCATED\n", pv_count, pv_max_count); pv_count = pv_max_count; // limit } lv_addr = 0; lp_buf = static_cast<char *>(pp_buf); trace_clear_line(la_line); while (pv_count > 0) { if (pv_count < 16) lv_max = pv_count; else lv_max = 16; lp_hex = &la_line[HEX_DIGIT_OFFSET]; lp_ascii = &la_line[ASCII_OFFSET]; sprintf(la_line, "%08lx: ", lv_addr); for (lv_inx = 0; lv_inx < lv_max; lv_inx++, lp_buf++, lp_hex += 3, lp_ascii++) { lv_byte = (*lp_buf) & 0xff; sprintf(lp_hex, "%02x ", lv_byte); if (isprint(lv_byte)) *lp_ascii = static_cast<char>(lv_byte); else *lp_ascii = '.'; } *lp_hex = ' '; trace_print_fprintf("%s\n", la_line); trace_clear_line(la_line); lv_addr += lv_max; pv_count -= lv_max; } if (iv_trace_lock) gv_trace_mutex.unlock(); if (iv_trace_sig_hdlr) gv_trace_sig.unlock(&lv_set_old); } }
static short sb_timer_cancel_com(const char *pp_where, short pv_tag, bool pv_cc) { SB_Timer_Comp_Queue *lp_comp_q; Timer_TLE_Type *lp_tle; short lv_fserr; bool lv_start_timer; int lv_status; SB_To lv_to; if (gv_ms_trace_params) trace_where_printf(pp_where, "ENTER tag=%d\n", pv_tag); if (gv_timer_alloc) sb_timer_alloc(); if ((pv_tag <= 0) || (pv_tag >= TIMER_MAX_TLES)) { if (gv_ms_trace_timer) trace_where_printf(pp_where, "tag out-of-bounds\n"); if (pv_cc) lv_fserr = XZFIL_ERR_INVALOP; // CCG else lv_fserr = XZFIL_ERR_BOUNDSERR; } else { lv_status = gv_timer_mutex.lock(); SB_util_assert_ieq(lv_status, 0); lp_tle = &gp_timer_tles[pv_tag]; if (lp_tle->iv_inuse) { if (gp_timer_head == lp_tle) { // cancel head - may need to restart timer if (lp_tle->ip_next == NULL) lv_to = 0; else lv_to = lp_tle->ip_next->iv_to; lv_start_timer = true; } else { lv_to = 0; // initialize for compiler lv_start_timer = false; } lv_fserr = XZFIL_ERR_OK; // delink switch (lp_tle->iv_on_list) { case LIST_TIMER: if (gp_timer_head == lp_tle) gp_timer_head = lp_tle->ip_next; if (gp_timer_tail == lp_tle) gp_timer_tail = lp_tle->ip_prev; if (lp_tle->ip_prev != NULL) lp_tle->ip_prev->ip_next = lp_tle->ip_next; if (lp_tle->ip_next != NULL) lp_tle->ip_next->ip_prev = lp_tle->ip_prev; sb_timer_tle_free(lp_tle); break; case LIST_COMP: lp_comp_q = lp_tle->ip_comp_q; SB_util_assert_ieq(lp_tle->iv_kind, TIMER_TLE_KIND_COMPQ); // sw fault SB_util_assert_pne(lp_comp_q, NULL); // sw fault lp_comp_q->remove_list(&lp_tle->iv_link); if (gv_ms_trace_timer) sb_timer_comp_q_print(lp_comp_q); sb_timer_tle_free(lp_tle); break; case LIST_NONE: // not on any list, can't cancel if (gv_ms_trace_timer) trace_where_printf(pp_where, "TLE not on list\n"); if (pv_cc) lv_fserr = XZFIL_ERR_INVALOP; // CCG else lv_fserr = XZFIL_ERR_INVALOP; break; default: SB_util_abort("invalid iv_on_list"); // sw fault break; } if (gv_ms_trace_timer) sb_timer_timer_list_print(); if (lv_start_timer) sb_timer_setitimer_retry(pp_where, lv_to); } else { if (gv_ms_trace_timer) trace_where_printf(pp_where, "TLE not in use\n"); if (pv_cc) lv_fserr = XZFIL_ERR_INVALOP; // CCG else lv_fserr = XZFIL_ERR_NOTFOUND; } lv_status = gv_timer_mutex.unlock(); SB_util_assert_ieq(lv_status, 0); } if (gv_ms_trace_params) trace_where_printf(pp_where, "EXIT ret=%d\n", lv_fserr); return lv_fserr; }
void SB_Timer::Timer::cancel_int(bool pv_lock) { const char *WHERE = "Timer::cancel"; char la_fmt_pop[100]; Timer *lp_curr; Timer *lp_next; Slot_Type lv_slot; int lv_status; if (!iv_running) return; lv_slot = hash(iv_pop_time); if (cv_trace_enabled) trace_where_printf(WHERE, "timer=%p, user-param=%ld, pop time=%s, slot=%d\n", pfp(this), iv_user_param, format_pop_time(la_fmt_pop), lv_slot); if (pv_lock) { lv_status = cv_mutex.lock(); SB_util_assert_ieq(lv_status, 0); // sw fault } lp_curr = ca_slots[lv_slot]; SB_util_assert_pne(lp_curr, NULL); if (lp_curr == this) { ca_slots[lv_slot] = ip_next; ip_next = NULL; iv_running = false; if (pv_lock) { lv_status = cv_mutex.unlock(); SB_util_assert_ieq(lv_status, 0); // sw fault } return; } while (lp_curr != NULL) { lp_next = lp_curr->ip_next; if (lp_next == this) { lp_curr->ip_next = ip_next; ip_next = NULL; iv_running = false; if (pv_lock) { lv_status = cv_mutex.unlock(); SB_util_assert_ieq(lv_status, 0); // sw fault } return; } lp_curr = lp_next; } // // shouldn't get here if timer is running. // SB_util_assert_bt(false); }