Пример #1
0
void sg_cleanup(Segment* const sg)
{
  tl_assert(sg);
  vc_cleanup(&sg->vc);
  bm_delete(sg->bm);
  sg->bm = 0;
}
Пример #2
0
/** Verify whether the danger set for thread tid is up to date. Only perform
 *  the check if the environment variable DRD_VERIFY_DANGER_SET has been set.
 */
static Bool thread_danger_set_up_to_date(const DrdThreadId tid)
{
  static int do_verify_danger_set = -1;
  Bool result;
  struct bitmap* computed_danger_set = 0;

  if (do_verify_danger_set < 0)
  {
    //VG_(message)(Vg_DebugMsg, "%s", VG_(getenv)("DRD_VERIFY_DANGER_SET"));
    do_verify_danger_set = VG_(getenv)("DRD_VERIFY_DANGER_SET") != 0;
  }
  if (do_verify_danger_set == 0)
    return True;

  thread_compute_danger_set(&computed_danger_set, tid);
  result = bm_equal(s_danger_set, computed_danger_set);
  bm_delete(computed_danger_set);
  return result;
}
Пример #3
0
/** Compute a bitmap that represents the union of all memory accesses of all
 *  segments that are unordered to the current segment of the thread tid.
 */
static void thread_compute_danger_set(struct bitmap** danger_set,
                                      const DrdThreadId tid)
{
  Segment* p;

  tl_assert(0 <= (int)tid && tid < DRD_N_THREADS
            && tid != DRD_INVALID_THREADID);
  tl_assert(tid == s_drd_running_tid);

  s_update_danger_set_count++;
  s_danger_set_bitmap_creation_count  -= bm_get_bitmap_creation_count();
  s_danger_set_bitmap2_creation_count -= bm_get_bitmap2_creation_count();

  if (*danger_set)
  {
    bm_delete(*danger_set);
  }
  *danger_set = bm_new();

  if (s_trace_danger_set)
  {
    char msg[256];

    VG_(snprintf)(msg, sizeof(msg),
                  "computing danger set for thread %d/%d with vc ",
                  DrdThreadIdToVgThreadId(tid), tid);
    vc_snprint(msg + VG_(strlen)(msg),
               sizeof(msg) - VG_(strlen)(msg),
               &s_threadinfo[tid].last->vc);
    VG_(message)(Vg_UserMsg, "%s", msg);
  }

  p = s_threadinfo[tid].last;
  {
    unsigned j;

    if (s_trace_danger_set)
    {
      char msg[256];

      VG_(snprintf)(msg, sizeof(msg),
                    "danger set: thread [%d] at vc ",
                    tid);
      vc_snprint(msg + VG_(strlen)(msg),
                 sizeof(msg) - VG_(strlen)(msg),
                 &p->vc);
      VG_(message)(Vg_UserMsg, "%s", msg);
    }

    for (j = 0; j < sizeof(s_threadinfo) / sizeof(s_threadinfo[0]); j++)
    {
      if (j != tid && IsValidDrdThreadId(j))
      {
        const Segment* q;
        for (q = s_threadinfo[j].last; q; q = q->prev)
        {
          if (! vc_lte(&q->vc, &p->vc) && ! vc_lte(&p->vc, &q->vc))
          {
            if (s_trace_danger_set)
            {
              char msg[256];
              VG_(snprintf)(msg, sizeof(msg),
                            "danger set: [%d] merging segment ", j);
              vc_snprint(msg + VG_(strlen)(msg),
                         sizeof(msg) - VG_(strlen)(msg),
                         &q->vc);
              VG_(message)(Vg_UserMsg, "%s", msg);
            }
            bm_merge2(*danger_set, q->bm);
          }
          else
          {
            if (s_trace_danger_set)
            {
              char msg[256];
              VG_(snprintf)(msg, sizeof(msg),
                            "danger set: [%d] ignoring segment ", j);
              vc_snprint(msg + VG_(strlen)(msg),
                         sizeof(msg) - VG_(strlen)(msg),
                         &q->vc);
              VG_(message)(Vg_UserMsg, "%s", msg);
            }
          }
        }
      }
    }
  }

  s_danger_set_bitmap_creation_count  += bm_get_bitmap_creation_count();
  s_danger_set_bitmap2_creation_count += bm_get_bitmap2_creation_count();

  if (0 && s_trace_danger_set)
  {
    VG_(message)(Vg_UserMsg, "[%d] new danger set:", tid);
    bm_print(*danger_set);
    VG_(message)(Vg_UserMsg, "[%d] end of new danger set.", tid);
  }
}