Home | History | Annotate | Download | only in rtl
      1 //===-- tsan_rtl_proc.cc ------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 //
     10 // This file is a part of ThreadSanitizer (TSan), a race detector.
     11 //
     12 //===----------------------------------------------------------------------===//
     13 
     14 #include "sanitizer_common/sanitizer_placement_new.h"
     15 #include "tsan_rtl.h"
     16 #include "tsan_mman.h"
     17 #include "tsan_flags.h"
     18 
     19 namespace __tsan {
     20 
     21 Processor *ProcCreate() {
     22   void *mem = InternalAlloc(sizeof(Processor));
     23   internal_memset(mem, 0, sizeof(Processor));
     24   Processor *proc = new(mem) Processor;
     25   proc->thr = nullptr;
     26 #ifndef SANITIZER_GO
     27   AllocatorProcStart(proc);
     28 #endif
     29   if (common_flags()->detect_deadlocks)
     30     proc->dd_pt = ctx->dd->CreatePhysicalThread();
     31   return proc;
     32 }
     33 
     34 void ProcDestroy(Processor *proc) {
     35   CHECK_EQ(proc->thr, nullptr);
     36 #ifndef SANITIZER_GO
     37   AllocatorProcFinish(proc);
     38 #endif
     39   ctx->clock_alloc.FlushCache(&proc->clock_cache);
     40   ctx->metamap.OnProcIdle(proc);
     41   if (common_flags()->detect_deadlocks)
     42      ctx->dd->DestroyPhysicalThread(proc->dd_pt);
     43   proc->~Processor();
     44   InternalFree(proc);
     45 }
     46 
     47 void ProcWire(Processor *proc, ThreadState *thr) {
     48   CHECK_EQ(thr->proc1, nullptr);
     49   CHECK_EQ(proc->thr, nullptr);
     50   thr->proc1 = proc;
     51   proc->thr = thr;
     52 }
     53 
     54 void ProcUnwire(Processor *proc, ThreadState *thr) {
     55   CHECK_EQ(thr->proc1, proc);
     56   CHECK_EQ(proc->thr, thr);
     57   thr->proc1 = nullptr;
     58   proc->thr = nullptr;
     59 }
     60 
     61 }  // namespace __tsan
     62