2 * Copyright 2017 Facebook, Inc.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <folly/portability/Config.h>
21 #if !FOLLY_HAVE_PTHREAD
24 #error Building Folly without pthreads is only supported on Windows.
27 #include <folly/portability/Windows.h>
31 namespace portability {
33 using pthread_key_t = DWORD;
35 int pthread_key_create(pthread_key_t* key, void (*destructor)(void*));
36 int pthread_key_delete(pthread_key_t key);
37 void* pthread_getspecific(pthread_key_t key);
38 int pthread_setspecific(pthread_key_t key, const void* value);
43 /* using override */ using namespace folly::portability::pthread;
50 // We implement a sane comparison operand for
51 // pthread_t and an integer so that it may be
52 // compared against 0.
54 inline bool operator==(pthread_t ptA, unsigned int b) {
55 if (ptA.p == nullptr) {
58 return pthread_getw32threadid_np(ptA) == b;
61 inline bool operator!=(pthread_t ptA, unsigned int b) {
62 if (ptA.p == nullptr) {
65 return pthread_getw32threadid_np(ptA) != b;
68 inline bool operator==(pthread_t ptA, pthread_t ptB) {
69 return pthread_equal(ptA, ptB) != 0;
72 inline bool operator!=(pthread_t ptA, pthread_t ptB) {
73 return pthread_equal(ptA, ptB) == 0;
76 inline bool operator<(pthread_t ptA, pthread_t ptB) {
80 inline bool operator!(pthread_t ptA) {
84 inline int pthread_attr_getstack(
88 if (pthread_attr_getstackaddr(attr, stackaddr) != 0) {
91 if (pthread_attr_getstacksize(attr, stacksize) != 0) {
98 pthread_attr_setstack(pthread_attr_t* attr, void* stackaddr, size_t stacksize) {
99 if (pthread_attr_setstackaddr(attr, stackaddr) != 0) {
102 if (pthread_attr_setstacksize(attr, stacksize) != 0) {
108 inline int pthread_attr_getguardsize(
109 pthread_attr_t* /* attr */,
115 #include <functional>
118 struct hash<pthread_t> {
119 std::size_t operator()(const pthread_t& k) const {
120 return 0 ^ std::hash<decltype(k.p)>()(k.p) ^
121 std::hash<decltype(k.x)>()(k.x);