Files
xmrig/src/base/tools/Handle.h

87 lines
1.9 KiB
C
Raw Normal View History

2017-08-31 04:30:59 +03:00
/* XMRig
2020-11-29 18:45:52 +07:00
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
2017-08-31 04:30:59 +03:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2019-02-15 04:59:20 +07:00
#ifndef XMRIG_HANDLE_H
#define XMRIG_HANDLE_H
2017-08-31 04:30:59 +03:00
2019-03-16 00:44:15 +07:00
#include <uv.h>
2017-08-31 04:30:59 +03:00
2019-02-15 04:59:20 +07:00
namespace xmrig {
2017-09-01 03:45:08 +03:00
2019-02-15 04:59:20 +07:00
class Handle
2017-08-31 04:30:59 +03:00
{
public:
2019-03-16 00:44:15 +07:00
template<typename T>
static inline void close(T handle)
{
if (handle) {
deleteLater(handle);
}
}
template<typename T>
static inline void deleteLater(T handle)
{
2019-03-17 16:03:45 +07:00
if (uv_is_closing(reinterpret_cast<uv_handle_t *>(handle))) {
return;
}
uv_close(reinterpret_cast<uv_handle_t *>(handle), [](uv_handle_t *handle) { delete reinterpret_cast<T>(handle); });
2019-03-16 00:44:15 +07:00
}
2017-08-31 04:30:59 +03:00
};
2018-03-27 14:01:38 +07:00
2019-03-16 00:44:15 +07:00
template<>
inline void Handle::close(uv_timer_t *handle)
{
if (handle) {
uv_timer_stop(handle);
deleteLater(handle);
}
}
template<>
inline void Handle::close(uv_signal_t *handle)
{
if (handle) {
uv_signal_stop(handle);
deleteLater(handle);
}
}
template<>
inline void Handle::close(uv_fs_event_t *handle)
{
if (handle) {
uv_fs_event_stop(handle);
deleteLater(handle);
}
}
2018-03-27 14:01:38 +07:00
} /* namespace xmrig */
2019-02-15 04:59:20 +07:00
#endif /* XMRIG_HANDLE_H */