Direct-BT v3.3.0-1-gc2d430c
Direct-BT - Direct Bluetooth Programming.
Public Member Functions | List of all members
jau::call_on_release< UnaryFunction > Class Template Reference

Call on release allows the user to pass a function to be called at destruction of this instance. More...

#include <basic_algos.hpp>

Collaboration diagram for jau::call_on_release< UnaryFunction >:

Public Member Functions

 call_on_release (const call_on_release &)=delete
 
 call_on_release (UnaryFunction release_func) noexcept
 
 ~call_on_release () noexcept
 
bool is_released () const noexcept
 Query whethr the resource has been orderly released. More...
 
call_on_releaseoperator= (const call_on_release &) volatile=delete
 
call_on_releaseoperator= (const call_on_release &)=delete
 
void set_released () noexcept
 Mark the resource being orderly released, release_func() will not be called and use after free avoided. More...
 

Detailed Description

template<class UnaryFunction>
class jau::call_on_release< UnaryFunction >

Call on release allows the user to pass a function to be called at destruction of this instance.

One goal was to provide a thread exit cleanup facility, setting a 'is_running' flag to false when the thread exists normally or abnormally.

  jau::relaxed_atomic_bool is_running = true;

  void some_thread_func() {
      thread_local jau::call_on_release thread_cleanup([&]() {
          is_running = false;
      });
      ...
      do some work here, which might get cancelled
      ..
      thread_cleanup.set_released(); // mark orderly release
  }
Template Parameters
UnaryFunctionuser provided function to be called @ dtor
See also
jau::service_runner

Definition at line 65 of file basic_algos.hpp.

Constructor & Destructor Documentation

◆ call_on_release() [1/2]

template<class UnaryFunction >
jau::call_on_release< UnaryFunction >::call_on_release ( UnaryFunction  release_func)
inlinenoexcept

Definition at line 71 of file basic_algos.hpp.

◆ ~call_on_release()

template<class UnaryFunction >
jau::call_on_release< UnaryFunction >::~call_on_release ( )
inlinenoexcept

Definition at line 73 of file basic_algos.hpp.

◆ call_on_release() [2/2]

template<class UnaryFunction >
jau::call_on_release< UnaryFunction >::call_on_release ( const call_on_release< UnaryFunction > &  )
delete

Member Function Documentation

◆ operator=() [1/2]

template<class UnaryFunction >
call_on_release & jau::call_on_release< UnaryFunction >::operator= ( const call_on_release< UnaryFunction > &  )
delete

◆ operator=() [2/2]

template<class UnaryFunction >
call_on_release & jau::call_on_release< UnaryFunction >::operator= ( const call_on_release< UnaryFunction > &  ) volatile
delete

◆ set_released()

template<class UnaryFunction >
void jau::call_on_release< UnaryFunction >::set_released ( )
inlinenoexcept

Mark the resource being orderly released, release_func() will not be called and use after free avoided.

Definition at line 81 of file basic_algos.hpp.

◆ is_released()

template<class UnaryFunction >
bool jau::call_on_release< UnaryFunction >::is_released ( ) const
inlinenoexcept

Query whethr the resource has been orderly released.

Definition at line 83 of file basic_algos.hpp.


The documentation for this class was generated from the following file: