GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Description: Beanstalkd is a fast, distributed, in-memory workqueue service. Its interface is generic, but was designed for use in reducing the latency of page views in high-volume web applications by running most time-consuming tasks asynchronously.
Homepage: http://xph.us/software/beanstalkd/
Clone URL: git://github.com/kr/beanstalkd.git
Click here to lend your support to: beanstalkd and make a donation at www.pledgie.com !
Allocate the hash table at startup.

This fixes a segfault when no jobs have been submitted and something, for
instance a peek command, tries to look up a job.

This also eliminates a compare instruction every time a job is inserted.
kr (author)
Sat Aug 30 13:27:55 -0700 2008
commit  72760cadb6983b15bca87999eda885c951cc5f1c
tree    18207727bdf1c36c7e3724a01fcdc5eecca406e6
parent  aab5cfb0ed5fe3d8edffbccbc573b36366215449
...
238
239
240
 
241
242
243
...
238
239
240
241
242
243
244
0
@@ -238,6 +238,7 @@ main(int argc, char **argv)
0
     progname = argv[0];
0
     opts(argc, argv);
0
 
0
+ job_init();
0
     prot_init();
0
 
0
     r = make_server_socket(host_addr, port);
0
...
38
39
40
41
42
43
44
45
46
47
48
49
50
51
...
232
233
234
 
 
 
 
 
 
 
 
 
...
38
39
40
 
 
 
 
 
 
 
 
41
42
43
...
224
225
226
227
228
229
230
231
232
233
234
235
0
@@ -38,14 +38,6 @@ store_job(job j)
0
 {
0
     int index=0;
0
 
0
- if (all_jobs == NULL) {
0
- all_jobs = calloc(NUM_JOB_BUCKETS, sizeof(job));
0
- if (all_jobs == NULL) {
0
- twarnx("Failed to allocate %d hash buckets", NUM_JOB_BUCKETS);
0
- return NULL;
0
- }
0
- }
0
-
0
     index = _get_job_hash_index(j->id);
0
 
0
     j->ht_next = all_jobs[index];
0
@@ -232,3 +224,12 @@ total_jobs()
0
 {
0
     return next_id - 1;
0
 }
0
+
0
+void
0
+job_init()
0
+{
0
+ all_jobs = calloc(NUM_JOB_BUCKETS, sizeof(job));
0
+ if (!all_jobs) {
0
+ twarnx("Failed to allocate %d hash buckets", NUM_JOB_BUCKETS);
0
+ }
0
+}
0
...
75
76
77
 
 
78
...
75
76
77
78
79
80
0
@@ -75,4 +75,6 @@ void job_insert(job head, job j);
0
 
0
 unsigned long long int total_jobs();
0
 
0
+void job_init();
0
+
0
 #endif /*job_h*/

Comments

    No one has commented yet.