ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / native_client_sdk / src / libraries / nacl_io / inode_pool.h
blob7bee2e40eb8db9948f0a29a458a1de1b7c944159
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 #ifndef LIBRARIES_NACL_IO_INODE_POOL_H_
6 #define LIBRARIES_NACL_IO_INODE_POOL_H_
8 #include <stdlib.h>
9 #include <vector>
11 #include "nacl_io/osstat.h"
12 #include "pthread.h"
13 #include "sdk_util/auto_lock.h"
15 namespace nacl_io {
17 class INodePool {
18 public:
19 INodePool() : num_nodes_(0), max_nodes_(0) {}
21 ino_t Acquire() {
22 AUTO_LOCK(lock_);
23 const int INO_CNT = 8;
25 // If we run out of INO numbers, then allocate 8 more
26 if (inos_.size() == 0) {
27 max_nodes_ += INO_CNT;
28 // Add eight more to the stack in reverse order, offset by 1
29 // since '0' refers to no INO.
30 for (int a = 0; a < INO_CNT; a++) {
31 inos_.push_back(max_nodes_ - a);
35 // Return the INO at the top of the stack.
36 int val = inos_.back();
37 inos_.pop_back();
38 num_nodes_++;
39 return val;
42 void Release(ino_t ino) {
43 AUTO_LOCK(lock_);
44 inos_.push_back(ino);
45 num_nodes_--;
48 size_t size() const { return num_nodes_; }
49 size_t capacity() const { return max_nodes_; }
51 private:
52 size_t num_nodes_;
53 size_t max_nodes_;
54 std::vector<ino_t> inos_;
55 sdk_util::SimpleLock lock_;
58 } // namespace nacl_io
60 #endif // LIBRARIES_NACL_IO_INODE_POOL_H_