This commit is contained in:
Robert Swiecki 2016-03-08 18:23:26 +01:00
parent e561dc6bb1
commit 833cf5d2c8
2 changed files with 10 additions and 7 deletions

View File

@ -34,14 +34,17 @@
#define _STRMERGE(a, b) a##b #define _STRMERGE(a, b) a##b
#ifdef __clang__ #ifdef __clang__
static void __attribute__((unused)) _clang_cleanup_func(void (^*dfunc)(void)) { (*dfunc)(); } static void __attribute__ ((unused)) _clang_cleanup_func(void (^*dfunc) (void))
{
(*dfunc) ();
}
#define defer(a) void (^_STRMERGE(__df_, __COUNTER__))(void) __attribute__((cleanup(_clang_cleanup_func))) __attribute__((unused)) = ^{ a; } #define defer(a) void (^_STRMERGE(__df_, __COUNTER__))(void) __attribute__((cleanup(_clang_cleanup_func))) __attribute__((unused)) = ^{ a; }
#else #else
#define __block #define __block
#define defer(a) void _STRMERGE(_cleanup_func_, __LINE__)(void *_STRMERGE(_cleanup_unused_, __LINE__) __attribute__((unused))) { a; } ; int _STRMERGE(_cleanup_var_, __LINE__) __attribute__((cleanup(_STRMERGE(_cleanup_func_, __LINE__)))) __attribute__((unused)) #define defer(a) void _STRMERGE(_cleanup_func_, __LINE__)(void *_STRMERGE(_cleanup_unused_, __LINE__) __attribute__((unused))) { a; } ; int _STRMERGE(_cleanup_var_, __LINE__) __attribute__((cleanup(_STRMERGE(_cleanup_func_, __LINE__)))) __attribute__((unused))
#endif #endif
struct pids_t { struct pids_t {
pid_t pid; pid_t pid;
time_t start; time_t start;