Commit e092e957 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Convert newlines in folly/portability/PThread.cpp

Summary:
[Folly] Convert newlines in `folly/portability/PThread.cpp`.

```
dos2unix folly/portability/PThread.cpp
```

Reviewed By: meyering

Differential Revision: D6720343

fbshipit-source-id: b92122b4a7012d7f8d73d293af51b4fcc868c582
parent 98d1077c
/* /*
* Copyright 2017 Facebook, Inc. * Copyright 2017 Facebook, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include <folly/portability/PThread.h> #include <folly/portability/PThread.h>
#if !FOLLY_HAVE_PTHREAD && _WIN32 #if !FOLLY_HAVE_PTHREAD && _WIN32
#include <unordered_map> #include <unordered_map>
#include <utility> #include <utility>
namespace folly { namespace folly {
namespace portability { namespace portability {
namespace pthread { namespace pthread {
static thread_local struct PThreadLocalMap { static thread_local struct PThreadLocalMap {
PThreadLocalMap() = default; PThreadLocalMap() = default;
~PThreadLocalMap() { ~PThreadLocalMap() {
for (auto kv : keyMap) { for (auto kv : keyMap) {
// Call destruction callbacks if they exist. // Call destruction callbacks if they exist.
if (kv.second.second != nullptr) { if (kv.second.second != nullptr) {
kv.second.second(kv.second.first); kv.second.second(kv.second.first);
} }
} }
} }
int createKey(pthread_key_t* key, void (*destructor)(void*)) { int createKey(pthread_key_t* key, void (*destructor)(void*)) {
auto ret = TlsAlloc(); auto ret = TlsAlloc();
if (ret == TLS_OUT_OF_INDEXES) { if (ret == TLS_OUT_OF_INDEXES) {
return -1; return -1;
} }
*key = ret; *key = ret;
keyMap.emplace(*key, std::make_pair(nullptr, destructor)); keyMap.emplace(*key, std::make_pair(nullptr, destructor));
return 0; return 0;
} }
int deleteKey(pthread_key_t key) { int deleteKey(pthread_key_t key) {
if (!TlsFree(key)) { if (!TlsFree(key)) {
return -1; return -1;
} }
keyMap.erase(key); keyMap.erase(key);
return 0; return 0;
} }
void* getKey(pthread_key_t key) { void* getKey(pthread_key_t key) {
return TlsGetValue(key); return TlsGetValue(key);
} }
int setKey(pthread_key_t key, void* value) { int setKey(pthread_key_t key, void* value) {
if (!TlsSetValue(key, value)) { if (!TlsSetValue(key, value)) {
return -1; return -1;
} }
keyMap[key].first = value; keyMap[key].first = value;
return 0; return 0;
} }
std::unordered_map<pthread_key_t, std::pair<void*, void (*)(void*)>> keyMap{}; std::unordered_map<pthread_key_t, std::pair<void*, void (*)(void*)>> keyMap{};
} s_tls_key_map; } s_tls_key_map;
int pthread_key_create(pthread_key_t* key, void (*destructor)(void*)) { int pthread_key_create(pthread_key_t* key, void (*destructor)(void*)) {
return s_tls_key_map.createKey(key, destructor); return s_tls_key_map.createKey(key, destructor);
} }
int pthread_key_delete(pthread_key_t key) { int pthread_key_delete(pthread_key_t key) {
return s_tls_key_map.deleteKey(key); return s_tls_key_map.deleteKey(key);
} }
void* pthread_getspecific(pthread_key_t key) { void* pthread_getspecific(pthread_key_t key) {
return s_tls_key_map.getKey(key); return s_tls_key_map.getKey(key);
} }
int pthread_setspecific(pthread_key_t key, const void* value) { int pthread_setspecific(pthread_key_t key, const void* value) {
// Yes, the PThread API really is this bad -_-... // Yes, the PThread API really is this bad -_-...
return s_tls_key_map.setKey(key, const_cast<void*>(value)); return s_tls_key_map.setKey(key, const_cast<void*>(value));
} }
} }
} }
} }
#endif #endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment