[package] update libtorrent to r1189
[packages.git] / libs / libtorrent / patches / 110-fix-no-posix_memalign.diff
1 --- a/rak/allocators.h
2 +++ b/rak/allocators.h
3 @@ -74,17 +74,13 @@ public:
4    size_type max_size () const throw() { return std::numeric_limits<size_t>::max() / sizeof(T); }
5  
6    pointer allocate(size_type num, const_void_pointer hint = 0) { return alloc_size(num*sizeof(T)); }
7 +  void deallocate (pointer p, size_type num) { dealloc_size(p, num*sizeof(T)); }
8  
9 -  static pointer alloc_size(size_type size) {
10 -    pointer ptr = NULL;
11 -    int __UNUSED result = posix_memalign((void**)&ptr, LT_SMP_CACHE_BYTES, size);
12 -
13 -    return ptr;
14 -  }
15 +  static pointer alloc_size(size_type size);
16 +  static void dealloc_size(pointer p, size_type size);
17  
18    void construct (pointer p, const T& value) { new((void*)p)T(value); }
19    void destroy (pointer p) { p->~T(); }
20 -  void deallocate (pointer p, size_type num) { free((void*)p); }
21  };
22  
23  
24 @@ -98,6 +94,36 @@ bool operator!= (const cacheline_allocator<T1>&, const cacheline_allocator<T2>&)
25    return false;
26  }
27  
28 +template <class T>
29 +inline typename cacheline_allocator<T>::pointer cacheline_allocator<T>::alloc_size(size_type size) {
30 +  pointer ptr;
31 +
32 +#if HAVE_POSIX_MEMALIGN
33 +  if (posix_memalign((void**)&ptr, LT_SMP_CACHE_BYTES, size))
34 +    return NULL;
35 +#else
36 +  char* org = (char*)malloc(size + sizeof(void*) + LT_SMP_CACHE_BYTES - 1);
37 +  if (org == NULL)
38 +    return NULL;
39 +
40 +  ptr = (pointer)((uintptr_t)(org + LT_SMP_CACHE_BYTES - 1) & ~(LT_SMP_CACHE_BYTES - 1));
41 +
42 +  // store originally allocated pointer for later free() at the end of the allocated data
43 +  *(void**)((char*)ptr + size) = org;
44 +#endif
45 +
46 +  return ptr;
47 +}
48 +
49 +template <class T>
50 +inline void cacheline_allocator<T>::dealloc_size(pointer p, size_type size) {
51 +#if HAVE_POSIX_MEMALIGN
52 +  free(p);
53 +#else
54 +  free(*(void**)((char*)p + size));
55 +#endif
56 +}
57 +
58  }
59  
60  //