|
6 | 6 | #include <sys/wait.h> |
7 | 7 | #include <unistd.h> |
8 | 8 |
|
| 9 | +#include <string> |
| 10 | + |
9 | 11 | #include "common.h" |
10 | 12 | #include "common_protocol.h" |
11 | 13 | #include "event_loop.h" |
@@ -342,42 +344,27 @@ LocalSchedulerState *LocalSchedulerState_init( |
342 | 344 |
|
343 | 345 | /* Connect to Redis if a Redis address is provided. */ |
344 | 346 | if (redis_primary_addr != NULL) { |
345 | | - int num_args; |
346 | | - const char **db_connect_args = NULL; |
347 | | - /* Use UT_string to convert the resource value into a string. */ |
348 | | - UT_string *num_cpus; |
349 | | - UT_string *num_gpus; |
350 | | - utstring_new(num_cpus); |
351 | | - utstring_new(num_gpus); |
352 | | - utstring_printf(num_cpus, "%f", static_resource_conf[0]); |
353 | | - utstring_printf(num_gpus, "%f", static_resource_conf[1]); |
| 347 | + /* Use std::string to convert the resource value into a string. */ |
| 348 | + std::string num_cpus = std::to_string(static_resource_conf[0]); |
| 349 | + std::string num_gpus = std::to_string(static_resource_conf[1]); |
| 350 | + |
| 351 | + /* Construct db_connect_args */ |
| 352 | + std::vector<const char *> db_connect_args; |
| 353 | + db_connect_args.push_back("local_scheduler_socket_name"); |
| 354 | + db_connect_args.push_back(local_scheduler_socket_name); |
| 355 | + db_connect_args.push_back("num_cpus"); |
| 356 | + db_connect_args.push_back(num_cpus.c_str()); |
| 357 | + db_connect_args.push_back("num_gpus"); |
| 358 | + db_connect_args.push_back(num_gpus.c_str()); |
| 359 | + |
354 | 360 | if (plasma_manager_address != NULL) { |
355 | | - num_args = 8; |
356 | | - db_connect_args = (const char **) malloc(sizeof(char *) * num_args); |
357 | | - db_connect_args[0] = "local_scheduler_socket_name"; |
358 | | - db_connect_args[1] = local_scheduler_socket_name; |
359 | | - db_connect_args[2] = "num_cpus"; |
360 | | - db_connect_args[3] = utstring_body(num_cpus); |
361 | | - db_connect_args[4] = "num_gpus"; |
362 | | - db_connect_args[5] = utstring_body(num_gpus); |
363 | | - db_connect_args[6] = "manager_address"; |
364 | | - db_connect_args[7] = plasma_manager_address; |
365 | | - } else { |
366 | | - num_args = 6; |
367 | | - db_connect_args = (const char **) malloc(sizeof(char *) * num_args); |
368 | | - db_connect_args[0] = "local_scheduler_socket_name"; |
369 | | - db_connect_args[1] = local_scheduler_socket_name; |
370 | | - db_connect_args[2] = "num_cpus"; |
371 | | - db_connect_args[3] = utstring_body(num_cpus); |
372 | | - db_connect_args[4] = "num_gpus"; |
373 | | - db_connect_args[5] = utstring_body(num_gpus); |
| 361 | + db_connect_args.push_back("manager_address"); |
| 362 | + db_connect_args.push_back(plasma_manager_address); |
374 | 363 | } |
| 364 | + |
375 | 365 | state->db = db_connect(std::string(redis_primary_addr), redis_primary_port, |
376 | | - "local_scheduler", node_ip_address, num_args, |
377 | | - db_connect_args); |
378 | | - utstring_free(num_cpus); |
379 | | - utstring_free(num_gpus); |
380 | | - free(db_connect_args); |
| 366 | + "local_scheduler", node_ip_address, |
| 367 | + db_connect_args.size(), &db_connect_args[0]); |
381 | 368 | db_attach(state->db, loop, false); |
382 | 369 | } else { |
383 | 370 | state->db = NULL; |
|
0 commit comments