mirror of https://github.com/grpc/grpc.git
parent
4c8d6fb8f5
commit
9c142c9dc9
7 changed files with 269 additions and 35 deletions
@ -0,0 +1,71 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2018 gRPC authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef GRPC_IMPL_CODEGEN_ATM64_H |
||||
#define GRPC_IMPL_CODEGEN_ATM64_H |
||||
|
||||
/** This interface provides atomic operations and barriers for 64 bit integer
|
||||
data types (instead of intptr_t so that this works on both 32-bit and 64-bit |
||||
systems. |
||||
|
||||
It is internal to gpr support code and should not be used outside it. |
||||
|
||||
If an operation with acquire semantics precedes another memory access by the |
||||
same thread, the operation will precede that other access as seen by other |
||||
threads. |
||||
|
||||
If an operation with release semantics follows another memory access by the |
||||
same thread, the operation will follow that other access as seen by other |
||||
threads. |
||||
|
||||
Routines with "acq" or "full" in the name have acquire semantics. Routines |
||||
with "rel" or "full" in the name have release semantics. Routines with |
||||
"no_barrier" in the name have neither acquire not release semantics. |
||||
|
||||
The routines may be implemented as macros. |
||||
|
||||
// Atomic operations act on an intergral_type gpr_atm64 that is 64 bit wide
|
||||
typedef int64_t gpr_atm64; |
||||
|
||||
gpr_atm64 gpr_atm64_no_barrier_load(gpr_atm64 *p); |
||||
|
||||
// Atomically set *p = value, with release semantics.
|
||||
void gpr_atm64_no_barrier_store(gpr_atm64 *p, gpr_atm64 value); |
||||
*/ |
||||
|
||||
#include <grpc/impl/codegen/port_platform.h> |
||||
|
||||
#if defined(GPR_GCC_ATOMIC) |
||||
#include <grpc/impl/codegen/atm64_gcc_atomic.h> |
||||
#elif defined(GPR_GCC_SYNC) |
||||
#include <grpc/impl/codegen/atm64_gcc_sync.h> |
||||
#elif defined(GPR_WINDOWS_ATOMIC) |
||||
#include <grpc/impl/codegen/atm64_windows.h> |
||||
#else |
||||
#error could not determine platform for atm |
||||
#endif |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
|
||||
#endif /* GRPC_IMPL_CODEGEN_ATM64_H */ |
@ -0,0 +1,42 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2018 gRPC authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef GRPC_IMPL_CODEGEN_ATM64_GCC_ATOMIC_H |
||||
#define GRPC_IMPL_CODEGEN_ATM64_GCC_ATOMIC_H |
||||
|
||||
/* atm_platform.h for gcc and gcc-like compilers with the
|
||||
__atomic_* interface. */ |
||||
#include <grpc/impl/codegen/port_platform.h> |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
typedef int64_t gpr_atm64; |
||||
#define GPR_ATM64_MAX INT64_MAX |
||||
#define GPR_ATM64_MIN INT64_MIN |
||||
|
||||
#define gpr_atm_no_barrier_load(p) (__atomic_load_n((p), __ATOMIC_RELAXED)) |
||||
#define gpr_atm_no_barrier_store(p, value) \ |
||||
(__atomic_store_n((p), (int64_t)(value), __ATOMIC_RELAXED)) |
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
|
||||
#endif /* GRPC_IMPL_CODEGEN_ATM64_GCC_ATOMIC_H */ |
@ -0,0 +1,43 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2015 gRPC authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef GRPC_IMPL_CODEGEN_ATM64_GCC_SYNC64_H |
||||
#define GRPC_IMPL_CODEGEN_ATM64_GCC_SYNC64_H |
||||
|
||||
/* variant of atm_platform.h for gcc and gcc-like compiers with __sync_*
|
||||
interface */ |
||||
#include <grpc/impl/codegen/port_platform.h> |
||||
|
||||
typedef int64_t gpr_atm64; |
||||
#define GPR_ATM64_MAX INT64_MAX |
||||
#define GPR_ATM64_MIN INT64_MIN |
||||
|
||||
#define GPR_ATM64_COMPILE_BARRIER_() __asm__ __volatile__("" : : : "memory") |
||||
|
||||
static __inline gpr_atm64 gpr_atm64_no_barrier_load(const gpr_atm64* p) { |
||||
gpr_atm64 value = *p; |
||||
GPR_ATM64_COMPILE_BARRIER_(); |
||||
return value; |
||||
} |
||||
|
||||
static __inline void gpr_atm64_no_barrier_store(gpr_atm64* p, gpr_atm64 value) { |
||||
GPR_ATM64_COMPILE_BARRIER_(); |
||||
*p = value; |
||||
} |
||||
|
||||
#endif /* GRPC_IMPL_CODEGEN_ATM64_GCC_SYNC64_H */ |
@ -0,0 +1,50 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2015 gRPC authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef GRPC_IMPL_CODEGEN_ATM64_WINDOWS_H |
||||
#define GRPC_IMPL_CODEGEN_ATM64_WINDOWS_H |
||||
|
||||
/** Win32 variant of atm_platform.h */ |
||||
#include <grpc/impl/codegen/port_platform.h> |
||||
|
||||
typedef int64_t gpr_atm64; |
||||
#define GPR_ATM64_MAX INT64_MAX |
||||
#define GPR_ATM64_MIN INT64_MIN |
||||
|
||||
#define gpr_atm64_full_barrier MemoryBarrier |
||||
|
||||
static __inline gpr_atm64 gpr_atm64_acq_load(const gpr_atm64* p) { |
||||
gpr_atm64 result = *p; |
||||
gpr_atm64_full_barrier(); |
||||
return result; |
||||
} |
||||
|
||||
static __inline gpr_atm64 gpr_atm64_no_barrier_load(const gpr_atm64* p) { |
||||
return gpr_atm64_acq_load(p); |
||||
} |
||||
|
||||
static __inline void gpr_atm64_rel_store(gpr_atm64* p, gpr_atm64 value) { |
||||
gpr_atm64_full_barrier(); |
||||
*p = value; |
||||
} |
||||
|
||||
static __inline void gpr_atm64_no_barrier_store(gpr_atm64* p, gpr_atm64 value) { |
||||
gpr_atm64_rel_store(p, value); |
||||
} |
||||
|
||||
#endif /* GRPC_IMPL_CODEGEN_ATM64_WINDOWS_H */ |
@ -0,0 +1,26 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2018 gRPC authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef GRPC_SUPPORT_ATM64_H |
||||
#define GRPC_SUPPORT_ATM64_H |
||||
|
||||
#include <grpc/support/port_platform.h> |
||||
|
||||
#include <grpc/impl/codegen/atm64.h> |
||||
|
||||
#endif /* GRPC_SUPPORT_ATM64_H */ |
Loading…
Reference in new issue