Add mechanizm for caching local and peer addresses in AsyncSSLSocket.
[folly.git] / folly / SpinLock.h
1 /*
2  * Copyright 2015 Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #pragma once
18
19 #include <folly/detail/SpinLockImpl.h>
20
21 namespace folly {
22
23 #if __x86_64__
24 typedef SpinLockMslImpl SpinLock;
25 #elif __APPLE__
26 typedef SpinLockAppleImpl SpinLock;
27 #elif FOLLY_HAVE_PTHREAD_SPINLOCK_T
28 typedef SpinLockPthreadImpl SpinLock;
29 #else
30 typedef SpinLockPthreadMutexImpl SpinLock;
31 #endif
32
33 template <typename LOCK>
34 class SpinLockGuardImpl : private boost::noncopyable {
35  public:
36   FOLLY_ALWAYS_INLINE explicit SpinLockGuardImpl(LOCK& lock) :
37     lock_(lock) {
38     lock_.lock();
39   }
40   FOLLY_ALWAYS_INLINE ~SpinLockGuardImpl() {
41     lock_.unlock();
42   }
43  private:
44   LOCK& lock_;
45 };
46
47 typedef SpinLockGuardImpl<SpinLock> SpinLockGuard;
48
49 }