Provide a simple configurable limit on the number of threads.
[bluesky.git] / bluesky / init.c
1 /* Blue Sky: File Systems in the Cloud
2  *
3  * Copyright (C) 2009  The Regents of the University of California
4  * Written by Michael Vrable <mvrable@cs.ucsd.edu>
5  *
6  * TODO: Licensing
7  */
8
9 #include <stdint.h>
10 #include <stdlib.h>
11 #include <glib.h>
12 #include <string.h>
13
14 #include "bluesky-private.h"
15
16 BlueSkyOptions bluesky_options;
17
18 /* Maximum number of threads to use in any particular thread pool, or -1 for no
19  * limit */
20 int bluesky_max_threads = -1;
21
22 /* Environment variables that can be used to initialize settings. */
23 static struct {
24     const char *env;
25     int *option;
26 } option_table[] = {
27     {"BLUESKY_OPT_SYNC_STORES", &bluesky_options.synchronous_stores},
28     {"BLUESKY_OPT_WRITETHROUGH", &bluesky_options.writethrough_cache},
29     {"BLUESKY_OPT_SYNC_INODE_FETCH", &bluesky_options.sync_inode_fetches},
30     {"BLUESKY_OPT_SYNC_FRONTENDS", &bluesky_options.sync_frontends},
31     {NULL, NULL}
32 };
33
34 /* BlueSky library initialization. */
35
36 void bluesky_store_init_s3(void);
37 void bluesky_store_init_kv(void);
38
39 /* Initialize the BlueSky library and dependent libraries. */
40 void bluesky_init(void)
41 {
42     g_thread_init(NULL);
43     bluesky_crypt_init();
44
45     for (int i = 0; option_table[i].env != NULL; i++) {
46         const char *val = getenv(option_table[i].env);
47         if (val != NULL) {
48             int v = atoi(val);
49             g_print("Option %s set to %d\n", option_table[i].env, v);
50             *option_table[i].option = atoi(val);
51         }
52     }
53
54     bluesky_store_init();
55     bluesky_store_init_kv();
56     bluesky_store_init_s3();
57 }