forked from danaj/Math-Prime-Util
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcache.h
43 lines (38 loc) · 1.44 KB
/
cache.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#ifndef MPU_CACHE_H
#define MPU_CACHE_H
#include "ptypes.h"
/* Sieve from 0 to x and store in primary cache */
extern void prime_precalc(UV x);
/* Release all extra memory -- go back to initial amounts */
extern void prime_memfree(void);
/* Seriously shut everything down, including destroying mutexes.
* This should ONLY be called when we're leaving for good.
*/
extern void _prime_memfreeall(void);
/* Get the primary cache (mod-30 wheel sieve).
* Try to make sure it contains n.
* Returns the maximum value in the cache.
* Sets sieve* to the cache, unless given 0.
* If you get a pointer back, you MUST call release when you're done.
*
* Ex: just give me the current size:
* UV cache_size = get_prime_cache(0, 0);
*
* Ex: give me the current cache and size:
* UV cache_size = get_prime_cache(0, &sieve);
*
* Ex: give me the cache at least size n:
* UV cache_size = get_prime_cache(n, &sieve);
*/
extern UV get_prime_cache(UV n, const unsigned char** sieve);
/* Inform the system we're done using the primary cache if we got a ptr. */
#ifdef USE_ITHREADS
extern void release_prime_cache(const unsigned char* sieve);
#else
#define release_prime_cache(mem)
#endif
/* Get the segment cache. Set size to its size. */
extern unsigned char* get_prime_segment(UV* size);
/* Inform the system we're done using the segment cache. */
extern void release_prime_segment(unsigned char* segment);
#endif