L4Re Operating System Framework
Interface and Usage Documentation
Loading...
Searching...
No Matches
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 * This file is part of TUD:OS and distributed under the terms of the
6 * GNU General Public License 2.
7 * Please see the COPYING-GPL-2 file for details.
8 *
9 * As a special exception, you may use this file as part of a free software
10 * library without restriction. Specifically, if other files instantiate
11 * templates or use macros or inline functions from this file, or you compile
12 * this file and link it with other files to produce an executable, this
13 * file does not by itself cause the resulting executable to be covered by
14 * the GNU General Public License. This exception does not however
15 * invalidate any other reasons why the executable file might be covered by
16 * the GNU General Public License.
17 */
18#pragma once
19
20#include <l4/l4re_vfs/vfs.h>
21
22namespace L4Re { namespace Core {
23
24using cxx::Ref_ptr;
25
26class Fd_store
27{
28public:
29 enum { MAX_FILES = 50 };
30
31 Fd_store() noexcept : _fd_hint(0) {}
32
33 int alloc() noexcept;
34 void free(int fd) noexcept;
35 bool check_fd(int fd) noexcept;
36 Ref_ptr<L4Re::Vfs::File> get(int fd) noexcept;
37 void set(int fd, Ref_ptr<L4Re::Vfs::File> const &f) noexcept;
38
39private:
40 int _fd_hint;
41 Ref_ptr<L4Re::Vfs::File> _files[MAX_FILES];
42};
43
44inline
45bool
46Fd_store::check_fd(int fd) noexcept
47{
48 return fd >= 0 && fd < MAX_FILES;
49}
50
51inline
52Ref_ptr<L4Re::Vfs::File>
53Fd_store::get(int fd) noexcept
54{
55 if (check_fd(fd))
56 return _files[fd];
57
58 return Ref_ptr<>::Nil;
59}
60
61inline
62void
63Fd_store::set(int fd, Ref_ptr<L4Re::Vfs::File> const &f) noexcept
64{
65 _files[fd] = f;
66}
67
68}}
A reference-counting pointer with automatic cleanup.
Definition ref_ptr:82
L4Re C++ Interfaces.
Definition l4re.dox:17