scoped_mach_msg_destroy.h 903 B

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright 2018 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef BASE_MAC_SCOPED_MACH_MSG_DESTROY_H_
  5. #define BASE_MAC_SCOPED_MACH_MSG_DESTROY_H_
  6. #include <mach/message.h>
  7. #include "base/macros.h"
  8. namespace base {
  9. // Calls mach_msg_destroy on the specified message when the object goes out
  10. // of scope.
  11. class ScopedMachMsgDestroy {
  12. public:
  13. explicit ScopedMachMsgDestroy(mach_msg_header_t* header) : header_(header) {}
  14. ~ScopedMachMsgDestroy() {
  15. if (header_) {
  16. mach_msg_destroy(header_);
  17. }
  18. }
  19. // Prevents the message from being destroyed when it goes out of scope.
  20. void Disarm() { header_ = nullptr; }
  21. private:
  22. mach_msg_header_t* header_;
  23. DISALLOW_COPY_AND_ASSIGN(ScopedMachMsgDestroy);
  24. };
  25. } // namespace base
  26. #endif // BASE_MAC_SCOPED_MACH_MSG_DESTROY_H_