other.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright 2011 Institute of Communication and Computer Systems (ICCS)
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. *
  16. */
  17. #include "other.h"
  18. #include <pthread.h>
  19. size_t req_padding(size_t size) {
  20. if(size <= 32)
  21. return 32;
  22. if(size <= 64)
  23. return 64;
  24. if(size <= 128)
  25. return 128;
  26. if(size <= 256)
  27. return 256;
  28. return size;
  29. }
  30. int map_size_to_list(heap_t *heap, size_t sz) {
  31. int i;
  32. maptable_node_t *node;
  33. i = 0;
  34. node = heap->maptable_head;
  35. while(node) {
  36. if(node->size == sz) {
  37. return i;
  38. }
  39. i++;
  40. node = node->next;
  41. }
  42. return -1;
  43. }
  44. #ifndef WITH_MEMORY_SPACE_AWARENESS
  45. /* Random assignment */
  46. int map_thread_heap(void) {
  47. return (int) (((unsigned long) pthread_self() >> 10) % NUM_HEAPS);
  48. }
  49. #endif /* WITH_MEMORY_SPACE_AWARENESS */