cef_lock_impl.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // Copyright (c) 2011 Google Inc. All rights reserved.
  2. //
  3. // Redistribution and use in source and binary forms, with or without
  4. // modification, are permitted provided that the following conditions are
  5. // met:
  6. //
  7. // * Redistributions of source code must retain the above copyright
  8. // notice, this list of conditions and the following disclaimer.
  9. // * Redistributions in binary form must reproduce the above
  10. // copyright notice, this list of conditions and the following disclaimer
  11. // in the documentation and/or other materials provided with the
  12. // distribution.
  13. // * Neither the name of Google Inc. nor the name Chromium Embedded
  14. // Framework nor the names of its contributors may be used to endorse
  15. // or promote products derived from this software without specific prior
  16. // written permission.
  17. //
  18. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. // Do not include this header file directly. Use base/cef_lock.h instead.
  30. #ifndef CEF_INCLUDE_BASE_INTERNAL_CEF_LOCK_IMPL_H_
  31. #define CEF_INCLUDE_BASE_INTERNAL_CEF_LOCK_IMPL_H_
  32. #include "include/base/cef_build.h"
  33. #if defined(OS_WIN)
  34. #include <windows.h>
  35. #elif defined(OS_POSIX)
  36. #include <pthread.h>
  37. #endif
  38. #include "include/base/cef_macros.h"
  39. namespace base {
  40. namespace cef_internal {
  41. // This class implements the underlying platform-specific spin-lock mechanism
  42. // used for the Lock class. Most users should not use LockImpl directly, but
  43. // should instead use Lock.
  44. class LockImpl {
  45. public:
  46. #if defined(OS_WIN)
  47. typedef CRITICAL_SECTION NativeHandle;
  48. #elif defined(OS_POSIX)
  49. typedef pthread_mutex_t NativeHandle;
  50. #endif
  51. LockImpl();
  52. ~LockImpl();
  53. // If the lock is not held, take it and return true. If the lock is already
  54. // held by something else, immediately return false.
  55. bool Try();
  56. // Take the lock, blocking until it is available if necessary.
  57. void Lock();
  58. // Release the lock. This must only be called by the lock's holder: after
  59. // a successful call to Try, or a call to Lock.
  60. void Unlock();
  61. // Return the native underlying lock.
  62. // TODO(awalker): refactor lock and condition variables so that this is
  63. // unnecessary.
  64. NativeHandle* native_handle() { return &native_handle_; }
  65. private:
  66. NativeHandle native_handle_;
  67. DISALLOW_COPY_AND_ASSIGN(LockImpl);
  68. };
  69. } // namespace cef_internal
  70. } // namespace base
  71. #endif // CEF_INCLUDE_BASE_INTERNAL_CEF_LOCK_IMPL_H_