Sha256: e887c077f9a609e5d3bf4659d5e706f88991ba669e507dc6ab369b77b39776c1

Contents?: true

Size: 1.03 KB

Versions: 6

Compression:

Stored size: 1.03 KB

Contents

#include "../sass.hpp"
#include "allocator.hpp"
#include "memory_pool.hpp"

#if defined (_MSC_VER) // Visual studio
#define thread_local __declspec( thread )
#elif defined (__GCC__) // GCC
#define thread_local __thread
#endif

namespace Sass {

#ifdef SASS_CUSTOM_ALLOCATOR

  // Only use PODs for thread_local
  // Objects get unpredictable init order
  static thread_local MemoryPool* pool;
  static thread_local size_t allocations;

  void* allocateMem(size_t size)
  {
    if (pool == nullptr) {
      pool = new MemoryPool();
    }
    allocations++;
    return pool->allocate(size);
  }

  void deallocateMem(void* ptr, size_t size)
  {

    // It seems thread_local variable might be discharged!?
    // But the destructors of e.g. static strings is still
    // called, although their memory was discharged too.
    // Fine with me as long as address sanitizer is happy.
    if (pool == nullptr || allocations == 0) { return; }

    pool->deallocate(ptr);
    if (--allocations == 0) {
      delete pool;
      pool = nullptr;
    }

  }

#endif

}

Version data entries

6 entries across 5 versions & 4 rubygems

Version Path
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.1.0/gems/sassc-2.4.0/ext/libsass/src/memory/allocator.cpp
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.3.0/gems/sassc-2.4.0/ext/libsass/src/memory/allocator.cpp
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/sassc-2.4.0/ext/libsass/src/memory/allocator.cpp
date_n_time_picker_activeadmin-0.1.2 vendor/bundle/ruby/2.6.0/gems/sassc-2.4.0/ext/libsass/src/memory/allocator.cpp
date_n_time_picker_activeadmin-0.1.1 vendor/bundle/ruby/2.6.0/gems/sassc-2.4.0/ext/libsass/src/memory/allocator.cpp
sassc-2.4.0 ext/libsass/src/memory/allocator.cpp