MCPcopy Create free account
hub / github.com/apache/brpc / FightAuthentication

Method FightAuthentication

src/brpc/socket.cpp:2124–2144  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2122}
2123
2124int Socket::FightAuthentication(int* auth_error) {
2125 // Use relaxed fence since `bthread_id_trylock' ensures thread safety
2126 // Here `flag_error' just acts like a cache information
2127 uint64_t flag_error = _auth_flag_error.load(butil::memory_order_relaxed);
2128 if (flag_error & AUTH_FLAG) {
2129 // Already authenticated
2130 *auth_error = (int32_t)(flag_error & 0xFFFFFFFFul);
2131 return EINVAL;
2132 }
2133 if (0 == bthread_id_trylock(_auth_id, NULL)) {
2134 // Winner
2135 return 0;
2136 } else {
2137 // Use relaxed fence since `bthread_id_join' has acquire fence to ensure
2138 // `_auth_flag_error' to be the latest value
2139 bthread_id_join(_auth_id);
2140 flag_error = _auth_flag_error.load(butil::memory_order_relaxed);
2141 *auth_error = (int32_t)(flag_error & 0xFFFFFFFFul);
2142 return EINVAL;
2143 }
2144}
2145
2146void Socket::SetAuthentication(int error_code) {
2147 uint64_t expected = 0;

Callers 4

auth_fighterFunction · 0.80
TEST_FFunction · 0.80
ProcessNewMessageMethod · 0.80
IssueRPCMethod · 0.80

Calls 3

bthread_id_trylockFunction · 0.85
bthread_id_joinFunction · 0.85
loadMethod · 0.45

Tested by 2

auth_fighterFunction · 0.64
TEST_FFunction · 0.64