Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(224)

Side by Side Diff: base/rand_util_posix.cc

Issue 8491043: Allow linker initialization of lazy instance (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: willchan comments + rebase Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/path_service.cc ('k') | base/sys_info_chromeos.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2008 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 "base/rand_util.h" 5 #include "base/rand_util.h"
6 #include "base/rand_util_c.h" 6 #include "base/rand_util_c.h"
7 7
8 #include <errno.h> 8 #include <errno.h>
9 #include <fcntl.h> 9 #include <fcntl.h>
10 #include <unistd.h> 10 #include <unistd.h>
(...skipping 18 matching lines...) Expand all
29 ~URandomFd() { 29 ~URandomFd() {
30 close(fd_); 30 close(fd_);
31 } 31 }
32 32
33 int fd() const { return fd_; } 33 int fd() const { return fd_; }
34 34
35 private: 35 private:
36 int fd_; 36 int fd_;
37 }; 37 };
38 38
39 base::LazyInstance<URandomFd> g_urandom_fd(base::LINKER_INITIALIZED); 39 base::LazyInstance<URandomFd> g_urandom_fd = LAZY_INSTANCE_INITIALIZER;
40 40
41 } // namespace 41 } // namespace
42 42
43 namespace base { 43 namespace base {
44 44
45 uint64 RandUint64() { 45 uint64 RandUint64() {
46 uint64 number; 46 uint64 number;
47 47
48 int urandom_fd = g_urandom_fd.Pointer()->fd(); 48 int urandom_fd = g_urandom_fd.Pointer()->fd();
49 bool success = file_util::ReadFromFD(urandom_fd, 49 bool success = file_util::ReadFromFD(urandom_fd,
50 reinterpret_cast<char*>(&number), 50 reinterpret_cast<char*>(&number),
51 sizeof(number)); 51 sizeof(number));
52 CHECK(success); 52 CHECK(success);
53 53
54 return number; 54 return number;
55 } 55 }
56 56
57 } // namespace base 57 } // namespace base
58 58
59 int GetUrandomFD(void) { 59 int GetUrandomFD(void) {
60 return g_urandom_fd.Pointer()->fd(); 60 return g_urandom_fd.Pointer()->fd();
61 } 61 }
OLDNEW
« no previous file with comments | « base/path_service.cc ('k') | base/sys_info_chromeos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698