summaryrefslogtreecommitdiff
path: root/ot_fullscrape.c
diff options
context:
space:
mode:
authorerdgeist <>2007-11-16 00:23:42 +0000
committererdgeist <>2007-11-16 00:23:42 +0000
commit6458a37d82aef8e910b2aed4cf25333e211482ae (patch)
tree619db62da7168b8979ec61913128fcbbefa0e128 /ot_fullscrape.c
parentd3963803caab5b1cb30bb58b271dede1b731bbd8 (diff)
introducing multithreaded full scrape creation.
Diffstat (limited to 'ot_fullscrape.c')
-rw-r--r--ot_fullscrape.c41
1 files changed, 35 insertions, 6 deletions
diff --git a/ot_fullscrape.c b/ot_fullscrape.c
index 3c9540d..58e525f 100644
--- a/ot_fullscrape.c
+++ b/ot_fullscrape.c
@@ -5,6 +5,7 @@
5#include <sys/uio.h> 5#include <sys/uio.h>
6#include <stdio.h> 6#include <stdio.h>
7#include <string.h> 7#include <string.h>
8#include <pthread.h>
8 9
9/* Libowfat */ 10/* Libowfat */
10 11
@@ -23,14 +24,45 @@
23/* "d8:completei%zde10:downloadedi%zde10:incompletei%zdee" */ 24/* "d8:completei%zde10:downloadedi%zde10:incompletei%zdee" */
24#define OT_FULLSCRAPE_MAXENTRYLEN 100 25#define OT_FULLSCRAPE_MAXENTRYLEN 100
25 26
26size_t return_fullscrape_for_tracker( int *iovec_entries, struct iovec **iovector ) { 27/* Forward declaration */
28static void fullscrape_make( int *iovec_entries, struct iovec **iovector );
29
30/* This is the entry point into this worker thread
31 It grabs tasks from mutex_tasklist and delivers results back
32*/
33static void * fullscrape_worker( void * args) {
34 int iovec_entries;
35 struct iovec *iovector;
36
37 args = args;
38
39 while( 1 ) {
40 ot_taskid taskid = mutex_workqueue_poptask( OT_TASKTYPE_FULLSCRAPE );
41 fullscrape_make( &iovec_entries, &iovector );
42 if( mutex_workqueue_pushresult( taskid, iovec_entries, iovector ) )
43 iovec_free( &iovec_entries, &iovector );
44 }
45 return NULL;
46}
47
48void fullscrape_init( ) {
49 pthread_t thread_id;
50 pthread_create( &thread_id, NULL, fullscrape_worker, NULL );
51}
52
53void fullscrape_deliver( int64 socket ) {
54 mutex_workqueue_pushtask( socket, OT_TASKTYPE_FULLSCRAPE );
55}
56
57static void fullscrape_make( int *iovec_entries, struct iovec **iovector ) {
27 int bucket; 58 int bucket;
28 char *r, *re; 59 char *r, *re;
29 60
30 /* Setup return vector... */ 61 /* Setup return vector... */
31 *iovec_entries = 0; 62 *iovec_entries = 0;
63 *iovector = NULL;
32 if( !( r = iovec_increase( iovec_entries, iovector, OT_SCRAPE_CHUNK_SIZE ) ) ) 64 if( !( r = iovec_increase( iovec_entries, iovector, OT_SCRAPE_CHUNK_SIZE ) ) )
33 return 0; 65 return;
34 66
35 /* ... and pointer to end of current output buffer. 67 /* ... and pointer to end of current output buffer.
36 This works as a low watermark */ 68 This works as a low watermark */
@@ -76,7 +108,7 @@ size_t return_fullscrape_for_tracker( int *iovec_entries, struct iovec **iovecto
76 108
77 /* Release lock on current bucket and return */ 109 /* Release lock on current bucket and return */
78 mutex_bucket_unlock( bucket ); 110 mutex_bucket_unlock( bucket );
79 return 0; 111 return;
80 } 112 }
81 113
82 /* Adjust new end of output buffer */ 114 /* Adjust new end of output buffer */
@@ -93,7 +125,4 @@ size_t return_fullscrape_for_tracker( int *iovec_entries, struct iovec **iovecto
93 125
94 /* Release unused memory in current output buffer */ 126 /* Release unused memory in current output buffer */
95 iovec_fixlast( iovec_entries, iovector, OT_SCRAPE_CHUNK_SIZE - ( re - r ) ); 127 iovec_fixlast( iovec_entries, iovector, OT_SCRAPE_CHUNK_SIZE - ( re - r ) );
96
97 /* Return answer size */
98 return iovec_length( iovec_entries, iovector );
99} 128}