MeVisLab Toolbox Reference
ResourceDestructionGuard.h
Go to the documentation of this file.
1// Copyright (c) Fraunhofer MEVIS, Germany. All rights reserved.
2// **InsertLicense** code
3
4#pragma once
5
6#include <asio/System.h>
7
8#include <FMEThirdPartyWarningsDisable.h>
9#include <mutex>
10#include <memory>
11#include <FMEThirdPartyWarningsRestore.h>
12
13
14namespace asio {
15
68 {
69 using ShareType = unsigned char;
70
71 class ASYNCHRONOUSIO_EXPORT LockedHandle final
72 {
73 public:
74
75 LockedHandle(std::mutex& mutex, std::weak_ptr<ShareType> share);
76
77 operator bool() const;
78
79 private:
80
81 std::unique_lock<std::mutex> lock;
82 std::shared_ptr<ShareType> share;
83 };
84
85
86 class ASYNCHRONOUSIO_EXPORT WeakHandle final
87 {
88 public:
89
90 WeakHandle(std::shared_ptr<std::mutex> mutex, std::weak_ptr<ShareType> share);
91
92 LockedHandle lock() const;
93
94 private:
95
96 std::shared_ptr<std::mutex> mutex;
97 std::weak_ptr<ShareType> share;
98 };
99
100
101 public:
102
104
106
107 WeakHandle handle() const;
108
109 private:
110
111 std::shared_ptr<std::mutex> mutex;
112 std::shared_ptr<ShareType> share;
113 };
114
115}
#define ASYNCHRONOUSIO_EXPORT
Definition System.h:10
A guard that protects resources of a given class from being detroyed if another thread still works wi...
Target mlrange_cast(Source arg)
Generic version of checked ML casts.