MMKV_OSX.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Tencent is pleased to support the open source community by making
  3. * MMKV available.
  4. *
  5. * Copyright (C) 2019 THL A29 Limited, a Tencent company.
  6. * All rights reserved.
  7. *
  8. * Licensed under the BSD 3-Clause License (the "License"); you may not use
  9. * this file except in compliance with the License. You may obtain a copy of
  10. * the License at
  11. *
  12. * https://opensource.org/licenses/BSD-3-Clause
  13. *
  14. * Unless required by applicable law or agreed to in writing, software
  15. * distributed under the License is distributed on an "AS IS" BASIS,
  16. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. * See the License for the specific language governing permissions and
  18. * limitations under the License.
  19. */
  20. #pragma once
  21. #include "MMKVPredef.h"
  22. #if defined(MMKV_IOS) && defined(__cplusplus)
  23. MMKV_NAMESPACE_BEGIN
  24. class MLockPtr {
  25. size_t m_lockDownSize;
  26. uint8_t *m_lockedPtr;
  27. public:
  28. MLockPtr(void *ptr, size_t size);
  29. MLockPtr(MLockPtr &&other);
  30. ~MLockPtr();
  31. bool isLocked() const {
  32. return (m_lockedPtr != nullptr);
  33. }
  34. // just forbid it for possibly misuse
  35. explicit MLockPtr(const MLockPtr &other) = delete;
  36. MLockPtr &operator=(const MLockPtr &other) = delete;
  37. };
  38. std::pair<bool, MLockPtr> guardForBackgroundWriting(void *ptr, size_t size);
  39. MMKV_NAMESPACE_END
  40. #endif