Пример #1
0
/**
 * Translate a tid given by pthread_self into an index.  Called by 
 * basetramps everywhere.
 **/
int DYNINSTthreadIndex() {
    dyntid_t tid;
    unsigned curr_index;

    rtdebug_printf("%s[%d]:  welcome to DYNINSTthreadIndex()\n", __FILE__, __LINE__);
    if (!DYNINSThasInitialized) {
      rtdebug_printf("%s[%d]: dyninst not initialized, ret false\n", __FILE__, __LINE__);
      return 0;
    }

    tid = (dyntid_t) ((unsigned long)dyn_pthread_self());
    rtdebug_printf("%s[%d]:  DYNINSTthreadIndex(): tid = %lu\n", __FILE__, __LINE__,
                   (unsigned long) tid);
    if (tid == (dyntid_t) DYNINST_SINGLETHREADED) return 0;
    rtdebug_printf("%s[%d]: calling thread index slow (modified)\n", __FILE__, __LINE__);
    curr_index = DYNINSTthreadIndexSLOW(tid);
    rtdebug_printf("%s[%d]: back from thread index slow\n", __FILE__, __LINE__);
    /* While DYNINST_max_num_threads is an error return for
       DYNINSTthreadIndexSLOW(), there's not really anything we
       can do about it at the moment, so just return it
       and let the mutatee scribble into the so-allocated memory. */
    if ( curr_index == DYNINST_NOT_IN_HASHTABLE ) {
        rtdebug_printf("%s[%d]:  DYNINSTthreadIndex(): failed to find index for %lu\n",
                __FILE__, __LINE__, tid);
        curr_index = DYNINST_max_num_threads;
    }

    rtdebug_printf("%s[%d]:  DYNINSTthreadIndex(): returning index: %d\n",
                   __FILE__, __LINE__, curr_index);
    return curr_index;
}
Пример #2
0
int DYNINSTthreadIndex ()
{
  int tid;
  int curr_index = DYNINSTthreadIndexFAST();
  if (!DYNINST_initialize_done)
    return 0;
  tid = P_thread_self();
  if (tid <= 0) {
     /* P_thread_self isn't returning unexpected values at times after a fork
        so return 0 in this case. */
     /* abort(); */
     return 0;
  }

  /* Quick method. Could we get away with a logical AND? */
  if ((curr_index >= 0) && 
      (curr_index < MAX_NUMBER_OF_THREADS)) {
      if (indexToThreads[curr_index] == tid)
          return curr_index;
  }

  /* Slow method */
  curr_index = DYNINSTthreadIndexSLOW(tid);
  if (curr_index == MAX_NUMBER_OF_THREADS) {
    /* Oh, crud. Really slow */
    curr_index = DYNINSTthreadCreate(tid);
  }
  return curr_index;
}