2 * Copyright 2016 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.
22 // We implement a sane comparison operand for
23 // pthread_t and an integer so that it may be
24 // compared against 0.
26 inline bool operator==(pthread_t ptA, unsigned int b) {
27 if (ptA.p == nullptr) {
30 return pthread_getw32threadid_np(ptA) == b;
33 inline bool operator!=(pthread_t ptA, unsigned int b) {
34 if (ptA.p == nullptr) {
37 return pthread_getw32threadid_np(ptA) != b;
40 inline bool operator==(pthread_t ptA, pthread_t ptB) {
41 return pthread_equal(ptA, ptB) != 0;
44 inline bool operator!=(pthread_t ptA, pthread_t ptB) {
45 return pthread_equal(ptA, ptB) == 0;
48 inline bool operator<(pthread_t ptA, pthread_t ptB) {
52 inline bool operator!(pthread_t ptA) {
56 inline int pthread_attr_getstack(
60 if (pthread_attr_getstackaddr(attr, stackaddr) != 0) {
63 if (pthread_attr_getstacksize(attr, stacksize) != 0) {
70 pthread_attr_setstack(pthread_attr_t* attr, void* stackaddr, size_t stacksize) {
71 if (pthread_attr_setstackaddr(attr, stackaddr) != 0) {
74 if (pthread_attr_setstacksize(attr, stacksize) != 0) {
80 inline int pthread_attr_getguardsize(pthread_attr_t* attr, size_t* guardsize) {
88 struct hash<pthread_t> {
89 std::size_t operator()(const pthread_t& k) const {
90 return 0 ^ std::hash<decltype(k.p)>()(k.p) ^
91 std::hash<decltype(k.x)>()(k.x);