LCOV - code coverage report
Current view: top level - src/mem - hibernation_manager.cpp (source / functions) Coverage Total Hit
Test: HPActor Coverage Lines: 77.5 % 40 31
Test Date: 2026-05-20 02:24:49 Functions: 85.7 % 7 6
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : // Copyright 2026 HPActor Contributors
       2                 :             : //
       3                 :             : // Licensed under the Apache License, Version 2.0 (the "License");
       4                 :             : // you may not use this file except in compliance with the License.
       5                 :             : // You may obtain a copy of the License at
       6                 :             : //
       7                 :             : //     http://www.apache.org/licenses/LICENSE-2.0
       8                 :             : //
       9                 :             : // Unless required by applicable law or agreed to in writing, software
      10                 :             : // distributed under the License is distributed on an "AS IS" BASIS,
      11                 :             : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      12                 :             : // See the License for the specific language governing permissions and
      13                 :             : // limitations under the License.
      14                 :             : 
      15                 :             : #include <hpactor/mem/hibernation_registry.hpp>
      16                 :             : #include <hpactor/platform.hpp>
      17                 :             : 
      18                 :             : #include <cstdlib>
      19                 :             : #include <cstring>
      20                 :             : #include <sys/mman.h>
      21                 :             : 
      22                 :             : namespace hpactor::mem {
      23                 :             : 
      24                 :           1 : HibernationRegistry& HibernationRegistry::instance() {
      25                 :           1 :     static HibernationRegistry hr;
      26                 :           1 :     return hr;
      27                 :             : }
      28                 :             : 
      29                 :           1 : void HibernationRegistry::store(ActorId id, HibernationBuffer buf) {
      30                 :           1 :     std::lock_guard<std::mutex> lock(mutex_);
      31                 :           1 :     buf.actor_id = static_cast<uint32_t>(id.value());
      32                 :           1 :     entries_[id.value()] = buf;
      33                 :           1 : }
      34                 :             : 
      35                 :           1 : HibernationBuffer HibernationRegistry::load(ActorId id) {
      36                 :           1 :     std::lock_guard<std::mutex> lock(mutex_);
      37                 :           1 :     auto it = entries_.find(id.value());
      38                 :           1 :     if (it == entries_.end()) {
      39                 :           0 :         return HibernationBuffer{};
      40                 :             :     }
      41                 :           1 :     HibernationBuffer buf = it->second;
      42                 :           1 :     entries_.erase(it);
      43                 :           1 :     return buf;
      44                 :           1 : }
      45                 :             : 
      46                 :           0 : void HibernationRegistry::remove(ActorId id) {
      47                 :           0 :     std::lock_guard<std::mutex> lock(mutex_);
      48                 :           0 :     auto it = entries_.find(id.value());
      49                 :           0 :     if (it != entries_.end()) {
      50                 :           0 :         if (it->second.ptr) {
      51                 :           0 :             munmap(it->second.ptr, it->second.size);
      52                 :             :         }
      53                 :           0 :         entries_.erase(it);
      54                 :             :     }
      55                 :           0 : }
      56                 :             : 
      57                 :           2 : bool HibernationRegistry::contains(ActorId id) const {
      58                 :           2 :     std::lock_guard<std::mutex> lock(mutex_);
      59                 :           2 :     return entries_.find(id.value()) != entries_.end();
      60                 :           2 : }
      61                 :             : 
      62                 :           2 : size_t HibernationRegistry::count() const {
      63                 :           2 :     std::lock_guard<std::mutex> lock(mutex_);
      64                 :           2 :     return entries_.size();
      65                 :           2 : }
      66                 :             : 
      67                 :           1 : size_t HibernationRegistry::total_bytes() const {
      68                 :           1 :     std::lock_guard<std::mutex> lock(mutex_);
      69                 :           1 :     size_t total = 0;
      70                 :           2 :     for (const auto& [id, buf] : entries_) {
      71                 :           1 :         total += buf.size;
      72                 :             :     }
      73                 :           2 :     return total;
      74                 :           1 : }
      75                 :             : 
      76                 :             : } // namespace hpactor::mem
        

Generated by: LCOV version 2.0-1