@@ -231,8 +231,9 @@ void slab_unreg(slab_t *slab) {
231231 slab_unreg_by_addr (end_addr , slab );
232232}
233233
234- bucket_t * create_bucket (size_t sz , disjoint_pool_t * pool ,
235- umf_disjoint_pool_shared_limits_t * shared_limits ) {
234+ bucket_t *
235+ create_bucket (size_t sz , disjoint_pool_t * pool ,
236+ umf_disjoint_pool_shared_limits_handle_t shared_limits ) {
236237
237238 bucket_t * bucket = (bucket_t * )umf_ba_global_alloc (sizeof (bucket_t ));
238239 if (bucket == NULL ) {
@@ -1089,3 +1090,147 @@ void umfDisjointPoolSharedLimitsDestroy(
10891090 umf_disjoint_pool_shared_limits_t * limits ) {
10901091 umf_ba_global_free (limits );
10911092}
1093+
1094+ umf_result_t
1095+ umfDisjointPoolParamsCreate (umf_disjoint_pool_params_handle_t * hParams ) {
1096+ static const char * DEFAULT_NAME = "disjoint_pool" ;
1097+
1098+ if (!hParams ) {
1099+ LOG_ERR ("disjoint pool params handle is NULL" );
1100+ return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
1101+ }
1102+
1103+ umf_disjoint_pool_params_handle_t params =
1104+ umf_ba_global_alloc (sizeof (umf_disjoint_pool_params_t ));
1105+ if (params == NULL ) {
1106+ LOG_ERR ("cannot allocate memory for disjoint pool params" );
1107+ return UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY ;
1108+ }
1109+
1110+ params -> SlabMinSize = 0 ;
1111+ params -> MaxPoolableSize = 0 ;
1112+ params -> Capacity = 0 ;
1113+ params -> MinBucketSize = UMF_DISJOINT_POOL_MIN_BUCKET_DEFAULT_SIZE ;
1114+ params -> CurPoolSize = 0 ;
1115+ params -> PoolTrace = 0 ;
1116+ params -> SharedLimits = NULL ;
1117+ params -> Name = NULL ;
1118+
1119+ umf_result_t ret = umfDisjointPoolParamsSetName (params , DEFAULT_NAME );
1120+ if (ret != UMF_RESULT_SUCCESS ) {
1121+ umf_ba_global_free (params );
1122+ return ret ;
1123+ }
1124+
1125+ * hParams = params ;
1126+
1127+ return UMF_RESULT_SUCCESS ;
1128+ }
1129+
1130+ umf_result_t
1131+ umfDisjointPoolParamsDestroy (umf_disjoint_pool_params_handle_t hParams ) {
1132+ if (hParams ) {
1133+ umf_ba_global_free (hParams -> Name );
1134+ umf_ba_global_free (hParams );
1135+ }
1136+
1137+ return UMF_RESULT_SUCCESS ;
1138+ }
1139+
1140+ umf_result_t
1141+ umfDisjointPoolParamsSetSlabMinSize (umf_disjoint_pool_params_handle_t hParams ,
1142+ size_t slabMinSize ) {
1143+ if (!hParams ) {
1144+ LOG_ERR ("disjoint pool params handle is NULL" );
1145+ return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
1146+ }
1147+
1148+ hParams -> SlabMinSize = slabMinSize ;
1149+ return UMF_RESULT_SUCCESS ;
1150+ }
1151+
1152+ umf_result_t umfDisjointPoolParamsSetMaxPoolableSize (
1153+ umf_disjoint_pool_params_handle_t hParams , size_t maxPoolableSize ) {
1154+ if (!hParams ) {
1155+ LOG_ERR ("disjoint pool params handle is NULL" );
1156+ return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
1157+ }
1158+
1159+ hParams -> MaxPoolableSize = maxPoolableSize ;
1160+ return UMF_RESULT_SUCCESS ;
1161+ }
1162+
1163+ umf_result_t
1164+ umfDisjointPoolParamsSetCapacity (umf_disjoint_pool_params_handle_t hParams ,
1165+ size_t maxCapacity ) {
1166+ if (!hParams ) {
1167+ LOG_ERR ("disjoint pool params handle is NULL" );
1168+ return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
1169+ }
1170+
1171+ hParams -> Capacity = maxCapacity ;
1172+ return UMF_RESULT_SUCCESS ;
1173+ }
1174+
1175+ umf_result_t
1176+ umfDisjointPoolParamsSetMinBucketSize (umf_disjoint_pool_params_handle_t hParams ,
1177+ size_t minBucketSize ) {
1178+ if (!hParams ) {
1179+ LOG_ERR ("disjoint pool params handle is NULL" );
1180+ return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
1181+ }
1182+
1183+ // minBucketSize parameter must be a power of 2 and greater than 0.
1184+ if (minBucketSize == 0 || (minBucketSize & (minBucketSize - 1 ))) {
1185+ LOG_ERR ("minBucketSize must be a power of 2 and greater than 0" );
1186+ return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
1187+ }
1188+
1189+ hParams -> MinBucketSize = minBucketSize ;
1190+ return UMF_RESULT_SUCCESS ;
1191+ }
1192+
1193+ umf_result_t
1194+ umfDisjointPoolParamsSetTrace (umf_disjoint_pool_params_handle_t hParams ,
1195+ int poolTrace ) {
1196+ if (!hParams ) {
1197+ LOG_ERR ("disjoint pool params handle is NULL" );
1198+ return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
1199+ }
1200+
1201+ hParams -> PoolTrace = poolTrace ;
1202+ return UMF_RESULT_SUCCESS ;
1203+ }
1204+
1205+ umf_result_t umfDisjointPoolParamsSetSharedLimits (
1206+ umf_disjoint_pool_params_handle_t hParams ,
1207+ umf_disjoint_pool_shared_limits_handle_t hSharedLimits ) {
1208+ if (!hParams ) {
1209+ LOG_ERR ("disjoint pool params handle is NULL" );
1210+ return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
1211+ }
1212+
1213+ hParams -> SharedLimits = hSharedLimits ;
1214+ return UMF_RESULT_SUCCESS ;
1215+ }
1216+
1217+ umf_result_t
1218+ umfDisjointPoolParamsSetName (umf_disjoint_pool_params_handle_t hParams ,
1219+ const char * name ) {
1220+ if (!hParams ) {
1221+ LOG_ERR ("disjoint pool params handle is NULL" );
1222+ return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
1223+ }
1224+
1225+ char * newName = umf_ba_global_alloc (sizeof (char ) * (strlen (name ) + 1 ));
1226+ if (newName == NULL ) {
1227+ LOG_ERR ("cannot allocate memory for disjoint pool name" );
1228+ return UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY ;
1229+ }
1230+
1231+ umf_ba_global_free (hParams -> Name );
1232+ hParams -> Name = newName ;
1233+ strcpy (hParams -> Name , name );
1234+
1235+ return UMF_RESULT_SUCCESS ;
1236+ }
0 commit comments