1 // Copyright (c) 2012 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.
5 #include "base/posix/global_descriptors.h"
10 #include "base/logging.h"
14 GlobalDescriptors::Descriptor::Descriptor(Key key
, int fd
)
15 : key(key
), fd(fd
), region(base::MemoryMappedFile::Region::kWholeFile
) {
18 GlobalDescriptors::Descriptor::Descriptor(Key key
,
20 base::MemoryMappedFile::Region region
)
21 : key(key
), fd(fd
), region(region
) {
25 GlobalDescriptors
* GlobalDescriptors::GetInstance() {
26 typedef Singleton
<base::GlobalDescriptors
,
27 LeakySingletonTraits
<base::GlobalDescriptors
> >
28 GlobalDescriptorsSingleton
;
29 return GlobalDescriptorsSingleton::get();
32 int GlobalDescriptors::Get(Key key
) const {
33 const int ret
= MaybeGet(key
);
36 DLOG(FATAL
) << "Unknown global descriptor: " << key
;
40 int GlobalDescriptors::MaybeGet(Key key
) const {
41 for (Mapping::const_iterator
42 i
= descriptors_
.begin(); i
!= descriptors_
.end(); ++i
) {
50 void GlobalDescriptors::Set(Key key
, int fd
) {
51 Set(key
, fd
, base::MemoryMappedFile::Region::kWholeFile
);
54 void GlobalDescriptors::Set(Key key
,
56 base::MemoryMappedFile::Region region
) {
57 for (auto& i
: descriptors_
) {
65 descriptors_
.push_back(Descriptor(key
, fd
, region
));
68 base::MemoryMappedFile::Region
GlobalDescriptors::GetRegion(Key key
) const {
69 for (const auto& i
: descriptors_
) {
73 DLOG(FATAL
) << "Unknown global descriptor: " << key
;
74 return base::MemoryMappedFile::Region::kWholeFile
;
77 void GlobalDescriptors::Reset(const Mapping
& mapping
) {
78 descriptors_
= mapping
;
81 GlobalDescriptors::GlobalDescriptors() {}
83 GlobalDescriptors::~GlobalDescriptors() {}