lock-free-alloc.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /**
  2. * \file
  3. * Lock free allocator.
  4. *
  5. * (C) Copyright 2011 Novell, Inc
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining
  8. * a copy of this software and associated documentation files (the
  9. * "Software"), to deal in the Software without restriction, including
  10. * without limitation the rights to use, copy, modify, merge, publish,
  11. * distribute, sublicense, and/or sell copies of the Software, and to
  12. * permit persons to whom the Software is furnished to do so, subject to
  13. * the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be
  16. * included in all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  19. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  20. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  21. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  22. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  23. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  24. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  25. */
  26. #ifndef __MONO_LOCKFREEALLOC_H__
  27. #define __MONO_LOCKFREEALLOC_H__
  28. #include <glib.h>
  29. #include <mono/utils/lock-free-queue.h>
  30. #include <mono/utils/mono-mmap.h>
  31. typedef struct {
  32. MonoLockFreeQueue partial;
  33. unsigned int slot_size;
  34. unsigned int block_size;
  35. } MonoLockFreeAllocSizeClass;
  36. struct _MonoLockFreeAllocDescriptor;
  37. typedef struct {
  38. struct _MonoLockFreeAllocDescriptor *active;
  39. MonoLockFreeAllocSizeClass *sc;
  40. MonoMemAccountType account_type;
  41. } MonoLockFreeAllocator;
  42. #define LOCK_FREE_ALLOC_SB_MAX_SIZE 16384
  43. #define LOCK_FREE_ALLOC_SB_HEADER_SIZE (sizeof (gpointer))
  44. #define LOCK_FREE_ALLOC_SB_USABLE_SIZE(block_size) ((block_size) - LOCK_FREE_ALLOC_SB_HEADER_SIZE)
  45. MONO_API void mono_lock_free_allocator_init_size_class (MonoLockFreeAllocSizeClass *sc, unsigned int slot_size, unsigned int block_size);
  46. MONO_API void mono_lock_free_allocator_init_allocator (MonoLockFreeAllocator *heap, MonoLockFreeAllocSizeClass *sc, MonoMemAccountType account_type);
  47. MONO_API gpointer mono_lock_free_alloc (MonoLockFreeAllocator *heap);
  48. MONO_API void mono_lock_free_free (gpointer ptr, size_t block_size);
  49. MONO_API gboolean mono_lock_free_allocator_check_consistency (MonoLockFreeAllocator *heap);
  50. #endif