create_thread_identity.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2017 The Abseil Authors.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *      https://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 // Interface for getting the current ThreadIdentity, creating one if necessary.
00018 // See thread_identity.h.
00019 //
00020 // This file is separate from thread_identity.h because creating a new
00021 // ThreadIdentity requires slightly higher level libraries (per_thread_sem
00022 // and low_level_alloc) than accessing an existing one.  This separation allows
00023 // us to have a smaller //absl/base:base.
00024 
00025 #ifndef ABSL_SYNCHRONIZATION_INTERNAL_CREATE_THREAD_IDENTITY_H_
00026 #define ABSL_SYNCHRONIZATION_INTERNAL_CREATE_THREAD_IDENTITY_H_
00027 
00028 #include "absl/base/internal/thread_identity.h"
00029 #include "absl/base/port.h"
00030 
00031 namespace absl {
00032 namespace synchronization_internal {
00033 
00034 // Allocates and attaches a ThreadIdentity object for the calling thread.
00035 // For private use only.
00036 base_internal::ThreadIdentity* CreateThreadIdentity();
00037 
00038 // Returns the ThreadIdentity object representing the calling thread; guaranteed
00039 // to be unique for its lifetime.  The returned object will remain valid for the
00040 // program's lifetime; although it may be re-assigned to a subsequent thread.
00041 // If one does not exist for the calling thread, allocate it now.
00042 inline base_internal::ThreadIdentity* GetOrCreateCurrentThreadIdentity() {
00043   base_internal::ThreadIdentity* identity =
00044       base_internal::CurrentThreadIdentityIfPresent();
00045   if (ABSL_PREDICT_FALSE(identity == nullptr)) {
00046     return CreateThreadIdentity();
00047   }
00048   return identity;
00049 }
00050 
00051 }  // namespace synchronization_internal
00052 }  // namespace absl
00053 
00054 #endif  // ABSL_SYNCHRONIZATION_INTERNAL_CREATE_THREAD_IDENTITY_H_


abseil_cpp
Author(s):
autogenerated on Wed Jun 19 2019 19:42:14