LCOV - code coverage report
Current view: top level - ipc/client/source - BlockingClosure.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 47.2 % 36 17
Test Date: 2025-03-21 11:02:39 Functions: 60.0 % 10 6

            Line data    Source code
       1              : /*
       2              :  * If not stated otherwise in this file or this component's LICENSE file the
       3              :  * following copyright and licenses apply:
       4              :  *
       5              :  * Copyright 2022 Sky UK
       6              :  *
       7              :  * Licensed under the Apache License, Version 2.0 (the "License");
       8              :  * you may not use this file except in compliance with the License.
       9              :  * You may obtain a copy of the License at
      10              :  *
      11              :  * http://www.apache.org/licenses/LICENSE-2.0
      12              :  *
      13              :  * Unless required by applicable law or agreed to in writing, software
      14              :  * distributed under the License is distributed on an "AS IS" BASIS,
      15              :  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      16              :  * See the License for the specific language governing permissions and
      17              :  * limitations under the License.
      18              :  */
      19              : 
      20              : #include "BlockingClosure.h"
      21              : #include "IpcLogging.h"
      22              : 
      23              : #include <memory>
      24              : #include <unistd.h>
      25              : #include <utility>
      26              : 
      27              : namespace firebolt::rialto::ipc
      28              : {
      29           13 : std::shared_ptr<IBlockingClosureFactory> IBlockingClosureFactory::createFactory()
      30              : {
      31           13 :     std::shared_ptr<IBlockingClosureFactory> factory;
      32              :     try
      33              :     {
      34           13 :         factory = std::make_shared<BlockingClosureFactory>();
      35              :     }
      36            0 :     catch (const std::exception &e)
      37              :     {
      38            0 :         RIALTO_IPC_LOG_ERROR("Failed to create the blocking closure factory, reason: %s", e.what());
      39              :     }
      40              : 
      41           13 :     return factory;
      42              : }
      43              : 
      44              : std::shared_ptr<IBlockingClosure>
      45            0 : BlockingClosureFactory::createBlockingClosurePoll(std::shared_ptr<::firebolt::rialto::ipc::IChannel> ipcChannel)
      46              : {
      47            0 :     std::shared_ptr<IBlockingClosure> blockingClosure;
      48              :     try
      49              :     {
      50            0 :         blockingClosure = std::make_shared<BlockingClosurePoll>(ipcChannel);
      51              :     }
      52            0 :     catch (const std::exception &e)
      53              :     {
      54            0 :         RIALTO_IPC_LOG_ERROR("Failed to create the blocking closure, reason: %s", e.what());
      55              :     }
      56              : 
      57            0 :     return blockingClosure;
      58              : }
      59              : 
      60           10 : std::shared_ptr<IBlockingClosure> BlockingClosureFactory::createBlockingClosureSemaphore()
      61              : {
      62           10 :     std::shared_ptr<IBlockingClosure> blockingClosure;
      63              :     try
      64              :     {
      65           10 :         blockingClosure = std::make_shared<BlockingClosureSemaphore>();
      66              :     }
      67            0 :     catch (const std::exception &e)
      68              :     {
      69            0 :         RIALTO_IPC_LOG_ERROR("Failed to create the blocking closure, reason: %s", e.what());
      70              :     }
      71              : 
      72           10 :     return blockingClosure;
      73              : }
      74              : 
      75            0 : BlockingClosurePoll::BlockingClosurePoll(std::shared_ptr<::firebolt::rialto::ipc::IChannel> ipcChannel)
      76            0 :     : m_kChannel(std::move(ipcChannel)), m_done(false)
      77              : {
      78            0 : }
      79              : 
      80            0 : void BlockingClosurePoll::Run() // NOLINT(build/function_format)
      81              : {
      82            0 :     m_done = true;
      83              : }
      84              : 
      85            0 : void BlockingClosurePoll::wait()
      86              : {
      87            0 :     while (m_kChannel->process() && !m_done)
      88              :     {
      89            0 :         m_kChannel->wait(-1);
      90              :     }
      91              : }
      92              : 
      93           10 : BlockingClosureSemaphore::BlockingClosureSemaphore() : m_sem{{0}}
      94              : {
      95           10 :     sem_init(&m_sem, 0, 0);
      96              : }
      97              : 
      98           10 : BlockingClosureSemaphore::~BlockingClosureSemaphore()
      99              : {
     100           10 :     sem_destroy(&m_sem);
     101              : }
     102              : 
     103           10 : void BlockingClosureSemaphore::Run() // NOLINT(build/function_format)
     104              : {
     105           10 :     if (sem_post(&m_sem) != 0)
     106            0 :         RIALTO_IPC_LOG_SYS_ERROR(errno, "failed to signal semaphore");
     107           10 : }
     108              : 
     109           10 : void BlockingClosureSemaphore::wait()
     110              : {
     111           10 :     TEMP_FAILURE_RETRY(sem_wait(&m_sem));
     112              : }
     113              : }; // namespace firebolt::rialto::ipc
        

Generated by: LCOV version 2.0-1