diff --git a/src/brpc/ubshm/common/common.h b/src/brpc/ubshm/common/common.h index f5bffa14b9..c64ae9843f 100644 --- a/src/brpc/ubshm/common/common.h +++ b/src/brpc/ubshm/common/common.h @@ -130,9 +130,9 @@ static inline uint64_t GetCurNanoSeconds(void) { #define FREE_PTR(ptr) \ do { \ - if ((ptr) != NULL) { \ + if ((ptr) != nullptr) { \ free(ptr); \ - (ptr) = NULL; \ + (ptr) = nullptr; \ } \ } while (0) diff --git a/src/brpc/ubshm/common/thread_lock.h b/src/brpc/ubshm/common/thread_lock.h index 3c274ce0cd..0233955168 100644 --- a/src/brpc/ubshm/common/thread_lock.h +++ b/src/brpc/ubshm/common/thread_lock.h @@ -30,7 +30,7 @@ extern "C" { static inline void UnlockMutex(pthread_mutex_t **mtx) { - if (LIKELY(mtx != NULL && *mtx != NULL)) { + if (LIKELY(mtx != nullptr && *mtx != nullptr)) { pthread_mutex_unlock(*mtx); } else { LOG(ERROR) << "Invalid input for mtx."; diff --git a/src/brpc/ubshm/shm/shm_ipc.cpp b/src/brpc/ubshm/shm/shm_ipc.cpp index a63e9cdd7c..f0a9d7ea1c 100644 --- a/src/brpc/ubshm/shm/shm_ipc.cpp +++ b/src/brpc/ubshm/shm/shm_ipc.cpp @@ -91,10 +91,10 @@ RETURN_CODE IpcShmLocalMalloc(SHM *shm) return SHM_ERR; } - shm->addr = (uint8_t*)mmap(NULL, shm->len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + shm->addr = (uint8_t*)mmap(nullptr, shm->len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (shm->addr == (uint8_t*)MAP_FAILED) { LOG(ERROR) << "IPC map shm=" << shm->name << " length=" << shm->len << " failed, ret(" << errno << ")."; - shm->addr = NULL; + shm->addr = nullptr; close(fd); shm_unlink(shm->name); return SHM_ERR; @@ -106,7 +106,7 @@ RETURN_CODE IpcShmLocalMalloc(SHM *shm) RETURN_CODE IpcShmMunmap(SHM *shm) { - if (shm->addr == NULL) { + if (shm->addr == nullptr) { LOG(INFO) << "IPC unmap shm=" << shm->name << " already unmapped."; return UBRING_OK; } @@ -117,7 +117,7 @@ RETURN_CODE IpcShmMunmap(SHM *shm) return SHM_ERR; } - shm->addr = NULL; + shm->addr = nullptr; LOG(INFO) << "IPC unmap shm=" << shm->name << " length=" << shm->len << " success."; return UBRING_OK; } @@ -133,7 +133,7 @@ RETURN_CODE IpcShmFree(SHM *shm) } if (errno == ENOENT) { LOG(INFO) << "IPC free shm=" << shm->name << " already deleted."; - shm->addr = NULL; + shm->addr = nullptr; return SHM_ERR_NOT_FOUND; } LOG_EVERY_SECOND(ERROR) << "IPC free shm=" << shm->name << " failed, errno=" << errno; @@ -144,7 +144,7 @@ RETURN_CODE IpcShmFree(SHM *shm) RETURN_CODE IpcShmLocalFree(SHM *shm) { - if (shm->addr == NULL) { + if (shm->addr == nullptr) { LOG(INFO) << "IPC free local shm=" << shm->name << " already freed."; return SHM_ERR_NOT_FOUND; } @@ -153,7 +153,7 @@ RETURN_CODE IpcShmLocalFree(SHM *shm) if (ret != UBRING_OK) { LOG(WARNING) << "IPC unmap shm=" << shm->name << " failed, ret=" << ret; } else { - shm->addr = NULL; + shm->addr = nullptr; } ret = shm_unlink(shm->name); @@ -164,13 +164,13 @@ RETURN_CODE IpcShmLocalFree(SHM *shm) } if (errno == ENOENT) { LOG(INFO) << "IPC delete shm=" << shm->name << " already deleted by peer."; - shm->addr = NULL; + shm->addr = nullptr; return SHM_ERR_NOT_FOUND; } LOG_EVERY_SECOND(ERROR) << "IPC delete shm=" << shm->name << " failed, ret=" << ret; return SHM_ERR; } - shm->addr = NULL; + shm->addr = nullptr; LOG(INFO) << "IPC free local shm=" << shm->name << " success."; return UBRING_OK; } @@ -188,10 +188,10 @@ RETURN_CODE IpcShmRemoteMalloc(SHM *shm) return SHM_ERR; } - shm->addr = (uint8_t*)mmap(NULL, shm->len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + shm->addr = (uint8_t*)mmap(nullptr, shm->len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (shm->addr == (uint8_t*)MAP_FAILED) { LOG(ERROR) << "IPC map shm=" << shm->name << " failed, ret=" << errno; - shm->addr = NULL; + shm->addr = nullptr; close(fd); return SHM_ERR; } @@ -213,10 +213,10 @@ RETURN_CODE IpcShmLocalMmap(SHM *shm, int prot) return SHM_ERR; } - shm->addr = (uint8_t*)mmap(NULL, shm->len, prot, MAP_SHARED, fd, 0); + shm->addr = (uint8_t*)mmap(nullptr, shm->len, prot, MAP_SHARED, fd, 0); if (shm->addr == (uint8_t*)MAP_FAILED) { LOG(ERROR) << "IPC map shm=" << shm->name << " failed, ret=" << errno; - shm->addr = NULL; + shm->addr = nullptr; close(fd); return SHM_ERR; } @@ -228,7 +228,7 @@ RETURN_CODE IpcShmLocalMmap(SHM *shm, int prot) RETURN_CODE IpcShmRemoteFree(SHM *shm) { - if (shm->addr == NULL) { + if (shm->addr == nullptr) { LOG(INFO) << "IPC free remote shm=" << shm->name << " already freed."; return UBRING_OK; } @@ -239,7 +239,7 @@ RETURN_CODE IpcShmRemoteFree(SHM *shm) return SHM_ERR; } - shm->addr = NULL; + shm->addr = nullptr; LOG(INFO) << "IPC free remote shm=" << shm->name << " success."; return UBRING_OK; } diff --git a/src/brpc/ubshm/shm/shm_mgr.cpp b/src/brpc/ubshm/shm/shm_mgr.cpp index 9535cc1a90..ea01113e54 100644 --- a/src/brpc/ubshm/shm/shm_mgr.cpp +++ b/src/brpc/ubshm/shm/shm_mgr.cpp @@ -31,7 +31,7 @@ DEFINE_int32(ub_shm_type, 1, "shm type: 1-ipc; 2-ub_ring"); static SHM_TYPE g_shm_type; static bool CheckInputShmParam(SHM *shm) { - if (shm == NULL) { + if (shm == nullptr) { LOG(ERROR) << "Input Param shm is NULL."; return false; } @@ -114,7 +114,7 @@ RETURN_CODE ShmLocalCalloc(SHM *shm) { LOG(ERROR) << "Failed to alloc local shm."; return rc; } - if (UNLIKELY(shm->addr == NULL)) { + if (UNLIKELY(shm->addr == nullptr)) { LOG(ERROR) << "Local shm=" << shm->name << " allocated with NULL address."; ShmFree(shm); return SHM_ERR; diff --git a/src/brpc/ubshm/shm/shm_ubs.cpp b/src/brpc/ubshm/shm/shm_ubs.cpp index f1da0fc7a7..2d06b0a15b 100644 --- a/src/brpc/ubshm/shm/shm_ubs.cpp +++ b/src/brpc/ubshm/shm/shm_ubs.cpp @@ -36,7 +36,7 @@ namespace brpc { namespace ubring { -#define UBRING_MK_UBSM(ret, fn, args) ret (*fn) args = NULL +#define UBRING_MK_UBSM(ret, fn, args) ret (*fn) args = nullptr #include "brpc/ubshm/ubs_mem/declare_shm_ubs.h" #define SHM_RIGHT_MODE 0666 #define UBRING_REGION_NAME_PREFIX "UbrONE2ALLRegion" @@ -47,7 +47,7 @@ DEFINE_int32(ub_flying_io_timeout, 5, "Waiting time for stopping data" "sending and receiving when the link is disconnected."); char g_region_name[MAX_REGION_NAME_DESC_LENGTH] = {0}; int g_shm_timer_fd = 0; -ShmList *g_shm_list = NULL; +ShmList *g_shm_list = nullptr; static RETURN_CODE UbsShmInterfacesLoad(void); char hostname[MAX_HOST_NAME_DESC_LENGTH]; @@ -60,7 +60,7 @@ RETURN_CODE UbsShmInterfacesLoad(void) #elif defined(OS_MACOSX) void* dlhandler = dlopen(ubsm_sdk_location, RTLD_NOW | RTLD_LOCAL | RTLD_NODELETE); #endif - if (dlhandler == NULL) { + if (dlhandler == nullptr) { LOG(ERROR) << "Dlopen libubsm_sdk.so in " << ubsm_sdk_location << " failed, error:" << dlerror(); return UBRING_ERR; } @@ -72,11 +72,11 @@ RETURN_CODE UbsShmInterfacesLoad(void) #define UBRING_MK_UBSM(ret, fn, args) \ do { \ - if ((fn) != NULL) { \ + if ((fn) != nullptr) { \ break; \ } \ UBRING_MK_UBSM_OPTIONAL(ret, fn, args); \ - if ((fn) == NULL) { \ + if ((fn) == nullptr) { \ LOG(ERROR) << "Fail load ubs_mem func " << #fn <<" error:" << dlerror(); \ return UBRING_ERR; \ } \ @@ -84,7 +84,7 @@ RETURN_CODE UbsShmInterfacesLoad(void) #include "brpc/ubshm/ubs_mem/declare_shm_ubs.h" dlclose(dlhandler); - dlhandler = NULL; + dlhandler = nullptr; #endif return UBRING_OK; } @@ -155,7 +155,7 @@ do { } } while (0); - ret = ubsmem_shmem_map(NULL, shm->len, PROT_READ | PROT_WRITE, MAP_SHARED, shm->name, 0, (void**)&(shm->addr)); + ret = ubsmem_shmem_map(nullptr, shm->len, PROT_READ | PROT_WRITE, MAP_SHARED, shm->name, 0, (void**)&(shm->addr)); if (ret != UBSM_OK) { LOG(ERROR) << "Ubs map shm=" << shm->name << " failed, ret=" << ret; if (ret == UBSM_ERR_NOT_FOUND) { @@ -174,7 +174,7 @@ do { RETURN_CODE UbsShmMunmap(SHM *shm) { // unmap - if (shm->addr == NULL) { + if (shm->addr == nullptr) { LOG(ERROR) << "Ubs input shm param is invalid, addr is NULL."; return SHM_ERR_INPUT_INVALID; } @@ -196,7 +196,7 @@ RETURN_CODE UbsShmMunmap(SHM *shm) RETURN_CODE UbsShmFree(SHM *shm) { - if (shm->addr == NULL) { + if (shm->addr == nullptr) { LOG(ERROR) << "Ubs input shm param is invalid, addr is NULL."; return SHM_ERR_INPUT_INVALID; } @@ -214,7 +214,7 @@ RETURN_CODE UbsShmFree(SHM *shm) LOG(ERROR) << "Ubs free shm="<< shm->name << " failed, ret=" << ret; return SHM_ERR; } - shm->addr = NULL; + shm->addr = nullptr; LOG(INFO) << "Ubs free shm=" << shm->name << " length=" << shm->len << " success."; return UBRING_OK; } @@ -222,7 +222,7 @@ RETURN_CODE UbsShmFree(SHM *shm) RETURN_CODE UbsShmLocalFree(SHM *shm) { // unmap - if (shm->addr == NULL) { + if (shm->addr == nullptr) { LOG(ERROR) << "Ubs input shm param is invalid, addr is NULL."; return SHM_ERR_INPUT_INVALID; } @@ -247,14 +247,14 @@ RETURN_CODE UbsShmLocalFree(SHM *shm) LOG(ERROR) << "Ubs delete shm=" << shm->name << " failed, ret=" << ret; return SHM_ERR; } - shm->addr = NULL; + shm->addr = nullptr; LOG(INFO) << "Ubs free local shm=" << shm->name << " length=" << shm->len << " success."; return UBRING_OK; } RETURN_CODE UbsShmRemoteMalloc(SHM *shm) { - int ret = ubsmem_shmem_map(NULL, shm->len, PROT_READ | PROT_WRITE, MAP_SHARED, shm->name, 0, (void**)&(shm->addr)); + int ret = ubsmem_shmem_map(nullptr, shm->len, PROT_READ | PROT_WRITE, MAP_SHARED, shm->name, 0, (void**)&(shm->addr)); if (ret != UBSM_OK) { LOG(ERROR) << "Ubs map Shm=" << shm->name << " failed, ret=" << ret; return SHM_ERR; @@ -266,7 +266,7 @@ RETURN_CODE UbsShmRemoteMalloc(SHM *shm) RETURN_CODE UbsShmLocalMmap(SHM *shm, int prot) { - int ret = ubsmem_shmem_map(NULL, shm->len, prot, MAP_SHARED, shm->name, 0, (void**)&(shm->addr)); + int ret = ubsmem_shmem_map(nullptr, shm->len, prot, MAP_SHARED, shm->name, 0, (void**)&(shm->addr)); if (ret != UBSM_OK) { LOG(ERROR) << "Ubs map Shm=" << shm->name << " failed, ret=" << ret; return SHM_ERR; @@ -279,7 +279,7 @@ RETURN_CODE UbsShmLocalMmap(SHM *shm, int prot) RETURN_CODE UbsShmRemoteFree(SHM *shm) { // unmap - if (shm->addr == NULL) { + if (shm->addr == nullptr) { LOG(ERROR) << "Ubs input shm param is invalid, addr is NULL."; return SHM_ERR_INPUT_INVALID; } @@ -393,16 +393,16 @@ RETURN_CODE UbsShmFini(void) static void DeleteShmToList(ShmList* shm_list) { - if (shm_list == NULL || shm_list->head == NULL) { + if (shm_list == nullptr || shm_list->head == nullptr) { return; } ShmListNode *cur_node = shm_list->head; shm_list->head = cur_node->next; - if (shm_list->head != NULL) { - shm_list->head->prev = NULL; + if (shm_list->head != nullptr) { + shm_list->head->prev = nullptr; } else { - shm_list->tail = NULL; + shm_list->tail = nullptr; } LOG(INFO) << "Delete shm to list, name=" << cur_node->shm.name << " size=" << shm_list->size; FREE_PTR(cur_node); @@ -412,26 +412,26 @@ static void DeleteShmToList(ShmList* shm_list) void *UbsShmCallback(void* args) { ShmList *shm_list = (ShmList*)args; - if (UNLIKELY(shm_list == NULL)) { + if (UNLIKELY(shm_list == nullptr)) { LOG(ERROR) << "Shm list is null."; - return NULL; + return nullptr; } LOCK_GUARD(shm_list->shm_lock); - while (shm_list->head != NULL) { + while (shm_list->head != nullptr) { SHM shm = shm_list->head->shm; - if (shm.addr == NULL) { + if (shm.addr == nullptr) { LOG(ERROR) << "Ubs input shm param is invalid, addr is NULL."; - return NULL; + return nullptr; } int ret = ubsmem_shmem_unmap(shm.addr, shm.len); if (ret != UBSM_OK) { if (ret == UBSM_ERR_NET) { - return NULL; + return nullptr; } LOG(ERROR) << "Ubs unmap shm=" << shm.name << " length=" << shm.len << " failed, ret=" << ret; - return NULL; + return nullptr; } LOG(INFO) << "Ubs unmap shm=" << shm.name << " length=" << shm.len << " success."; @@ -439,13 +439,13 @@ void *UbsShmCallback(void* args) if (ret != UBSM_OK) { DeleteShmToList(shm_list); LOG(ERROR) << "Ubs delete shm=" << shm.name << " failed, ret=" << ret; - return NULL; + return nullptr; } DeleteShmToList(shm_list); LOG(INFO) << "Ubs free local shm=" << shm.name << " length=" << shm.len << " success."; } - return NULL; + return nullptr; } RETURN_CODE UbsShmAddTimer(ShmList *shm_list) @@ -468,15 +468,15 @@ RETURN_CODE UbsShmAddTimer(ShmList *shm_list) RETURN_CODE InitShmTimer(ShmList **shm_list) { *shm_list = (ShmList *)malloc(sizeof(ShmList)); - if (*shm_list == NULL) { + if (*shm_list == nullptr) { LOG(ERROR) << "Malloc shm list failed."; return UBRING_ERR; } - (*shm_list)->head = NULL; - (*shm_list)->tail = NULL; + (*shm_list)->head = nullptr; + (*shm_list)->tail = nullptr; (*shm_list)->size = 0; - if (pthread_mutex_init(&(*shm_list)->shm_lock, NULL) != 0) { + if (pthread_mutex_init(&(*shm_list)->shm_lock, nullptr) != 0) { LOG(ERROR) << "Init shm list mutex failed."; FREE_PTR(*shm_list); return UBRING_ERR; @@ -493,14 +493,14 @@ RETURN_CODE InitShmTimer(ShmList **shm_list) RETURN_CODE DestroyShmTimer(ShmList *shm_list) { DeleteTimerSafe((uint32_t)g_shm_timer_fd); - if (shm_list == NULL) { + if (shm_list == nullptr) { LOG(WARNING) << "Shm list is null."; return UBRING_ERR; } ShmListNode* current = shm_list->head; ShmListNode* next; - while (current != NULL) { + while (current != nullptr) { next = current->next; free(current); current = next; @@ -512,14 +512,14 @@ RETURN_CODE DestroyShmTimer(ShmList *shm_list) RETURN_CODE IsExistInShmList(ShmList *shm_list, const SHM *shm) { - if (UNLIKELY(shm_list == NULL || shm == NULL)) { + if (UNLIKELY(shm_list == nullptr || shm == nullptr)) { LOG(ERROR) << "Shm list or shm is null."; return UBRING_ERR; } LOCK_GUARD(shm_list->shm_lock); ShmListNode *cur_node = shm_list->head; - while (cur_node != NULL) { + while (cur_node != nullptr) { if (strcmp(cur_node->shm.name, shm->name) == 0 && cur_node->shm.len == shm->len) { return UBRING_OK; } @@ -530,7 +530,7 @@ RETURN_CODE IsExistInShmList(ShmList *shm_list, const SHM *shm) RETURN_CODE AddShmToList(ShmList *shm_list, SHM *shm) { - if (shm_list == NULL || shm == NULL) { + if (shm_list == nullptr || shm == nullptr) { LOG(ERROR) << "Shm list or shm is null."; return UBRING_ERR; } @@ -541,14 +541,14 @@ RETURN_CODE AddShmToList(ShmList *shm_list, SHM *shm) } ShmListNode *new_shm_node = (ShmListNode *)malloc(sizeof(ShmListNode)); - if (new_shm_node == NULL) { + if (new_shm_node == nullptr) { LOG(ERROR) << "Malloc shm node failed."; return UBRING_ERR; } memcpy(&new_shm_node->shm, shm, sizeof(SHM)); LOCK_GUARD(shm_list->shm_lock); - new_shm_node->next = NULL; + new_shm_node->next = nullptr; new_shm_node->prev = shm_list->tail; if (shm_list->tail) { shm_list->tail->next = new_shm_node; diff --git a/src/brpc/ubshm/timer/timer_mgr.cpp b/src/brpc/ubshm/timer/timer_mgr.cpp index b563e7f6ab..b5e0c9ef3b 100644 --- a/src/brpc/ubshm/timer/timer_mgr.cpp +++ b/src/brpc/ubshm/timer/timer_mgr.cpp @@ -31,7 +31,7 @@ namespace ubring { int32_t g_epoll_fd = -1; std::atomic g_total_timer_num(0); -TimerFdCtx *g_timer_fd_ctx_map = NULL; +TimerFdCtx *g_timer_fd_ctx_map = nullptr; uint32_t g_max_system_fd = 0; static pthread_t g_epoll_execute_thread = 0; static int32_t g_timer_module_initialized = 0; @@ -44,7 +44,7 @@ static int timerfd_settime_macosx(int fd, int flags, #endif static RETURN_CODE DeleteTimerInner(uint32_t fd) { - if (g_timer_fd_ctx_map == NULL) { + if (g_timer_fd_ctx_map == nullptr) { return UBRING_OK; } @@ -58,19 +58,19 @@ static RETURN_CODE DeleteTimerInner(uint32_t fd) { } g_timer_fd_ctx_map[fd].status = TIMER_CONTEXT_NOT_USING; - g_timer_fd_ctx_map[fd].cb = NULL; - g_timer_fd_ctx_map[fd].args = NULL; + g_timer_fd_ctx_map[fd].cb = nullptr; + g_timer_fd_ctx_map[fd].args = nullptr; g_timer_fd_ctx_map[fd].periodical = 0; g_timer_fd_ctx_map[fd].fd = 0; pthread_spin_unlock(&g_timer_fd_ctx_map[fd].spin_lock); #if defined(OS_LINUX) - epoll_ctl(g_epoll_fd, EPOLL_CTL_DEL, (int)fd, NULL); + epoll_ctl(g_epoll_fd, EPOLL_CTL_DEL, (int)fd, nullptr); #elif defined(OS_MACOSX) struct kevent evt; - EV_SET(&evt, fd, EVFILT_TIMER, EV_DELETE, 0, 0, NULL); - kevent(g_epoll_fd, &evt, 1, NULL, 0, NULL); + EV_SET(&evt, fd, EVFILT_TIMER, EV_DELETE, 0, 0, nullptr); + kevent(g_epoll_fd, &evt, 1, nullptr, 0, nullptr); #endif uint64_t exp = 0; @@ -92,7 +92,7 @@ static RETURN_CODE StartTimeEpoll(void) { return UBRING_ERR; } - int ret = pthread_create(&g_epoll_execute_thread, NULL, TimerEpoll, NULL); + int ret = pthread_create(&g_epoll_execute_thread, nullptr, TimerEpoll, nullptr); if (UNLIKELY(ret != 0)) { LOG(ERROR) << "Failed to create thread err=" << ret; return UBRING_ERR; @@ -101,7 +101,7 @@ static RETURN_CODE StartTimeEpoll(void) { } static RETURN_CODE TimerSpinLocksInit(void) { - if (g_timer_fd_ctx_map == NULL) { + if (g_timer_fd_ctx_map == nullptr) { LOG(ERROR) << "Timer module is not fully initialized."; return UBRING_ERR; } @@ -150,7 +150,7 @@ RETURN_CODE TimerInit(void) { } g_max_system_fd = (uint32_t)rlim.rlim_cur; - if (g_timer_fd_ctx_map == NULL) { + if (g_timer_fd_ctx_map == nullptr) { g_timer_fd_ctx_map = (TimerFdCtx *)malloc(sizeof(TimerFdCtx) * g_max_system_fd); if (UNLIKELY(!g_timer_fd_ctx_map)) { LOG(ERROR) << "Fail to malloc space for timer modules. errno=%d", errno; @@ -161,7 +161,7 @@ RETURN_CODE TimerInit(void) { if (ret != UBRING_OK) { LOG(ERROR) << "Failed to init main data structure of Time Module. ret=" << ret; free(g_timer_fd_ctx_map); - g_timer_fd_ctx_map = NULL; + g_timer_fd_ctx_map = nullptr; return UBRING_ERR; } } @@ -169,7 +169,7 @@ RETURN_CODE TimerInit(void) { RETURN_CODE ret = StartTimeEpoll(); if (ret != UBRING_OK) { LOG(ERROR) << "Failed to start Timer Epoll. ret=" << ret; - if (LIKELY(g_timer_fd_ctx_map != NULL)) { + if (LIKELY(g_timer_fd_ctx_map != nullptr)) { FREE_PTR(g_timer_fd_ctx_map); } return UBRING_ERR; @@ -181,12 +181,12 @@ RETURN_CODE TimerInit(void) { void *UnifiedCallback(void *args) { TimerFdCtx *ctx = (TimerFdCtx *)args; if (pthread_spin_lock(&ctx->spin_lock) != 0) { - return NULL; + return nullptr; } if (ctx->status == TIMER_CONTEXT_NOT_USING) { pthread_spin_unlock(&ctx->spin_lock); - return NULL; + return nullptr; } void *(*cb)(void *) = ctx->cb; @@ -202,7 +202,7 @@ void *UnifiedCallback(void *args) { if (!is_periodical) { DeleteTimerInner(fd); } - return NULL; + return nullptr; } void *TimerEpoll(void *args) { @@ -224,7 +224,7 @@ void *TimerEpoll(void *args) { TIMER_EPOLL_WAIT_TIMEOUT); #elif defined(OS_MACOSX) struct timespec timeout = {0, TIMER_EPOLL_WAIT_TIMEOUT * 1000000}; - int32_t ready_num = kevent(g_epoll_fd, NULL, 0, ready_events, MAX_TIMER, &timeout); + int32_t ready_num = kevent(g_epoll_fd, nullptr, 0, ready_events, MAX_TIMER, &timeout); #endif if (UNLIKELY(ready_num == -1)) { @@ -268,11 +268,11 @@ void *TimerEpoll(void *args) { } } } - return NULL; + return nullptr; } void DeleteTimerSafe(uint32_t fd) { - if (g_timer_fd_ctx_map == NULL) { + if (g_timer_fd_ctx_map == nullptr) { return; } @@ -286,19 +286,19 @@ void DeleteTimerSafe(uint32_t fd) { } g_timer_fd_ctx_map[fd].status = TIMER_CONTEXT_NOT_USING; - g_timer_fd_ctx_map[fd].cb = NULL; - g_timer_fd_ctx_map[fd].args = NULL; + g_timer_fd_ctx_map[fd].cb = nullptr; + g_timer_fd_ctx_map[fd].args = nullptr; g_timer_fd_ctx_map[fd].periodical = 0; g_timer_fd_ctx_map[fd].fd = 0; pthread_spin_unlock(&g_timer_fd_ctx_map[fd].spin_lock); #if defined(OS_LINUX) - epoll_ctl(g_epoll_fd, EPOLL_CTL_DEL, (int)fd, NULL); + epoll_ctl(g_epoll_fd, EPOLL_CTL_DEL, (int)fd, nullptr); #elif defined(OS_MACOSX) struct kevent evt; - EV_SET(&evt, fd, EVFILT_TIMER, EV_DELETE, 0, 0, NULL); - kevent(g_epoll_fd, &evt, 1, NULL, 0, NULL); + EV_SET(&evt, fd, EVFILT_TIMER, EV_DELETE, 0, 0, nullptr); + kevent(g_epoll_fd, &evt, 1, nullptr, 0, nullptr); #endif uint64_t exp = 0; @@ -309,7 +309,7 @@ void DeleteTimerSafe(uint32_t fd) { } void DeleteTimer(uint32_t fd) { - if (g_timer_fd_ctx_map == NULL) { + if (g_timer_fd_ctx_map == nullptr) { LOG(WARNING) << "The timer is not initialized."; return; } @@ -355,8 +355,8 @@ int32_t TimerStart(const itimerspec *time, void *(*cb)(void *), void *args) { uint64_t timeout_nsec = time->it_value.tv_sec * 1000000000ULL + time->it_value.tv_nsec; uint64_t interval_nsec = time->it_interval.tv_sec * 1000000000ULL + time->it_interval.tv_nsec; EV_SET(&event, timer_fd, EVFILT_TIMER, EV_ADD | EV_ENABLE, 0, - timeout_nsec / 1000000, NULL); - int32_t ret = kevent(g_epoll_fd, &event, 1, NULL, 0, NULL); + timeout_nsec / 1000000, nullptr); + int32_t ret = kevent(g_epoll_fd, &event, 1, nullptr, 0, nullptr); #endif if (UNLIKELY(ret != 0)) { @@ -368,18 +368,18 @@ int32_t TimerStart(const itimerspec *time, void *(*cb)(void *), void *args) { std::atomic_fetch_add(&g_total_timer_num, 1U); #if defined(OS_LINUX) - ret = timerfd_settime(timer_fd, 0, time, NULL); + ret = timerfd_settime(timer_fd, 0, time, nullptr); #elif defined(OS_MACOSX) - ret = timerfd_settime_macosx(timer_fd, 0, time, NULL); + ret = timerfd_settime_macosx(timer_fd, 0, time, nullptr); #endif if (UNLIKELY(ret != 0)) { #if defined(OS_LINUX) - if (epoll_ctl(g_epoll_fd, EPOLL_CTL_DEL, timer_fd, NULL) != 0) { + if (epoll_ctl(g_epoll_fd, EPOLL_CTL_DEL, timer_fd, nullptr) != 0) { #elif defined(OS_MACOSX) struct kevent evt; - EV_SET(&evt, timer_fd, EVFILT_TIMER, EV_DELETE, 0, 0, NULL); - if (kevent(g_epoll_fd, &evt, 1, NULL, 0, NULL) != 0) { + EV_SET(&evt, timer_fd, EVFILT_TIMER, EV_DELETE, 0, 0, nullptr); + if (kevent(g_epoll_fd, &evt, 1, nullptr, 0, nullptr) != 0) { #endif LOG(ERROR) << "Failed to delete the timer fd=" << timer_fd << " with errno=" << errno; } @@ -397,8 +397,8 @@ uint32_t GetActiveTimerNum(void) { } void CloseTimerFd(int fd) { - g_timer_fd_ctx_map[fd].cb = NULL; - g_timer_fd_ctx_map[fd].args = NULL; + g_timer_fd_ctx_map[fd].cb = nullptr; + g_timer_fd_ctx_map[fd].args = nullptr; g_timer_fd_ctx_map[fd].status = TIMER_CONTEXT_NOT_USING; g_timer_fd_ctx_map[fd].fd = 0; g_timer_fd_ctx_map[fd].periodical = 0; @@ -421,7 +421,7 @@ void TimerModuleDestroy(void) { g_epoll_fd = -1; g_total_timer_num = 0; g_timer_module_initialized = 0; - int32_t ret = pthread_join(g_epoll_execute_thread, NULL); + int32_t ret = pthread_join(g_epoll_execute_thread, nullptr); if (ret != EOK) { LOG(ERROR) << "Failed to join pthread, during destroying timer module. ret=" << ret; return; @@ -437,7 +437,7 @@ RETURN_CODE TimerFdCtxValidate(uint32_t fd) { LOG(ERROR) << "TimerFd=" << fd << " has wrong status=" << g_timer_fd_ctx_map[fd].status; return UBRING_ERR; } - if (g_timer_fd_ctx_map[fd].cb == NULL) { + if (g_timer_fd_ctx_map[fd].cb == nullptr) { LOG(ERROR) << "The callback is not set."; return UBRING_ERR; } @@ -457,7 +457,7 @@ static int timerfd_create_macosx(int clockid, int flags) { static int timerfd_settime_macosx(int fd, int flags, const itimerspec *new_value, itimerspec *old_value) { - if (old_value != NULL) { + if (old_value != nullptr) { memset(old_value, 0, sizeof(itimerspec)); } return 0; diff --git a/src/brpc/ubshm/ub_endpoint.cpp b/src/brpc/ubshm/ub_endpoint.cpp index ea965a45b3..45794fdc6e 100644 --- a/src/brpc/ubshm/ub_endpoint.cpp +++ b/src/brpc/ubshm/ub_endpoint.cpp @@ -66,7 +66,7 @@ static uint16_t g_ub_impl_version = 1; static const uint32_t ACK_MSG_UB_OK = 0x1; -static butil::Mutex* g_ubring_resource_mutex = NULL; +static butil::Mutex* g_ubring_resource_mutex = nullptr; void HelloMessage::Serialize(void* data) const { char* current_pos = static_cast(data); @@ -149,7 +149,7 @@ void UBConnect::StartConnect(const Socket* socket, void (*done)(int err, void* data), void* data) { auto* ub_transport = static_cast(socket->_transport.get()); - CHECK(ub_transport->_ub_ep != NULL); + CHECK(ub_transport->_ub_ep != nullptr); SocketUniquePtr s; if (Socket::Address(socket->id(), &s) != 0) { return; @@ -211,7 +211,7 @@ static void TryReadOnTcpDuringRdmaEst(Socket* s) { void UBShmEndpoint::OnNewDataFromTcp(Socket* m) { auto* ub_transport = static_cast(m->_transport.get()); UBShmEndpoint* ep = ub_transport->GetUBShmEp(); - CHECK(ep != NULL); + CHECK(ep != nullptr); int progress = Socket::PROGRESS_INIT; while (true) { @@ -267,7 +267,7 @@ bool HelloNegotiationValid(HelloMessage& msg) { static const int WAIT_TIMEOUT_MS = 50; int UBShmEndpoint::ReadFromFd(void* data, size_t len) { - CHECK(data != NULL); + CHECK(data != nullptr); int nr = 0; size_t received = 0; do { @@ -295,7 +295,7 @@ int UBShmEndpoint::ReadFromFd(void* data, size_t len) { } int UBShmEndpoint::WriteToFd(void* data, size_t len) { - CHECK(data != NULL); + CHECK(data != nullptr); int nw = 0; size_t written = 0; do { @@ -341,14 +341,14 @@ void* UBShmEndpoint::ProcessHandshakeAtClient(void* arg) { ep->_state = C_ALLOC_SHM; auto* ub_transport = static_cast(s->_transport.get()); size_t local_shm_len = (size_t)(FLAGS_data_queue_size) * MB_TO_BYTE; - SHM local_trx_shm = {NULL, local_shm_len, 0, {0}, (uint32_t)s->fd()}; + SHM local_trx_shm = {nullptr, local_shm_len, 0, {0}, (uint32_t)s->fd()}; auto shm_name_str = butil::endpoint2str(s->local_side()); const char* shm_name = shm_name_str.c_str(); if (ep->AllocateClientResources(&local_trx_shm, shm_name) < 0) { LOG(WARNING) << "Fallback to tcp:" << s->description(); ub_transport->_ub_state = UBShmTransport::UB_OFF; ep->_state = FALLBACK_TCP; - return NULL; + return nullptr; } ep->_state = C_HELLO_SEND; @@ -366,7 +366,7 @@ void* UBShmEndpoint::ProcessHandshakeAtClient(void* arg) { s->SetFailed(saved_errno, "Fail to complete ubring handshake from %s: %s", s->description().c_str(), berror(saved_errno)); ep->_state = FAILED; - return NULL; + return nullptr; } LOG_IF(INFO, FLAGS_ub_trace_verbose) << "client handshake message : " << local_msg.toString(); @@ -377,14 +377,14 @@ void* UBShmEndpoint::ProcessHandshakeAtClient(void* arg) { s->SetFailed(saved_errno, "Fail to complete ubring handshake from %s: %s", s->description().c_str(), berror(saved_errno)); ep->_state = FAILED; - return NULL; + return nullptr; } if (memcmp(data, MAGIC_STR, MAGIC_STR_LEN) != 0) { LOG(WARNING) << "Read unexpected data during handshake:" << s->description(); s->SetFailed(EPROTO, "Fail to complete ubring handshake from %s: %s", s->description().c_str(), berror(EPROTO)); ep->_state = FAILED; - return NULL; + return nullptr; } if (ep->ReadFromFd(data, HELLO_MSG_LEN_MIN - MAGIC_STR_LEN) < 0) { @@ -393,7 +393,7 @@ void* UBShmEndpoint::ProcessHandshakeAtClient(void* arg) { s->SetFailed(saved_errno, "Fail to complete ubring handshake from %s: %s", s->description().c_str(), berror(saved_errno)); ep->_state = FAILED; - return NULL; + return nullptr; } HelloMessage remote_msg; remote_msg.Deserialize(data); @@ -403,7 +403,7 @@ void* UBShmEndpoint::ProcessHandshakeAtClient(void* arg) { s->SetFailed(EPROTO, "Fail to complete ubring handshake from %s: %s", s->description().c_str(), berror(EPROTO)); ep->_state = FAILED; - return NULL; + return nullptr; } if (remote_msg.msg_len > HELLO_MSG_LEN_MIN) { @@ -438,7 +438,7 @@ void* UBShmEndpoint::ProcessHandshakeAtClient(void* arg) { s->SetFailed(saved_errno, "Fail to complete ubring handshake from %s: %s", s->description().c_str(), berror(saved_errno)); ep->_state = FAILED; - return NULL; + return nullptr; } if (ub_transport->_ub_state == UBShmTransport::UB_ON) { @@ -454,7 +454,7 @@ void* UBShmEndpoint::ProcessHandshakeAtClient(void* arg) { errno = 0; - return NULL; + return nullptr; } void* UBShmEndpoint::ProcessHandshakeAtServer(void* arg) { @@ -473,7 +473,7 @@ void* UBShmEndpoint::ProcessHandshakeAtServer(void* arg) { s->SetFailed(saved_errno, "Fail to complete ubring handshake from %s: %s", s->description().c_str(), berror(saved_errno)); ep->_state = FAILED; - return NULL; + return nullptr; } auto* ub_transport = static_cast(s->_transport.get()); if (memcmp(data, MAGIC_STR, MAGIC_STR_LEN) != 0) { @@ -484,7 +484,7 @@ void* UBShmEndpoint::ProcessHandshakeAtServer(void* arg) { ep->_state = FALLBACK_TCP; ub_transport->_ub_state = UBShmTransport::UB_OFF; ep->TryReadOnTcp(); - return NULL; + return nullptr; } if (ep->ReadFromFd(data, g_ub_hello_msg_len - MAGIC_STR_LEN) < 0) { @@ -493,7 +493,7 @@ void* UBShmEndpoint::ProcessHandshakeAtServer(void* arg) { s->SetFailed(saved_errno, "Fail to complete ubring handshake from %s: %s", s->description().c_str(), berror(saved_errno)); ep->_state = FAILED; - return NULL; + return nullptr; } HelloMessage remote_msg; @@ -505,7 +505,7 @@ void* UBShmEndpoint::ProcessHandshakeAtServer(void* arg) { s->SetFailed(EPROTO, "Fail to complete ubring handshake from %s: %s", s->description().c_str(), berror(EPROTO)); ep->_state = FAILED; - return NULL; + return nullptr; } if (remote_msg.msg_len > HELLO_MSG_LEN_MIN) { // TODO: Read Hello Message customized header @@ -518,17 +518,17 @@ void* UBShmEndpoint::ProcessHandshakeAtServer(void* arg) { ub_transport->_ub_state = UBShmTransport::UB_OFF; } else { ep->_state = S_ALLOC_SHM; - ubring::SHM remote_trx_shm = {NULL, remote_msg.len, 0, {0}, (uint32_t)ep->_socket->fd()}; + ubring::SHM remote_trx_shm = {nullptr, remote_msg.len, 0, {0}, (uint32_t)ep->_socket->fd()}; strncpy(remote_trx_shm.name, remote_msg.shm_name, SHM_MAX_NAME_BUFF_LEN); size_t local_shm_len = (size_t)(FLAGS_data_queue_size) * MB_TO_BYTE; // server-side shared memory name - ubring::SHM local_trx_shm = {NULL, local_shm_len, 0, {0}, (uint32_t)ep->_socket->fd()}; + ubring::SHM local_trx_shm = {nullptr, local_shm_len, 0, {0}, (uint32_t)ep->_socket->fd()}; char client_name[SHM_MAX_NAME_BUFF_LEN]; strncpy(client_name, remote_msg.shm_name, SHM_MAX_NAME_BUFF_LEN); char *client_ip_port = strrchr(client_name, '_'); - if (client_ip_port != NULL) { + if (client_ip_port != nullptr) { *client_ip_port = '\0'; } int result = snprintf(local_trx_shm.name, SHM_MAX_NAME_BUFF_LEN, "%s_%s", @@ -564,7 +564,7 @@ void* UBShmEndpoint::ProcessHandshakeAtServer(void* arg) { s->SetFailed(saved_errno, "Fail to complete ub handshake from %s: %s", s->description().c_str(), berror(saved_errno)); ep->_state = FAILED; - return NULL; + return nullptr; } ep->_state = S_ACK_WAIT; @@ -574,7 +574,7 @@ void* UBShmEndpoint::ProcessHandshakeAtServer(void* arg) { s->SetFailed(saved_errno, "Fail to complete ubring handshake from %s: %s", s->description().c_str(), berror(saved_errno)); ep->_state = FAILED; - return NULL; + return nullptr; } uint32_t* tmp = (uint32_t*)data; @@ -586,7 +586,7 @@ void* UBShmEndpoint::ProcessHandshakeAtServer(void* arg) { s->SetFailed(EPROTO, "Fail to complete ub handshake from %s: %s", s->description().c_str(), berror(EPROTO)); ep->_state = FAILED; - return NULL; + return nullptr; } else { ub_transport->_ub_state = UBShmTransport::UB_ON; ep->_state = ESTABLISHED; @@ -602,7 +602,7 @@ void* UBShmEndpoint::ProcessHandshakeAtServer(void* arg) { } ep->TryReadOnTcp(); - return NULL; + return nullptr; } bool UBShmEndpoint::IsWritable() const { @@ -671,7 +671,7 @@ int UBShmEndpoint::AllocateClientResources(ubring::SHM* local_trx_shm, const cha return 0; } - CHECK(_ub_ring == NULL); + CHECK(_ub_ring == nullptr); // TODO: Pooling management _ub_ring = new UBRing(); @@ -696,7 +696,7 @@ int UBShmEndpoint::AllocateServerResources(ubring::SHM* remote_trx_shm, ubring:: return 0; } - CHECK(_ub_ring == NULL); + CHECK(_ub_ring == nullptr); // TODO: Pooling management _ub_ring = new UBRing(); @@ -725,7 +725,7 @@ void UBShmEndpoint::DeallocateResources() { if (INVALID_SOCKET_ID != _cq_sid) { SocketUniquePtr s; if (Socket::Address(_cq_sid, &s) == 0) { - s->_user = NULL; + s->_user = nullptr; s->_fd = -1; s->SetFailed(); } @@ -914,7 +914,7 @@ void UBShmEndpoint::PollingModeRelease(bthread_tag_t tag) { auto& running = group.running; running.store(false, std::memory_order_relaxed); for (int i = 0; i < FLAGS_ub_poller_num; ++i) { - bthread_join(pollers[i].tid, NULL); + bthread_join(pollers[i].tid, nullptr); } } diff --git a/src/brpc/ubshm/ub_endpoint.h b/src/brpc/ubshm/ub_endpoint.h index bf9e61c5d7..03c5134522 100644 --- a/src/brpc/ubshm/ub_endpoint.h +++ b/src/brpc/ubshm/ub_endpoint.h @@ -68,8 +68,8 @@ class UBConnect : public AppConnect { private: void Run(); - void (*_done)(int, void*){NULL}; - void* _data{NULL}; + void (*_done)(int, void*){nullptr}; + void* _data{nullptr}; }; class BAIDU_CACHELINE_ALIGNMENT UBShmEndpoint : public SocketUser { diff --git a/src/brpc/ubshm/ub_helper.cpp b/src/brpc/ubshm/ub_helper.cpp index b88e656adc..230ca71bac 100644 --- a/src/brpc/ubshm/ub_helper.cpp +++ b/src/brpc/ubshm/ub_helper.cpp @@ -31,7 +31,7 @@ namespace brpc { namespace ubring { -void* g_handle_ub = NULL; +void* g_handle_ub = nullptr; bool g_skip_ub_init = false; butil::atomic g_ub_available(false); diff --git a/src/brpc/ubshm/ub_ring.cpp b/src/brpc/ubshm/ub_ring.cpp index 7008314437..72df015409 100644 --- a/src/brpc/ubshm/ub_ring.cpp +++ b/src/brpc/ubshm/ub_ring.cpp @@ -122,7 +122,7 @@ RETURN_CODE UBRing::UbrTrxClose() { } RETURN_CODE UBRing::UbrAddCloseTimer() { - if (UNLIKELY(_trx == NULL)) { + if (UNLIKELY(_trx == nullptr)) { LOG(ERROR) << "Trx add close timer failed, trx is null."; return UBRING_ERR; } @@ -196,7 +196,7 @@ void* UBRing::UbrTrxCloseCallback(void* args) { } RETURN_CODE UBRing::UbrAddHBTimer() { - if (UNLIKELY(_trx == NULL)) { + if (UNLIKELY(_trx == nullptr)) { LOG(ERROR) << "Trx add heartbeat timer failed, trx is null."; return UBRING_ERR; } @@ -227,7 +227,7 @@ RETURN_CODE UBRing::UbrPassiveClearTrx(UbrTrx *trx, int fd, PASSIVE_DISC_TYPE ty trx->ubr_tx.trx_state = UBR_STATE_CLOSED; trx->ubr_rx.trx_state = UBR_STATE_CLOSED; DeleteTimerSafe((uint32_t)trx->timer_fd); - const char *type_name = NULL; + const char *type_name = nullptr; if (type == UBR_HEARTBEAT) { DeleteTimer((uint32_t)trx->hb_timer_fd); type_name = "Trx heartbeat"; @@ -253,42 +253,42 @@ RETURN_CODE UBRing::UbrPassiveClearTrx(UbrTrx *trx, int fd, PASSIVE_DISC_TYPE ty void* UBRing::UbrTrxHBCallback(void* args) { auto* trx = (UbrTrx*) args; if (UNLIKELY(UbrTrxCallbackCheck(trx) != UBRING_OK)) { - return NULL; + return nullptr; } auto* local_data_status = (UbrDataStatusQMsg *)trx->ubr_tx.local_data_status_q.addr; auto* remote_data_status = (UbrDataStatusQMsg *)trx->ubr_rx.remote_data_status_q.addr; - if (UNLIKELY(local_data_status == NULL || remote_data_status == NULL)) { + if (UNLIKELY(local_data_status == nullptr || remote_data_status == nullptr)) { LOG(ERROR) << "Heartbeat error, datastatus is NULL."; - return NULL; + return nullptr; } if (trx->ubr_tx.trx_state != UBR_STATE_CONNECTED || trx->ubr_rx.trx_state != UBR_STATE_CONNECTED) { LOG_EVERY_SECOND(INFO) << "Heartbeat cannot be started, wait connected state."; - return NULL; + return nullptr; } remote_data_status->heart_beat = 1; if (local_data_status->heart_beat == 1) { local_data_status->heart_beat = 0; trx->ubr_tx.hb_retry_cnt = 0; - return NULL; + return nullptr; } ++trx->ubr_tx.hb_retry_cnt; if (trx->ubr_tx.hb_retry_cnt <= FLAGS_ub_hb_retry_cnt) { - return NULL; + return nullptr; } int fd = (int)trx->local_shm.fd; LOG(INFO) << "Hlc heartbeat, start to clear trx resource. hb_timer_fd=" << fd << ", shm_name=" << trx->local_shm.name; UbrPassiveClearTrx(trx, fd, UBR_HEARTBEAT); LOG(INFO) << "Hlc heartbeat clear trx resource finish."; - return NULL; + return nullptr; } RETURN_CODE UBRing::UbrAddAsynClearTimer(UbrTrx *trx) { - if (UNLIKELY(trx == NULL)) { + if (UNLIKELY(trx == nullptr)) { LOG(ERROR) << "Trx add close timer failed, trx is null."; return UBRING_ERR; } @@ -314,9 +314,9 @@ RETURN_CODE UBRing::UbrAddAsynClearTimer(UbrTrx *trx) { void *UBRing::UbrAsynClearCallback(void *args) { auto* trx = (UbrTrx*) args; - if (UNLIKELY(trx == NULL)) { + if (UNLIKELY(trx == nullptr)) { LOG(ERROR) << "Trx close, trx is null."; - return NULL; + return nullptr; } if (UNLIKELY(UbrTrxFreeShm(trx) != UBRING_OK)) { @@ -326,7 +326,7 @@ void *UBRing::UbrAsynClearCallback(void *args) if (UNLIKELY(UBRingManager::ReleaseUbrTrxFromMgr(trx) != UBRING_OK)) { LOG(ERROR) << "Trx close, release shm " << trx->local_shm.name << " trx failed."; } - return NULL; + return nullptr; } int UBRing::UbrTrxSend(const void *buf, uint32_t buf_len) @@ -539,11 +539,11 @@ ssize_t UBRing::UbrTrxReadvBlockMode(const struct iovec *iov, int iovcnt) RETURN_CODE UBRing::IsUbrTrxReadable(uint32_t ep_event) { - if (UNLIKELY(_trx == NULL)) { + if (UNLIKELY(_trx == nullptr)) { LOG(ERROR) << "The trx to be checked is NULL."; return UBRING_ERR; } - if (UNLIKELY(_trx->local_shm.addr == NULL)) { + if (UNLIKELY(_trx->local_shm.addr == nullptr)) { LOG(ERROR) << "The trx local_shm to be checked is NULL."; return UBRING_ERR; } @@ -574,19 +574,19 @@ RETURN_CODE UBRing::IsUbrTrxReadable(uint32_t ep_event) RETURN_CODE UBRing::IsUbrTrxWriteable(uint32_t ep_event) { - if (UNLIKELY(_trx == NULL)) { + if (UNLIKELY(_trx == nullptr)) { LOG(ERROR) << "The trx to be checked is NULL."; return UBRING_ERR; } - if (UNLIKELY(_trx->local_shm.addr == NULL)) { + if (UNLIKELY(_trx->local_shm.addr == nullptr)) { LOG(ERROR) << "The trx local_shm to be checked is NULL."; return UBRING_ERR; } - if (UNLIKELY((UbrEventQMsg *)_trx->ubr_tx.local_tx_event_q.addr == NULL)) { + if (UNLIKELY((UbrEventQMsg *)_trx->ubr_tx.local_tx_event_q.addr == nullptr)) { LOG(ERROR) << "The trx local_tx_event_q addr is NULL."; return UBRING_ERR; } - if (UNLIKELY((UbrEventQMsg *)_trx->ubr_tx.local_data_status_q.addr == NULL)) { + if (UNLIKELY((UbrEventQMsg *)_trx->ubr_tx.local_data_status_q.addr == nullptr)) { LOG(ERROR) << "The trx local_data_status_q addr is NULL."; return UBRING_ERR; } @@ -628,7 +628,7 @@ RETURN_CODE UBRing::UbrSetTimeout(UbrTaskStep task_type, int timeout) RETURN_CODE UBRing::UbrTrxFreeShm(UbrTrx *trx) { - if (trx == NULL) { + if (trx == nullptr) { LOG(ERROR) << "Trx is NULL."; return UBRING_ERR; } @@ -650,7 +650,7 @@ RETURN_CODE UBRing::UbrTrxFreeShm(UbrTrx *trx) } RETURN_CODE remote_rc = UBRING_OK; - if (trx->remote_shm.addr != NULL) { + if (trx->remote_shm.addr != nullptr) { remote_rc = ShmRemoteFree(&trx->remote_shm); } if (remote_rc != UBRING_OK) { @@ -662,7 +662,7 @@ RETURN_CODE UBRing::UbrTrxFreeShm(UbrTrx *trx) RETURN_CODE UBRing::UbrUnlinkLocalShm() { - if (UNLIKELY(_trx == NULL)) { + if (UNLIKELY(_trx == nullptr)) { return UBRING_ERR; } RETURN_CODE rc = ShmFree(&_trx->local_shm); @@ -675,7 +675,7 @@ RETURN_CODE UBRing::UbrUnlinkLocalShm() void UBRing::PreWriteAddr(uint8_t *addr, size_t len) { - if (addr == NULL) { + if (addr == nullptr) { return; } @@ -699,7 +699,7 @@ void UBRing::PreWriteAddr(uint8_t *addr, size_t len) void UBRing::PrewriteUbrTx(UbrTx *tx) { - if (tx == NULL) { + if (tx == nullptr) { return; } PreWriteAddr(tx->remote_data_q.addr, tx->capacity * sizeof(UbrMsgFormat)); @@ -707,7 +707,7 @@ void UBRing::PrewriteUbrTx(UbrTx *tx) void UBRing::PrewriteUbrRx(UbrRx *rx) { - if (rx == NULL) { + if (rx == nullptr) { return; } PreWriteAddr(rx->local_data_q.addr, rx->capacity * sizeof(UbrMsgFormat)); @@ -715,11 +715,11 @@ void UBRing::PrewriteUbrRx(UbrRx *rx) RETURN_CODE UBRing::UbrTrxMapLocalShm(SHM *local_shm) { - if (UNLIKELY(_trx == NULL)) { + if (UNLIKELY(_trx == nullptr)) { LOG(ERROR) << "Trx map Shared memory failed, trx is null."; return UBRING_ERR; } - if (UNLIKELY(local_shm == NULL || local_shm->addr == NULL)) { + if (UNLIKELY(local_shm == nullptr || local_shm->addr == nullptr)) { LOG(ERROR) << "Trx map Shared memory failed, local_shm is null or addr is NULL."; return UBRING_ERR; } @@ -738,11 +738,11 @@ RETURN_CODE UBRing::UbrTrxMapLocalShm(SHM *local_shm) RETURN_CODE UBRing::UbrTrxMapRemoteShm(SHM *remote_shm) { - if (UNLIKELY(_trx == NULL)) { + if (UNLIKELY(_trx == nullptr)) { LOG(ERROR) << "Trx map Shared memory failed, trx is null."; return UBRING_ERR; } - if (UNLIKELY(remote_shm == NULL || remote_shm->addr == NULL)) { + if (UNLIKELY(remote_shm == nullptr || remote_shm->addr == nullptr)) { LOG(ERROR) << "Trx map Shared memory failed, remote_shm is null or addr is NULL."; return UBRING_ERR; } @@ -866,7 +866,7 @@ RETURN_CODE UBRing::UbrMapRemoteShmAddTimer(SHM *local_trx_shm, const char *loca size_t remote_server_len = UBR_MSG_LEN * (((UbrDataStatusQMsg *)(_trx->ubr_tx.local_data_status_q.addr))->tail + 1) + UBR_MSG_LEN * ((DATAQ_ADDR_OFFSET / UBR_MSG_LEN) + 1); - SHM remote_trx_shm = {NULL, remote_server_len, 0, {0}, local_trx_shm->fd}; + SHM remote_trx_shm = {nullptr, remote_server_len, 0, {0}, local_trx_shm->fd}; int result = snprintf(remote_trx_shm.name, SHM_MAX_NAME_BUFF_LEN, "%s_%s_%s", @@ -906,7 +906,7 @@ RETURN_CODE UBRing::UbrMapRemoteShmAddTimer(SHM *local_trx_shm, const char *loca RETURN_CODE UBRing::ApplyAndMapLocalShm(SHM *local_trx_shm, const char *local_name) { - if (UNLIKELY(_trx == NULL || local_trx_shm == NULL)) { + if (UNLIKELY(_trx == nullptr || local_trx_shm == nullptr)) { LOG(ERROR) << "Trx map Shared memory failed, trx is null, local_name=" << local_name; return UBRING_ERR; } @@ -988,7 +988,7 @@ RETURN_CODE UBRing::WritevHasEnoughSpace(size_t buf_len) RETURN_CODE UBRing::UbrClearResourceCheck(UbrTrx *trx, uint64_t start_time, UbrCloseType close_type) { - if (UNLIKELY(trx == NULL)) { + if (UNLIKELY(trx == nullptr)) { LOG(ERROR) << "Trx close failed, trx is null."; return UBRING_ERR; } @@ -1031,7 +1031,7 @@ RETURN_CODE UBRing::ClearTrxResource(UbrTrx *trx, uint64_t start_time, UbrCloseT RETURN_CODE UBRing::UbrTrxCloseCheck(UbrTrx *trx) { - if (UNLIKELY(trx == NULL)) { + if (UNLIKELY(trx == nullptr)) { LOG(ERROR) << "Trx close failed, client trx is null."; return UBRING_ERR; } diff --git a/src/brpc/ubshm/ub_ring.h b/src/brpc/ubshm/ub_ring.h index c08c90801a..f1a5cf14ff 100644 --- a/src/brpc/ubshm/ub_ring.h +++ b/src/brpc/ubshm/ub_ring.h @@ -96,11 +96,11 @@ class UBRing : public butil::IReader { static inline RETURN_CODE CheckTrxConnectParam(const char *listener_name, const char *local_name) { - if (UNLIKELY(listener_name == NULL)) { + if (UNLIKELY(listener_name == nullptr)) { LOG(ERROR) << "The request listener name is null."; return UBRING_ERR; } - if (UNLIKELY(local_name == NULL)) { + if (UNLIKELY(local_name == nullptr)) { LOG(ERROR) << "The request trx shared memory name is null."; return UBRING_ERR; } @@ -126,12 +126,12 @@ class UBRing : public butil::IReader { } static RETURN_CODE CheckTrxRecvParam(UbrTrx *trx, const void *buf, uint32_t buf_len) { - if (UNLIKELY(trx == NULL)) { + if (UNLIKELY(trx == nullptr)) { LOG(ERROR) << "Trx recv failed, trx is null."; return UBRING_ERR; } - if (UNLIKELY((UbrEventQMsg *)trx->ubr_rx.local_rx_event_q.addr == NULL)) { + if (UNLIKELY((UbrEventQMsg *)trx->ubr_rx.local_rx_event_q.addr == nullptr)) { LOG(ERROR) << "Trx send failed, local_tx_event_q addr is NULL."; return UBRING_ERR; } @@ -140,7 +140,7 @@ class UBRing : public butil::IReader { LOG(ERROR) << "Trx recv failed, trx is not connected statep=" << trx->ubr_rx.trx_state; return UBR_NOT_CONNECTED; } - if (UNLIKELY(buf == NULL)) { + if (UNLIKELY(buf == nullptr)) { LOG(ERROR) << "Trx recv failed, buf is null."; return UBRING_ERR; } @@ -167,19 +167,19 @@ class UBRing : public butil::IReader { static RETURN_CODE UbrTrxCallbackCheck(UbrTrx *trx) { - if (trx == NULL) { + if (trx == nullptr) { LOG(ERROR) << "Trx close callback failed, trx is null."; return UBRING_ERR; } - if (UNLIKELY(trx->local_shm.addr == NULL)) { + if (UNLIKELY(trx->local_shm.addr == nullptr)) { LOG(ERROR) << "Trx close failed, local_shm addr is NULL."; return UBRING_ERR; } - if (UNLIKELY(trx->ubr_rx.local_rx_event_q.addr == NULL)) { + if (UNLIKELY(trx->ubr_rx.local_rx_event_q.addr == nullptr)) { LOG(ERROR) << "Trx close failed, local_rx_event_q addr is NULL."; return UBRING_ERR; } - if (UNLIKELY(trx->ubr_tx.local_tx_event_q.addr == NULL)) { + if (UNLIKELY(trx->ubr_tx.local_tx_event_q.addr == nullptr)) { LOG(ERROR) << "Trx close failed, local_tx_event_q addr is NULL."; return UBRING_ERR; } diff --git a/src/brpc/ubshm/ub_ring_manager.cpp b/src/brpc/ubshm/ub_ring_manager.cpp index 6656e33726..64f2434eba 100644 --- a/src/brpc/ubshm/ub_ring_manager.cpp +++ b/src/brpc/ubshm/ub_ring_manager.cpp @@ -36,7 +36,7 @@ uint64_t g_ub_event_cnt = 0; uint64_t g_ubr_listener_num = 0; RETURN_CODE UBRingManager::GetUbrDealMsgMaxCnt(const uint32_t capacity, uint32_t *deal_msg_max_cnt) { - if (UNLIKELY(deal_msg_max_cnt == NULL)) { + if (UNLIKELY(deal_msg_max_cnt == nullptr)) { LOG(ERROR) << "Get update factor failed, deal_msg_max_cnt is null."; return UBRING_ERR; } @@ -52,8 +52,8 @@ RETURN_CODE UBRingManager::UbrMgrDefault() { g_ubr_mgr.trx_num = 0; g_ubr_mgr.trx_cap = FLAGS_ubr_max_managed_num; - g_ubr_mgr.trx_mgr_unit_status = NULL; - g_ubr_mgr.trx_mgr = NULL; + g_ubr_mgr.trx_mgr_unit_status = nullptr; + g_ubr_mgr.trx_mgr = nullptr; return UBRING_OK; } @@ -68,8 +68,8 @@ RETURN_CODE UBRingManager::UbrMgrInit() { g_ubr_mgr.trx_mgr = (UbrTrx *)malloc(trx_mgr_size); size_t trx_mgr_status_size = g_ubr_mgr.trx_cap * sizeof(UbrMgrUnitStatus); g_ubr_mgr.trx_mgr_unit_status = (UbrMgrUnitStatus *)malloc(trx_mgr_status_size); - if (UNLIKELY(g_ubr_mgr.trx_mgr == NULL || - g_ubr_mgr.trx_mgr_unit_status == NULL)) { + if (UNLIKELY(g_ubr_mgr.trx_mgr == nullptr || + g_ubr_mgr.trx_mgr_unit_status == nullptr)) { LOG(ERROR) << "Ubr manager memory allocation failed."; UbrMgrFini(); return UBRING_ERR; @@ -96,12 +96,12 @@ void UBRingManager::UbrMgrFini() { } RETURN_CODE UBRingManager::AcquireUbrTrxFromMgr(UbrTrx **trx) { - if (UNLIKELY(trx == NULL)) { + if (UNLIKELY(trx == nullptr)) { LOG(ERROR) << "Acquire trx failed, trx is null."; return UBRING_ERR; } - if (UNLIKELY(g_ubr_mgr.trx_mgr == NULL)) { + if (UNLIKELY(g_ubr_mgr.trx_mgr == nullptr)) { LOG(ERROR) << "Acquire trx failed, trx_mgr is null."; return UBRING_ERR; } @@ -131,17 +131,17 @@ RETURN_CODE UBRingManager::AcquireUbrTrxFromMgr(UbrTrx **trx) { } RETURN_CODE UBRingManager::ReleaseUbrTrxFromMgr(UbrTrx *trx) { - if (UNLIKELY(trx == NULL)) { + if (UNLIKELY(trx == nullptr)) { LOG(ERROR) << "Release trx failed, trx is null."; return UBRING_ERR; } - trx->local_shm.addr = NULL; - trx->ubr_tx.local_tx_event_q.addr = NULL; - trx->ubr_tx.local_data_status_q.addr = NULL; - trx->ubr_rx.local_rx_event_q.addr = NULL; - trx->ubr_rx.remote_data_status_q.addr = NULL; - if (UNLIKELY(g_ubr_mgr.trx_mgr == NULL)) { + trx->local_shm.addr = nullptr; + trx->ubr_tx.local_tx_event_q.addr = nullptr; + trx->ubr_tx.local_data_status_q.addr = nullptr; + trx->ubr_rx.local_rx_event_q.addr = nullptr; + trx->ubr_rx.remote_data_status_q.addr = nullptr; + if (UNLIKELY(g_ubr_mgr.trx_mgr == nullptr)) { LOG(ERROR) << "Release trx failed, trx_mgr is null."; return UBRING_ERR; } @@ -167,14 +167,14 @@ void UBRingManager::LinkInfoInit(void) { size_t link_info_mgr_size = FLAGS_ubr_max_managed_num * sizeof(UbrLinkInfo); g_link_info_mgr.all_link_info = (UbrLinkInfo*) malloc(link_info_mgr_size); - if (g_link_info_mgr.all_link_info == NULL) { + if (g_link_info_mgr.all_link_info == nullptr) { LOG(ERROR) << "all_link_info is NULL"; LinkInfoFini(); return; } g_link_info_mgr.link_mgr_unit_status = (UbrMgrUnitStatus*) malloc(link_info_mgr_size); - if (g_link_info_mgr.link_mgr_unit_status == NULL) { + if (g_link_info_mgr.link_mgr_unit_status == nullptr) { LinkInfoFini(); return; } @@ -184,7 +184,7 @@ void UBRingManager::LinkInfoInit(void) { } void UBRingManager::LinkInfoFini(void) { - if (g_link_info_mgr.link_mgr_unit_status == NULL || g_link_info_mgr.all_link_info == NULL) { + if (g_link_info_mgr.link_mgr_unit_status == nullptr || g_link_info_mgr.all_link_info == nullptr) { LOG(ERROR) << "LinkInfo is NULL"; return; } @@ -198,12 +198,12 @@ void UBRingManager::LinkInfoFini(void) { } void UBRingManager::AcquireLinkInfoToMgr(const char *listener_name, UbrTrx *trx) { - if (listener_name == NULL || trx == NULL) { + if (listener_name == nullptr || trx == nullptr) { LOG(ERROR) << "LinkInfo acquire fail."; return; } - if (g_link_info_mgr.link_mgr_unit_status == NULL || g_link_info_mgr.all_link_info == NULL) { + if (g_link_info_mgr.link_mgr_unit_status == nullptr || g_link_info_mgr.all_link_info == nullptr) { LOG(ERROR) << "LinkInfo is NULL."; return; } @@ -220,7 +220,7 @@ void UBRingManager::AcquireLinkInfoToMgr(const char *listener_name, UbrTrx *trx) } void UBRingManager::ReleaseLinkInfoFromMgr(UbrTrx *trx) { - if (trx == NULL || g_link_info_mgr.link_mgr_unit_status == NULL) { + if (trx == nullptr || g_link_info_mgr.link_mgr_unit_status == nullptr) { LOG(ERROR) << "LinkInfo release fail."; return; } @@ -235,11 +235,11 @@ void UBRingManager::ReleaseLinkInfoFromMgr(UbrTrx *trx) { int32_t UBRingManager::UbEventCallback(const char *shm_name) { - if (UNLIKELY(shm_name == NULL)) { + if (UNLIKELY(shm_name == nullptr)) { LOG(ERROR) << "Ub event callback failed, shm name is null."; return UBRING_ERR; } - if (UNLIKELY(g_ubr_mgr.trx_mgr == NULL)) { + if (UNLIKELY(g_ubr_mgr.trx_mgr == nullptr)) { LOG(ERROR) << "Ub event callback failed, trx mgr is null."; return UBRING_ERR; } diff --git a/src/brpc/ubshm/ubs_mem/ubs_mem.h b/src/brpc/ubshm/ubs_mem/ubs_mem.h index 6466dba67f..d5c1ab6814 100644 --- a/src/brpc/ubshm/ubs_mem/ubs_mem.h +++ b/src/brpc/ubshm/ubs_mem/ubs_mem.h @@ -122,7 +122,7 @@ SHMEM_API int ubsmem_shmem_deallocate(const char *name); /** * Map item in UBSMSHMEM to the local virtual address space, and return its pointer. - * @param addr - The starting address for the new mapping is specified in addr, If addr is NULL, then + * @param addr - The starting address for the new mapping is specified in addr, If addr is nullptr, then * the kernel chooses the (page-aligned) address at which to create the mapping * @param length - The length argument specifies the length of the mapping (which must be greater than 0) * @param prot - same as mmap, describes the desired memory protection of the mapping (and must not conflict with