LCOV - code coverage report
Current view: top level - zeroeq/detail - context.cpp (source / functions) Hit Total Coverage
Test: ZeroEQ Lines: 10 10 100.0 %
Date: 2017-12-01 01:44:57 Functions: 4 4 100.0 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2017, Human Brain Project
       3             :  *                     Stefan.Eilemann@epfl.ch
       4             :  */
       5             : 
       6             : #include "context.h"
       7             : 
       8             : #include <zmq.h>
       9             : 
      10             : #include <mutex>
      11             : 
      12             : namespace zeroeq
      13             : {
      14             : namespace detail
      15             : {
      16         177 : zmq::ContextPtr getContext()
      17             : {
      18         177 :     static std::weak_ptr<void> context;
      19             :     static std::mutex mutex;
      20         354 :     std::lock_guard<std::mutex> lock(mutex);
      21             : 
      22         177 :     zmq::ContextPtr sharedContext = context.lock();
      23         177 :     if (!sharedContext)
      24             :     {
      25         170 :         sharedContext.reset(zmq_ctx_new(),
      26         170 :                             [](void* c) { ::zmq_ctx_destroy(c); });
      27          85 :         context = sharedContext;
      28             :     }
      29         354 :     return sharedContext;
      30             : }
      31             : }
      32          24 : }

Generated by: LCOV version 1.11