OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "gpu/command_buffer/common/mailbox.h" | 5 #include "gpu/command_buffer/common/mailbox.h" |
6 | 6 |
| 7 #include <stddef.h> |
| 8 #include <stdint.h> |
7 #include <string.h> | 9 #include <string.h> |
8 | 10 |
9 #include "base/logging.h" | 11 #include "base/logging.h" |
10 #include "base/rand_util.h" | 12 #include "base/rand_util.h" |
11 | 13 |
12 namespace gpu { | 14 namespace gpu { |
13 | 15 |
14 Mailbox::Mailbox() { | 16 Mailbox::Mailbox() { |
15 memset(name, 0, sizeof(name)); | 17 memset(name, 0, sizeof(name)); |
16 } | 18 } |
17 | 19 |
18 bool Mailbox::IsZero() const { | 20 bool Mailbox::IsZero() const { |
19 for (size_t i = 0; i < arraysize(name); ++i) { | 21 for (size_t i = 0; i < arraysize(name); ++i) { |
20 if (name[i]) | 22 if (name[i]) |
21 return false; | 23 return false; |
22 } | 24 } |
23 return true; | 25 return true; |
24 } | 26 } |
25 | 27 |
26 void Mailbox::SetZero() { | 28 void Mailbox::SetZero() { |
27 memset(name, 0, sizeof(name)); | 29 memset(name, 0, sizeof(name)); |
28 } | 30 } |
29 | 31 |
30 void Mailbox::SetName(const int8* n) { | 32 void Mailbox::SetName(const int8_t* n) { |
31 DCHECK(IsZero() || !memcmp(name, n, sizeof(name))); | 33 DCHECK(IsZero() || !memcmp(name, n, sizeof(name))); |
32 memcpy(name, n, sizeof(name)); | 34 memcpy(name, n, sizeof(name)); |
33 } | 35 } |
34 | 36 |
35 Mailbox Mailbox::Generate() { | 37 Mailbox Mailbox::Generate() { |
36 Mailbox result; | 38 Mailbox result; |
37 // Generates cryptographically-secure bytes. | 39 // Generates cryptographically-secure bytes. |
38 base::RandBytes(result.name, sizeof(result.name)); | 40 base::RandBytes(result.name, sizeof(result.name)); |
39 #if !defined(NDEBUG) | 41 #if !defined(NDEBUG) |
40 int8 value = 1; | 42 int8_t value = 1; |
41 for (size_t i = 1; i < sizeof(result.name); ++i) | 43 for (size_t i = 1; i < sizeof(result.name); ++i) |
42 value ^= result.name[i]; | 44 value ^= result.name[i]; |
43 result.name[0] = value; | 45 result.name[0] = value; |
44 #endif | 46 #endif |
45 return result; | 47 return result; |
46 } | 48 } |
47 | 49 |
48 bool Mailbox::Verify() const { | 50 bool Mailbox::Verify() const { |
49 #if !defined(NDEBUG) | 51 #if !defined(NDEBUG) |
50 int8 value = 1; | 52 int8_t value = 1; |
51 for (size_t i = 0; i < sizeof(name); ++i) | 53 for (size_t i = 0; i < sizeof(name); ++i) |
52 value ^= name[i]; | 54 value ^= name[i]; |
53 return value == 0; | 55 return value == 0; |
54 #else | 56 #else |
55 return true; | 57 return true; |
56 #endif | 58 #endif |
57 } | 59 } |
58 | 60 |
59 } // namespace gpu | 61 } // namespace gpu |
OLD | NEW |