SDInternalMacros.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * This file is part of the SDWebImage package.
  3. * (c) Olivier Poitrey <rs@dailymotion.com>
  4. *
  5. * For the full copyright and license information, please view the LICENSE
  6. * file that was distributed with this source code.
  7. */
  8. #import <Foundation/Foundation.h>
  9. #import "SDmetamacros.h"
  10. #ifndef SD_LOCK
  11. #define SD_LOCK(lock) dispatch_semaphore_wait(lock, DISPATCH_TIME_FOREVER);
  12. #endif
  13. #ifndef SD_UNLOCK
  14. #define SD_UNLOCK(lock) dispatch_semaphore_signal(lock);
  15. #endif
  16. #ifndef weakify
  17. #define weakify(...) \
  18. sd_keywordify \
  19. metamacro_foreach_cxt(sd_weakify_,, __weak, __VA_ARGS__)
  20. #endif
  21. #ifndef strongify
  22. #define strongify(...) \
  23. sd_keywordify \
  24. _Pragma("clang diagnostic push") \
  25. _Pragma("clang diagnostic ignored \"-Wshadow\"") \
  26. metamacro_foreach(sd_strongify_,, __VA_ARGS__) \
  27. _Pragma("clang diagnostic pop")
  28. #endif
  29. #define sd_weakify_(INDEX, CONTEXT, VAR) \
  30. CONTEXT __typeof__(VAR) metamacro_concat(VAR, _weak_) = (VAR);
  31. #define sd_strongify_(INDEX, VAR) \
  32. __strong __typeof__(VAR) VAR = metamacro_concat(VAR, _weak_);
  33. #if DEBUG
  34. #define sd_keywordify autoreleasepool {}
  35. #else
  36. #define sd_keywordify try {} @catch (...) {}
  37. #endif
  38. #ifndef onExit
  39. #define onExit \
  40. sd_keywordify \
  41. __strong sd_cleanupBlock_t metamacro_concat(sd_exitBlock_, __LINE__) __attribute__((cleanup(sd_executeCleanupBlock), unused)) = ^
  42. #endif
  43. typedef void (^sd_cleanupBlock_t)(void);
  44. #if defined(__cplusplus)
  45. extern "C" {
  46. #endif
  47. void sd_executeCleanupBlock (__strong sd_cleanupBlock_t *block);
  48. #if defined(__cplusplus)
  49. }
  50. #endif