OLD | NEW |
1 // Copyright (C) 2011 The Libphonenumber Authors | 1 // Copyright (C) 2011 The Libphonenumber Authors |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
(...skipping 16 matching lines...) Expand all Loading... |
27 typedef boost::mutex::scoped_lock AutoLock; | 27 typedef boost::mutex::scoped_lock AutoLock; |
28 | 28 |
29 } // namespace phonenumbers | 29 } // namespace phonenumbers |
30 } // namespace i18n | 30 } // namespace i18n |
31 | 31 |
32 #else // I18N_PHONENUMBERS_USE_BOOST | 32 #else // I18N_PHONENUMBERS_USE_BOOST |
33 | 33 |
34 #include "phonenumbers/base/logging.h" | 34 #include "phonenumbers/base/logging.h" |
35 #include "phonenumbers/base/thread_checker.h" | 35 #include "phonenumbers/base/thread_checker.h" |
36 | 36 |
| 37 // Dummy lock implementation on non-POSIX platforms. If you are running on a |
| 38 // different platform and care about thread-safety, please compile with |
| 39 // -DI18N_PHONENUMBERS_USE_BOOST. |
| 40 #if !defined(__linux__) && !defined(__APPLE__) |
| 41 |
37 namespace i18n { | 42 namespace i18n { |
38 namespace phonenumbers { | 43 namespace phonenumbers { |
39 | 44 |
40 // Dummy lock implementation. If you care about thread-safety, please compile | |
41 // with -DI18N_PHONENUMBERS_USE_BOOST. | |
42 class Lock { | 45 class Lock { |
43 public: | 46 public: |
44 Lock() : thread_checker_() {} | 47 Lock() : thread_checker_() {} |
45 | 48 |
46 void Acquire() const { | 49 void Acquire() const { |
47 DCHECK(thread_checker_.CalledOnValidThread()); | 50 DCHECK(thread_checker_.CalledOnValidThread()); |
48 } | 51 } |
49 | 52 |
50 // No need for Release() since Acquire() is a no-op and Release() is not used | 53 void Release() const { |
51 // in the codebase. | 54 DCHECK(thread_checker_.CalledOnValidThread()); |
| 55 } |
52 | 56 |
53 private: | 57 private: |
54 const ThreadChecker thread_checker_; | 58 const ThreadChecker thread_checker_; |
55 }; | 59 }; |
56 | 60 |
| 61 } // namespace phonenumbers |
| 62 } // namespace i18n |
| 63 |
| 64 #else |
| 65 #include "phonenumbers/base/synchronization/lock_posix.h" |
| 66 #endif |
| 67 |
| 68 namespace i18n { |
| 69 namespace phonenumbers { |
| 70 |
57 class AutoLock { | 71 class AutoLock { |
58 public: | 72 public: |
59 AutoLock(Lock& lock) { | 73 AutoLock(Lock& lock) : lock_(lock) { |
60 lock.Acquire(); | 74 lock_.Acquire(); |
61 } | 75 } |
| 76 |
| 77 ~AutoLock() { |
| 78 lock_.Release(); |
| 79 } |
| 80 |
| 81 private: |
| 82 Lock& lock_; |
62 }; | 83 }; |
63 | 84 |
64 } // namespace phonenumbers | 85 } // namespace phonenumbers |
65 } // namespace i18n | 86 } // namespace i18n |
66 | 87 |
67 #endif // I18N_PHONENUMBERS_USE_BOOST | 88 #endif // I18N_PHONENUMBERS_USE_BOOST |
68 #endif // I18N_PHONENUMBERS_BASE_SYNCHRONIZATION_LOCK_H_ | 89 #endif // I18N_PHONENUMBERS_BASE_SYNCHRONIZATION_LOCK_H_ |
OLD | NEW |