summaryrefslogtreecommitdiffstats
path: root/Source/CTest/cmCTestResourceAllocator.h
blob: 9f0b9c95a388c098e052e32aed78433b4c10f3fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
   file Copyright.txt or https://cmake.org/licensing for details.  */
#ifndef cmCTestResourceAllocator_h
#define cmCTestResourceAllocator_h

#include <map>
#include <string>

class cmCTestResourceSpec;

class cmCTestResourceAllocator
{
public:
  struct Resource
  {
    unsigned int Total;
    unsigned int Locked;

    unsigned int Free() const { return this->Total - this->Locked; }

    bool operator==(const Resource& other) const;
    bool operator!=(const Resource& other) const;
  };

  void InitializeFromResourceSpec(const cmCTestResourceSpec& spec);

  const std::map<std::string, std::map<std::string, Resource>>& GetResources()
    const;

  bool AllocateResource(const std::string& name, const std::string& id,
                        unsigned int slots);
  bool DeallocateResource(const std::string& name, const std::string& id,
                          unsigned int slots);

private:
  std::map<std::string, std::map<std::string, Resource>> Resources;
};

#endif