From e6f676630007500278b559576811de99cb9fc2c1 Mon Sep 17 00:00:00 2001 From: Nicholas Sielicki Date: Mon, 12 Aug 2024 14:38:49 -0700 Subject: [PATCH] nit: msgbuff: avoid typedef hell stack-info: PR: https://github.com/aws/aws-ofi-nccl/pull/562, branch: aws-nslick/stack/9 Signed-off-by: Nicholas Sielicki --- include/nccl_ofi_msgbuff.h | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/include/nccl_ofi_msgbuff.h b/include/nccl_ofi_msgbuff.h index 41586260f..6a2023c8d 100644 --- a/include/nccl_ofi_msgbuff.h +++ b/include/nccl_ofi_msgbuff.h @@ -43,7 +43,7 @@ extern "C" { */ /* Enumeration to keep track of different msg statuses. */ -typedef enum { +enum nccl_ofi_msgbuff_status { /** The message has been marked completed **/ NCCL_OFI_MSGBUFF_COMPLETED, /** The message has been added to the buffer but not marked complete **/ @@ -52,39 +52,40 @@ typedef enum { NCCL_OFI_MSGBUFF_NOTSTARTED, /** The index is not in the range of completed or not-started messages **/ NCCL_OFI_MSGBUFF_UNAVAILABLE, -} nccl_ofi_msgbuff_status_t; +}; -typedef enum { +enum nccl_ofi_msgbuff_result { /** Operation completed successfully **/ NCCL_OFI_MSGBUFF_SUCCESS, /** The provided index was invalid; see msg_idx_status output **/ NCCL_OFI_MSGBUFF_INVALID_IDX, /** Other error **/ NCCL_OFI_MSGBUFF_ERROR, -} nccl_ofi_msgbuff_result_t; +}; /* Type of element stored in msg buffer. This is used to distinguish between reqs and bounce buffers (when we don't have req) stored in the message buffer */ -typedef enum { +enum nccl_ofi_msgbuff_elemtype { /* Request */ NCCL_OFI_MSGBUFF_REQ, /* Bounce buffer */ NCCL_OFI_MSGBUFF_BUFF -} nccl_ofi_msgbuff_elemtype_t; +}; /* Internal buffer storage type, used to keep status of elements currently stored in * buffer */ -typedef struct { +struct nccl_ofi_msgbuff_elem { // Status of message: COMPLETED, INPROGRESS, or NOTSTARTED - nccl_ofi_msgbuff_status_t stat; + enum nccl_ofi_msgbuff_status stat; // Type of element - nccl_ofi_msgbuff_elemtype_t type; + enum nccl_ofi_msgbuff_elemtype type; void *elem; -} nccl_ofi_msgbuff_elem_t; +}; -typedef struct { + +struct nccl_ofi_msgbuff { // Element storage buffer. Allocated in msgbuff_init - nccl_ofi_msgbuff_elem_t *buff; + struct nccl_ofi_msgbuff_elem *buff; /* Max number of INPROGRESS elements. These are the only * ones backed by the storage buffer, so this is also the * size of the storage buffer */ @@ -101,7 +102,13 @@ typedef struct { uint16_t msg_next; // Mutex for this msg buffer -- locks all non-init operations pthread_mutex_t lock; -} nccl_ofi_msgbuff_t; +}; + +typedef enum nccl_ofi_msgbuff_elemtype nccl_ofi_msgbuff_elemtype_t; +typedef enum nccl_ofi_msgbuff_status nccl_ofi_msgbuff_status_t; +typedef enum nccl_ofi_msgbuff_result nccl_ofi_msgbuff_result_t; +typedef struct nccl_ofi_msgbuff_elem nccl_ofi_msgbuff_elem_t; +typedef struct nccl_ofi_msgbuff nccl_ofi_msgbuff_t; /** * Allocates and initializes a new message buffer. @@ -182,7 +189,7 @@ nccl_ofi_msgbuff_result_t nccl_ofi_msgbuff_retrieve(nccl_ofi_msgbuff_t *msgbuff, nccl_ofi_msgbuff_result_t nccl_ofi_msgbuff_complete(nccl_ofi_msgbuff_t *msgbuff, uint16_t msg_index, nccl_ofi_msgbuff_status_t *msg_idx_status); -#ifdef _cplusplus +#ifdef __cplusplus } // End extern "C" #endif