diff options
Diffstat (limited to 'trackerlogic.c')
| -rw-r--r-- | trackerlogic.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/trackerlogic.c b/trackerlogic.c index 477c4a6..b0b7f4e 100644 --- a/trackerlogic.c +++ b/trackerlogic.c | |||
| @@ -20,6 +20,7 @@ | |||
| 20 | #include "ot_ip.h" | 20 | #include "ot_ip.h" |
| 21 | #include "ot_livesync.h" | 21 | #include "ot_livesync.h" |
| 22 | #include "ot_mutex.h" | 22 | #include "ot_mutex.h" |
| 23 | #include "ot_workqueue.h" | ||
| 23 | #include "ot_random.h" | 24 | #include "ot_random.h" |
| 24 | #include "ot_stats.h" | 25 | #include "ot_stats.h" |
| 25 | #include "ot_udp.h" | 26 | #include "ot_udp.h" |
| @@ -560,6 +561,7 @@ void trackerlogic_init(void) { | |||
| 560 | 561 | ||
| 561 | /* Initialise background worker threads */ | 562 | /* Initialise background worker threads */ |
| 562 | mutex_init(); | 563 | mutex_init(); |
| 564 | workqueue_init(); | ||
| 563 | clean_init(); | 565 | clean_init(); |
| 564 | fullscrape_init(); | 566 | fullscrape_init(); |
| 565 | accesslist_init(); | 567 | accesslist_init(); |
| @@ -567,6 +569,35 @@ void trackerlogic_init(void) { | |||
| 567 | stats_init(); | 569 | stats_init(); |
| 568 | } | 570 | } |
| 569 | 571 | ||
| 572 | int workstruct_init(struct ot_workstruct *ws) { | ||
| 573 | memset(ws, 0, sizeof(*ws)); | ||
| 574 | ws->inbuf = malloc(G_INBUF_SIZE); | ||
| 575 | ws->outbuf = malloc(G_OUTBUF_SIZE); | ||
| 576 | #ifdef _DEBUG_HTTPERROR | ||
| 577 | ws->debugbuf = malloc(G_DEBUGBUF_SIZE); | ||
| 578 | #endif | ||
| 579 | if (!ws->inbuf || !ws->outbuf) | ||
| 580 | return -1; | ||
| 581 | |||
| 582 | /* Picking which peers to hand out starts here, so two workers seeded alike | ||
| 583 | would hand out alike */ | ||
| 584 | random_bytes(ws->rand48_state, sizeof(ws->rand48_state)); | ||
| 585 | |||
| 586 | stats_counters_register(ws); | ||
| 587 | return 0; | ||
| 588 | } | ||
| 589 | |||
| 590 | void workstruct_deinit(struct ot_workstruct *ws) { | ||
| 591 | /* The tally goes to the global before this struct goes out of scope */ | ||
| 592 | stats_counters_retire(ws); | ||
| 593 | |||
| 594 | free(ws->inbuf); | ||
| 595 | free(ws->outbuf); | ||
| 596 | #ifdef _DEBUG_HTTPERROR | ||
| 597 | free(ws->debugbuf); | ||
| 598 | #endif | ||
| 599 | } | ||
| 600 | |||
| 570 | void trackerlogic_deinit(void) { | 601 | void trackerlogic_deinit(void) { |
| 571 | int delta_torrentcount = 0; | 602 | int delta_torrentcount = 0; |
| 572 | size_t bucket, j; | 603 | size_t bucket, j; |
| @@ -594,5 +625,6 @@ void trackerlogic_deinit(void) { | |||
| 594 | } | 625 | } |
| 595 | 626 | ||
| 596 | /* Release mutexes */ | 627 | /* Release mutexes */ |
| 628 | workqueue_deinit(); | ||
| 597 | mutex_deinit(); | 629 | mutex_deinit(); |
| 598 | } | 630 | } |
