WPILibC++  unspecified
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
Resource.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) FIRST 2008-2016. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
7 
8 #pragma once
9 
10 #include "ErrorBase.h"
11 #include <stdint.h>
12 #include <memory>
13 #include <vector>
14 
15 #include "HAL/cpp/priority_mutex.h"
16 
26 class Resource : public ErrorBase {
27  public:
28  virtual ~Resource() = default;
29 
30  Resource(const Resource&) = delete;
31  Resource& operator=(const Resource&) = delete;
32 
33  static void CreateResourceObject(std::unique_ptr<Resource>& r, uint32_t elements);
34  explicit Resource(uint32_t size);
35  uint32_t Allocate(const std::string &resourceDesc);
36  uint32_t Allocate(uint32_t index, const std::string &resourceDesc);
37  void Free(uint32_t index);
38 
39  private:
40  std::vector<bool> m_isAllocated;
41  priority_recursive_mutex m_allocateLock;
42 
43  static priority_recursive_mutex m_createLock;
44 };
static void CreateResourceObject(std::unique_ptr< Resource > &r, uint32_t elements)
Factory method to create a Resource allocation-tracker if needed.
Definition: Resource.cpp:36
Definition: priority_mutex.h:22
Base class for most objects.
Definition: ErrorBase.h:66
The Resource class is a convenient way to track allocated resources.
Definition: Resource.h:26
uint32_t Allocate(const std::string &resourceDesc)
Allocate a resource.
Definition: Resource.cpp:50
void Free(uint32_t index)
Free an allocated resource.
Definition: Resource.cpp:89