[packages] slang2: add the OLD directory as a source url
[packages.git] / net / rtorrent / patches / 110-fix-no-posix_memalign.patch
1 Index: rtorrent-0.8.6_r1209/rak/allocators.h
2 ===================================================================
3 --- rtorrent-0.8.6_r1209.orig/rak/allocators.h  2010-11-10 12:40:28.000000000 +0100
4 +++ rtorrent-0.8.6_r1209/rak/allocators.h       2011-04-13 16:30:02.370840196 +0200
5 @@ -42,6 +42,7 @@
6  #include <cstddef>
7  #include <limits>
8  #include <stdlib.h>
9 +#include <stdint.h>
10  #include <sys/types.h>
11  
12  namespace rak {
13 @@ -74,17 +75,13 @@
14    size_type max_size () const throw() { return std::numeric_limits<size_t>::max() / sizeof(T); }
15  
16    pointer allocate(size_type num, const_void_pointer hint = 0) { return alloc_size(num*sizeof(T)); }
17 +  void deallocate (pointer p, size_type num) { dealloc_size(p, num*sizeof(T)); }
18  
19 -  static pointer alloc_size(size_type size) {
20 -    pointer ptr = NULL;
21 -    int __UNUSED result = posix_memalign((void**)&ptr, LT_SMP_CACHE_BYTES, size);
22 -
23 -    return ptr;
24 -  }
25 +  static pointer alloc_size(size_type size);
26 +  static void dealloc_size(pointer p, size_type size);
27  
28    void construct (pointer p, const T& value) { new((void*)p)T(value); }
29    void destroy (pointer p) { p->~T(); }
30 -  void deallocate (pointer p, size_type num) { free((void*)p); }
31  };
32  
33  
34 @@ -98,6 +95,36 @@
35    return false;
36  }
37  
38 +template <class T>
39 +inline typename cacheline_allocator<T>::pointer cacheline_allocator<T>::alloc_size(size_type size) {
40 +  pointer ptr;
41 +
42 +#if HAVE_POSIX_MEMALIGN
43 +  if (posix_memalign((void**)&ptr, LT_SMP_CACHE_BYTES, size))
44 +    return NULL;
45 +#else
46 +  char* org = (char*)malloc(size + sizeof(void*) + LT_SMP_CACHE_BYTES - 1);
47 +  if (org == NULL)
48 +    return NULL;
49 +
50 +  ptr = (pointer)((uintptr_t)(org + LT_SMP_CACHE_BYTES - 1) & ~(LT_SMP_CACHE_BYTES - 1));
51 +
52 +  // store originally allocated pointer for later free() at the end of the allocated data
53 +  *(void**)((char*)ptr + size) = org;
54 +#endif
55 +
56 +  return ptr;
57 +}
58 +
59 +template <class T>
60 +inline void cacheline_allocator<T>::dealloc_size(pointer p, size_type size) {
61 +#if HAVE_POSIX_MEMALIGN
62 +  free(p);
63 +#else
64 +  free(*(void**)((char*)p + size));
65 +#endif
66 +}
67 +
68  }
69  
70  //