@@ -817,20 +817,19 @@ static void _common_ucx_tls_cleanup(_tlocal_table_t *tls)
817
817
// Cleanup memory table
818
818
size = tls -> mem_tbl_size ;
819
819
for (i = 0 ; i < size ; i ++ ) {
820
- if (NULL = = tls -> mem_tbl [i ]-> gmem ){
821
- continue ;
820
+ if (NULL ! = tls -> mem_tbl [i ]-> gmem ){
821
+ _tlocal_mem_record_cleanup ( tls -> mem_tbl [ i ]) ;
822
822
}
823
- _tlocal_mem_record_cleanup ( tls -> mem_tbl [ i ]);
823
+
824
824
free (tls -> mem_tbl [i ]);
825
825
}
826
826
827
827
// Cleanup ctx table
828
828
size = tls -> ctx_tbl_size ;
829
829
for (i = 0 ; i < size ; i ++ ) {
830
- if (NULL = = tls -> ctx_tbl [i ]-> gctx ){
831
- continue ;
830
+ if (NULL ! = tls -> ctx_tbl [i ]-> gctx ){
831
+ _tlocal_ctx_record_cleanup ( tls -> ctx_tbl [ i ]) ;
832
832
}
833
- _tlocal_ctx_record_cleanup (tls -> ctx_tbl [i ]);
834
833
free (tls -> ctx_tbl [i ]);
835
834
}
836
835
@@ -918,7 +917,7 @@ static _tlocal_ctx_t *
918
917
_tlocal_add_ctx (_tlocal_table_t * tls , opal_common_ucx_ctx_t * ctx )
919
918
{
920
919
size_t i , free_idx = -1 ;
921
- int rc ;
920
+ int rc , found = 0 ;
922
921
923
922
/* Try to find available record in the TLS table
924
923
* In parallel perform deferred cleanups */
@@ -929,14 +928,15 @@ _tlocal_add_ctx(_tlocal_table_t *tls, opal_common_ucx_ctx_t *ctx)
929
928
_tlocal_ctx_record_cleanup (tls -> ctx_tbl [i ]);
930
929
}
931
930
}
932
- if ((NULL != tls -> ctx_tbl [i ]-> gctx ) && ( 0 > free_idx ) ) {
931
+ if ((NULL == tls -> ctx_tbl [i ]-> gctx ) && ! found ) {
933
932
/* Found clean record */
934
933
free_idx = i ;
934
+ found = 1 ;
935
935
}
936
936
}
937
937
938
938
/* if needed - extend the table */
939
- if (0 > free_idx ) {
939
+ if (! found ) {
940
940
free_idx = tls -> ctx_tbl_size ;
941
941
rc = _tlocal_tls_ctxtbl_extend (tls , 4 );
942
942
if (rc ) {
@@ -1025,15 +1025,6 @@ _tlocal_mem_record_cleanup(_tlocal_mem_t *mem_rec)
1025
1025
size_t i ;
1026
1026
WPOOL_DBG_OUT (_dbg_tls || _dbg_mem , "record=%p, is_freed = %d\n" ,
1027
1027
(void * )mem_rec , mem_rec -> gmem -> released );
1028
- if (mem_rec -> gmem -> released ) {
1029
- return ;
1030
- }
1031
- /* Remove myself from the memory context structure
1032
- * This may result in context release as we are using
1033
- * delayed cleanup */
1034
- _common_ucx_mem_signout (mem_rec -> gmem );
1035
- WPOOL_DBG_OUT (_dbg_tls || _dbg_mem , "gmem = %p mem_rec = %p\n" ,
1036
- (void * )mem_rec -> gmem , (void * )mem_rec );
1037
1028
1038
1029
for (i = 0 ; i < mem_rec -> gmem -> ctx -> comm_size ; i ++ ) {
1039
1030
if (mem_rec -> mem -> rkeys [i ]) {
@@ -1044,6 +1035,13 @@ _tlocal_mem_record_cleanup(_tlocal_mem_t *mem_rec)
1044
1035
}
1045
1036
free (mem_rec -> mem -> rkeys );
1046
1037
1038
+ /* Remove myself from the memory context structure
1039
+ * This may result in context release as we are using
1040
+ * delayed cleanup */
1041
+ _common_ucx_mem_signout (mem_rec -> gmem );
1042
+ WPOOL_DBG_OUT (_dbg_tls || _dbg_mem , "gmem = %p mem_rec = %p\n" ,
1043
+ (void * )mem_rec -> gmem , (void * )mem_rec );
1044
+
1047
1045
/* Release fast-path pointers */
1048
1046
if (NULL != mem_rec -> mem_tls_ptr ) {
1049
1047
free (mem_rec -> mem_tls_ptr );
@@ -1059,24 +1057,24 @@ static _tlocal_mem_t *_tlocal_add_mem(_tlocal_table_t *tls,
1059
1057
{
1060
1058
size_t i , free_idx = -1 ;
1061
1059
_tlocal_ctx_t * ctx_rec = NULL ;
1062
- int rc = OPAL_SUCCESS ;
1060
+ int rc = OPAL_SUCCESS , found = 0 ;
1063
1061
1064
1062
/* Try to find available spot in the table */
1065
1063
for (i = 0 ; i < tls -> mem_tbl_size ; i ++ ) {
1066
- if (NULL = = tls -> mem_tbl [i ]-> gmem ) {
1064
+ if (NULL ! = tls -> mem_tbl [i ]-> gmem ) {
1067
1065
if (tls -> mem_tbl [i ]-> gmem -> released ) {
1068
1066
/* Found a dirty record. Need to clean it first */
1069
1067
_tlocal_mem_record_cleanup (tls -> mem_tbl [i ]);
1070
- break ;
1071
1068
}
1072
1069
}
1073
- if ((NULL == tls -> mem_tbl [i ]-> gmem ) && ( 0 > free_idx ) ) {
1070
+ if ((NULL == tls -> mem_tbl [i ]-> gmem ) && ! found ) {
1074
1071
/* Found a clear record */
1075
1072
free_idx = i ;
1073
+ found = 1 ;
1076
1074
}
1077
1075
}
1078
1076
1079
- if (0 > free_idx ){
1077
+ if (! found ){
1080
1078
free_idx = tls -> mem_tbl_size ;
1081
1079
rc = _tlocal_tls_memtbl_extend (tls , 4 );
1082
1080
if (rc != OPAL_SUCCESS ) {
0 commit comments