tsan_rtl_proc.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. //===-- tsan_rtl_proc.cpp -----------------------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file is a part of ThreadSanitizer (TSan), a race detector.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #include "sanitizer_common/sanitizer_placement_new.h"
  13. #include "tsan_rtl.h"
  14. #include "tsan_mman.h"
  15. #include "tsan_flags.h"
  16. namespace __tsan {
  17. Processor *ProcCreate() {
  18. void *mem = InternalAlloc(sizeof(Processor));
  19. internal_memset(mem, 0, sizeof(Processor));
  20. Processor *proc = new(mem) Processor;
  21. proc->thr = nullptr;
  22. #if !SANITIZER_GO
  23. AllocatorProcStart(proc);
  24. #endif
  25. if (common_flags()->detect_deadlocks)
  26. proc->dd_pt = ctx->dd->CreatePhysicalThread();
  27. return proc;
  28. }
  29. void ProcDestroy(Processor *proc) {
  30. CHECK_EQ(proc->thr, nullptr);
  31. #if !SANITIZER_GO
  32. AllocatorProcFinish(proc);
  33. #endif
  34. ctx->clock_alloc.FlushCache(&proc->clock_cache);
  35. ctx->metamap.OnProcIdle(proc);
  36. if (common_flags()->detect_deadlocks)
  37. ctx->dd->DestroyPhysicalThread(proc->dd_pt);
  38. proc->~Processor();
  39. InternalFree(proc);
  40. }
  41. void ProcWire(Processor *proc, ThreadState *thr) {
  42. CHECK_EQ(thr->proc1, nullptr);
  43. CHECK_EQ(proc->thr, nullptr);
  44. thr->proc1 = proc;
  45. proc->thr = thr;
  46. }
  47. void ProcUnwire(Processor *proc, ThreadState *thr) {
  48. CHECK_EQ(thr->proc1, proc);
  49. CHECK_EQ(proc->thr, thr);
  50. thr->proc1 = nullptr;
  51. proc->thr = nullptr;
  52. }
  53. } // namespace __tsan