* Note: certain statistics (e.g. shm statistics) require different handling, * hence the parameter */
| 405 | * hence the <unsafe> parameter |
| 406 | */ |
| 407 | static int __register_stat(str *module, str *name, stat_var **pvar, |
| 408 | unsigned short flags, void *ctx, int unsafe) |
| 409 | { |
| 410 | module_stats* mods; |
| 411 | stat_var **shash; |
| 412 | stat_var *stat; |
| 413 | stat_var *it; |
| 414 | int hash; |
| 415 | |
| 416 | if (module==0 || name==0 || pvar==0) { |
| 417 | LM_ERR("invalid parameters module=%p, name=%p, pvar=%p \n", |
| 418 | module, name, pvar); |
| 419 | goto error; |
| 420 | } |
| 421 | |
| 422 | if(flags&STAT_NOT_ALLOCATED){ |
| 423 | stat = *pvar; |
| 424 | goto do_register; |
| 425 | } |
| 426 | stat = unsafe ? |
| 427 | (stat_var*)shm_malloc_unsafe(sizeof(stat_var) + |
| 428 | (((flags&STAT_SHM_NAME)==0)?name->len:0)) |
| 429 | : |
| 430 | (stat_var*)shm_malloc(sizeof(stat_var) + |
| 431 | (((flags&STAT_SHM_NAME)==0)?name->len:0)); |
| 432 | |
| 433 | if (stat==0) { |
| 434 | LM_ERR("no more shm memory\n"); |
| 435 | goto error; |
| 436 | } |
| 437 | memset( stat, 0, sizeof(stat_var) ); |
| 438 | |
| 439 | if ( (flags&STAT_IS_FUNC)==0 ) { |
| 440 | stat->u.val = unsafe ? |
| 441 | (stat_val*)shm_malloc_unsafe(sizeof(stat_val)) : |
| 442 | (stat_val*)shm_malloc(sizeof(stat_val)); |
| 443 | if (stat->u.val==0) { |
| 444 | LM_ERR("no more shm memory\n"); |
| 445 | goto error1; |
| 446 | } |
| 447 | #ifdef NO_ATOMIC_OPS |
| 448 | *(stat->u.val) = 0; |
| 449 | #else |
| 450 | atomic_init(stat->u.val, 0); |
| 451 | #endif |
| 452 | *pvar = stat; |
| 453 | } else { |
| 454 | stat->u.f = (stat_function)(pvar); |
| 455 | } |
| 456 | |
| 457 | /* is the module already recorded? */ |
| 458 | do_register: |
| 459 | mods = get_stat_module(module); |
| 460 | if (mods==0) { |
| 461 | mods = __add_stat_module(module, unsafe); |
| 462 | if (mods==0) { |
| 463 | LM_ERR("failed to add new module\n"); |
| 464 | goto error2; |
no test coverage detected