Here it is, the new thread interface.
[citadel.git] / citadel / modules / checkpoint / serv_checkpoint.c
1 /*
2  * $Id: serv_checkpoint.c 5756 2007-11-16 17:15:22Z ajc $
3  *
4  * checkpointing module for the database
5  */
6  
7 #include "sysdep.h"
8 #include <stdlib.h>
9 #include <unistd.h>
10 #include <stdio.h>
11 #include <ctype.h>
12 #include <string.h>
13 #include <errno.h>
14 #include <sys/types.h>
15 #include <sys/stat.h>
16 #include <dirent.h>
17
18 #ifdef HAVE_DB_H
19 #include <db.h>
20 #elif defined(HAVE_DB4_DB_H)
21 #include <db4/db.h>
22 #else
23 #error Neither <db.h> nor <db4/db.h> was found by configure. Install db4-devel.
24 #endif
25
26
27 #if DB_VERSION_MAJOR < 4 || DB_VERSION_MINOR < 1
28 #error Citadel requires Berkeley DB v4.1 or newer.  Please upgrade.
29 #endif
30
31 #include "citadel.h"
32 #include "server.h"
33 #include "citserver.h"
34 #include "database.h"
35 #include "msgbase.h"
36 #include "sysdep_decls.h"
37 #include "config.h"
38
39 #include "ctdl_module.h"
40  
41 /*
42  * Main loop for the checkpoint thread.
43  */
44 void *checkpoint_thread(void *arg) {
45         struct CitContext checkpointCC;
46
47         CtdlLogPrintf(CTDL_DEBUG, "checkpoint_thread() initializing\n");
48
49         memset(&checkpointCC, 0, sizeof(struct CitContext));
50         checkpointCC.internal_pgm = 1;
51         checkpointCC.cs_pid = 0;
52         pthread_setspecific(MyConKey, (void *)&checkpointCC );
53
54         cdb_allocate_tsd();
55
56         while (!CtdlThreadCheckStop()) {
57                 cdb_checkpoint();
58                 CtdlThreadSleep(60);
59         }
60
61         CtdlLogPrintf(CTDL_DEBUG, "checkpoint_thread() exiting\n");
62         return NULL;
63 }
64
65
66 CTDL_MODULE_INIT(checkpoint) {
67         if (threading)
68         {
69                 CtdlThreadCreate ("checkpoint", CTDLTHREAD_BIGSTACK, checkpoint_thread, NULL);
70         }
71         /* return our Subversion id for the Log */
72         return "$Id: serv_autocompletion.c 5756 2007-11-16 17:15:22Z ajc $";
73 }