BU_SDInternalMacros.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 "BU_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 SD_OPTIONS_CONTAINS
  17. #define SD_OPTIONS_CONTAINS(options, value) (((options) & (value)) == (value))
  18. #endif
  19. #ifndef weakify
  20. #define weakify(...) \
  21. sd_keywordify \
  22. metamacro_foreach_cxt(sd_weakify_,, __weak, __VA_ARGS__)
  23. #endif
  24. #ifndef strongify
  25. #define strongify(...) \
  26. sd_keywordify \
  27. _Pragma("clang diagnostic push") \
  28. _Pragma("clang diagnostic ignored \"-Wshadow\"") \
  29. metamacro_foreach(sd_strongify_,, __VA_ARGS__) \
  30. _Pragma("clang diagnostic pop")
  31. #endif
  32. #define sd_weakify_(INDEX, CONTEXT, VAR) \
  33. CONTEXT __typeof__(VAR) metamacro_concat(VAR, _weak_) = (VAR);
  34. #define sd_strongify_(INDEX, VAR) \
  35. __strong __typeof__(VAR) VAR = metamacro_concat(VAR, _weak_);
  36. #if DEBUG
  37. #define sd_keywordify autoreleasepool {}
  38. #else
  39. #define sd_keywordify try {} @catch (...) {}
  40. #endif
  41. #ifndef onExit
  42. #define onExit \
  43. sd_keywordify \
  44. __strong bu_sd_cleanupBlock_t metamacro_concat(sd_exitBlock_, __LINE__) __attribute__((cleanup(bu_sd_executeCleanupBlock), unused)) = ^
  45. #endif
  46. typedef void (^bu_sd_cleanupBlock_t)(void);
  47. #if defined(__cplusplus)
  48. extern "C" {
  49. #endif
  50. void bu_sd_executeCleanupBlock (__strong bu_sd_cleanupBlock_t *block);
  51. #if defined(__cplusplus)
  52. }
  53. #endif