L4Re Operating System Framework
Interface and Usage Documentation
•All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
fd_store.h
1/*
2 * (c) 2010 Alexander Warg <warg@os.inf.tu-dresden.de>
3 * economic rights: Technische Universität Dresden (Germany)
4 *
5 * License: see LICENSE.spdx (in this directory or the directories above)
6 */
7#pragma once
8
9#include <l4/l4re_vfs/vfs.h>
10
11namespace L4Re { namespace Core {
12
13using cxx::Ref_ptr;
14
15class Fd_store
16{
17public:
18 enum { MAX_FILES = 50 };
19
20 Fd_store() noexcept : _fd_hint(0) {}
21
22 int alloc() noexcept;
23 void free(int fd) noexcept;
24 bool check_fd(int fd) noexcept;
25 Ref_ptr<L4Re::Vfs::File> get(int fd) noexcept;
26 void set(int fd, Ref_ptr<L4Re::Vfs::File> const &f) noexcept;
27
28private:
29 int _fd_hint;
30 Ref_ptr<L4Re::Vfs::File> _files[MAX_FILES];
31};
32
33inline
34bool
35Fd_store::check_fd(int fd) noexcept
36{
37 return fd >= 0 && fd < MAX_FILES;
38}
39
40inline
41Ref_ptr<L4Re::Vfs::File>
42Fd_store::get(int fd) noexcept
43{
44 if (check_fd(fd))
45 return _files[fd];
46
47 return Ref_ptr<>::Nil;
48}
49
50inline
51void
52Fd_store::set(int fd, Ref_ptr<L4Re::Vfs::File> const &f) noexcept
53{
54 _files[fd] = f;
55}
56
57}}
A reference-counting pointer with automatic cleanup.
Definition ref_ptr:71
L4Re C++ Interfaces.
Definition cmd_control:14