OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/basictypes.h" | |
6 #include "base/logging.h" | |
7 #include "base/process/process_handle.h" | |
8 | |
9 namespace base { | |
10 | |
11 namespace { | |
12 uint32 g_unique_id = kInvalidUniqueId; | |
13 | |
14 #ifndef NDEBUG | |
15 // The process which set g_unique_id. | |
16 uint32 g_procid; | |
17 #endif | |
18 } // namespace | |
19 | |
20 uint32 GetUniqueIdForProcess() { | |
21 if (g_unique_id == kInvalidUniqueId) { | |
22 return static_cast<uint32>(GetCurrentProcId()); | |
danakj
2015/06/17 17:17:16
Should SetUniqueId(GetCurrentProcId()) here so we
rickyz (no longer on Chrome)
2015/06/17 19:53:41
If we call SetUniqueIdForProcess here, then GetUni
| |
23 } | |
24 | |
25 #ifndef NDEBUG | |
willchan no longer on Chromium
2015/06/17 01:51:44
Why bother with NDEBUG if using DCHECK_EQ? Is ther
rickyz (no longer on Chrome)
2015/06/17 03:04:06
I kept the explicit ifndef because I saw that ther
danakj
2015/06/17 17:09:53
It avoids unused variable warnings when compiled o
danakj
2015/06/17 17:17:16
You can guard all your NDEBUG code with #if DCHECK
rickyz (no longer on Chrome)
2015/06/17 19:53:41
Ah, good point.
| |
26 // Make sure we are the same process that set g_procid. This check may have | |
27 // false negatives (if a process ID was reused) but should have no false | |
28 // positives. | |
29 DCHECK_EQ(static_cast<uint32>(GetCurrentProcId()), g_procid); | |
30 #endif | |
31 return g_unique_id; | |
32 } | |
33 | |
34 void SetUniqueIdForProcess(uint32 unique_id) { | |
35 g_unique_id = unique_id; | |
willchan no longer on Chromium
2015/06/17 01:51:45
This shouldn't be set twice, right? I wonder if it
rickyz (no longer on Chrome)
2015/06/17 03:04:05
In practice, this really shouldn't be set twice -
| |
36 #ifndef NDEBUG | |
37 g_procid = static_cast<uint32>(GetCurrentProcId()); | |
danakj
2015/06/17 17:17:16
How useful is this if GetCurrentProcId() is always
rickyz (no longer on Chrome)
2015/06/17 19:53:41
GetCurrentProcId is only 1 in processes which are
| |
38 #endif | |
39 } | |
40 | |
41 } // namespace base | |
OLD | NEW |