WPILibC++  unspecified
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
Resource.hpp
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) FIRST 2008. 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 $(WIND_BASE)/WPILib. */
5 /*----------------------------------------------------------------------------*/
6 #pragma once
7 
8 #include "../Errors.hpp"
9 #include "HAL/cpp/priority_mutex.h"
10 #include <stdint.h>
11 
12 #include <vector>
13 
14 // TODO: Replace this with something appropriate to avoid conflicts with
15 // wpilibC++ Resource class (which performs an essentially identical function).
16 namespace hal {
17 
27 class Resource
28 {
29 public:
30  Resource(const Resource&) = delete;
31  Resource& operator=(const Resource&) = delete;
32  explicit Resource(uint32_t size);
33  virtual ~Resource() = default;
34  static void CreateResourceObject(Resource **r, uint32_t elements);
35  uint32_t Allocate(const char *resourceDesc);
36  uint32_t Allocate(uint32_t index, const char *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 };
45 
46 } // namespace hal
The Resource class is a convenient way to track allocated resources.
Definition: Resource.hpp:27
Definition: priority_mutex.h:22