MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / zoneindex

Function zoneindex

src/slab.c:411–469  ·  view source on GitHub ↗

* Calculate the zone index for the allocation request size and set the * allocation request size to that particular zone's chunk size. */

Source from the content-addressed store, hash-verified

409 * allocation request size to that particular zone's chunk size.
410 */
411rt_inline int zoneindex(rt_size_t *bytes)
412{
413 /* unsigned for shift opt */
414 rt_uintptr_t n = (rt_uintptr_t)(*bytes);
415
416 if (n < 128)
417 {
418 *bytes = n = (n + 7) & ~7;
419
420 /* 8 byte chunks, 16 zones */
421 return (n / 8 - 1);
422 }
423 if (n < 256)
424 {
425 *bytes = n = (n + 15) & ~15;
426
427 return (n / 16 + 7);
428 }
429 if (n < 8192)
430 {
431 if (n < 512)
432 {
433 *bytes = n = (n + 31) & ~31;
434
435 return (n / 32 + 15);
436 }
437 if (n < 1024)
438 {
439 *bytes = n = (n + 63) & ~63;
440
441 return (n / 64 + 23);
442 }
443 if (n < 2048)
444 {
445 *bytes = n = (n + 127) & ~127;
446
447 return (n / 128 + 31);
448 }
449 if (n < 4096)
450 {
451 *bytes = n = (n + 255) & ~255;
452
453 return (n / 256 + 39);
454 }
455 *bytes = n = (n + 511) & ~511;
456
457 return (n / 512 + 47);
458 }
459 if (n < 16384)
460 {
461 *bytes = n = (n + 1023) & ~1023;
462
463 return (n / 1024 + 55);
464 }
465
466 rt_kprintf("Unexpected byte count %d", n);
467
468 return 0;

Callers 2

rt_slab_allocFunction · 0.85
rt_slab_reallocFunction · 0.85

Calls 1

rt_kprintfFunction · 0.85

Tested by

no test coverage detected