1 #ifndef TAGS_CACHE_H
2 #define TAGS_CACHE_H
3 
4 #include <pthread.h>
5 #ifdef HAVE_DB_H
6 #include <db.h>
7 #endif
8 
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
13 struct file_tags;
14 
15 /* Requests queue. */
16 struct request_queue_node;
17 struct request_queue
18 {
19 	struct request_queue_node *head;
20 	struct request_queue_node *tail;
21 };
22 
23 struct tags_cache
24 {
25 	/* BerkeleyDB's stuff for storing cache. */
26 #ifdef HAVE_DB_H
27 	DB_ENV *db_env;
28 	DB *db;
29 	u_int32_t locker;
30 #endif
31 
32 	int max_items;		/* maximum number of items in the cache. */
33 	struct request_queue queues[CLIENTS_MAX]; /* requests queues for each
34 						     client */
35 	int stop_reader_thread; /* request for stopping read thread (if
36 				   non-zero) */
37 	pthread_cond_t request_cond; /* condition for signalizing new
38 					requests */
39 	pthread_mutex_t mutex; /* mutex for all above data (except db because
40 				  it's thread-safe) */
41 	pthread_t reader_thread; /* tid of the reading thread */
42 };
43 
44 /* Administrative functions: */
45 void tags_cache_init (struct tags_cache *c, size_t max_size);
46 void tags_cache_destroy (struct tags_cache *c);
47 
48 /* Request queue manipulation functions: */
49 void tags_cache_clear_queue (struct tags_cache *c, int client_id);
50 void tags_cache_clear_up_to (struct tags_cache *c, const char *file,
51                                                       int client_id);
52 
53 /* Cache DB manipulation functions: */
54 void tags_cache_load (struct tags_cache *c, const char *cache_dir);
55 void tags_cache_save (struct tags_cache *c, const char *cache_dir);
56 void tags_cache_add_request (struct tags_cache *c, const char *file,
57                                         int tags_sel, int client_id);
58 struct file_tags *tags_cache_get_immediate (struct tags_cache *c,
59                                   const char *file, int tags_sel);
60 
61 #ifdef __cplusplus
62 }
63 #endif
64 
65 #endif
66