1 //===-- Process.cpp - Implement OS Process Concept --------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This header file implements the operating system Process concept.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/Config/config.h"
15 #include "llvm/Support/ErrorHandling.h"
16 #include "llvm/Support/Process.h"
21 //===----------------------------------------------------------------------===//
22 //=== WARNING: Implementation here must contain only TRULY operating system
23 //=== independent code.
24 //===----------------------------------------------------------------------===//
26 // Empty virtual destructor to anchor the vtable for the process class.
27 process::~process() {}
29 self_process *process::get_self() {
30 // Use a function local static for thread safe initialization and allocate it
31 // as a raw pointer to ensure it is never destroyed.
32 static self_process *SP = new self_process();
37 // The destructor for the self_process subclass must never actually be
38 // executed. There should be at most one instance of this class, and that
39 // instance should live until the process terminates to avoid the potential for
40 // racy accesses during shutdown.
41 self_process::~self_process() {
42 llvm_unreachable("This destructor must never be executed!");
45 /// \brief A helper function to compute the elapsed wall-time since the program
48 /// Note that this routine actually computes the elapsed wall time since the
49 /// first time it was called. However, we arrange to have it called during the
50 /// startup of the process to get approximately correct results.
51 static TimeValue getElapsedWallTime() {
52 static TimeValue &StartTime = *new TimeValue(TimeValue::now());
53 return TimeValue::now() - StartTime;
56 /// \brief A special global variable to ensure we call \c getElapsedWallTime
57 /// during global initialization of the program.
59 /// Note that this variable is never referenced elsewhere. Doing so could
60 /// create race conditions during program startup or shutdown.
61 static volatile TimeValue DummyTimeValue = getElapsedWallTime();
63 // Implement this routine by using the static helpers above. They're already
65 TimeValue self_process::get_wall_time() const {
66 return getElapsedWallTime();
70 #define COLOR(FGBG, CODE, BOLD) "\033[0;" BOLD FGBG CODE "m"
72 #define ALLCOLORS(FGBG,BOLD) {\
73 COLOR(FGBG, "0", BOLD),\
74 COLOR(FGBG, "1", BOLD),\
75 COLOR(FGBG, "2", BOLD),\
76 COLOR(FGBG, "3", BOLD),\
77 COLOR(FGBG, "4", BOLD),\
78 COLOR(FGBG, "5", BOLD),\
79 COLOR(FGBG, "6", BOLD),\
80 COLOR(FGBG, "7", BOLD)\
83 static const char colorcodes[2][2][8][10] = {
84 { ALLCOLORS("3",""), ALLCOLORS("3","1;") },
85 { ALLCOLORS("4",""), ALLCOLORS("4","1;") }
88 // Include the platform-specific parts of this class.
90 #include "Unix/Process.inc"
93 #include "Windows/Process.inc"