diff options
Diffstat (limited to 'ot_mutex.c')
-rw-r--r-- | ot_mutex.c | 16 |
1 files changed, 13 insertions, 3 deletions
@@ -24,6 +24,7 @@ | |||
24 | 24 | ||
25 | /* Our global all torrents list */ | 25 | /* Our global all torrents list */ |
26 | static ot_vector all_torrents[OT_BUCKET_COUNT]; | 26 | static ot_vector all_torrents[OT_BUCKET_COUNT]; |
27 | static size_t g_torrent_count; | ||
27 | 28 | ||
28 | /* Bucket Magic */ | 29 | /* Bucket Magic */ |
29 | static int bucket_locklist[ OT_MAX_THREADS ]; | 30 | static int bucket_locklist[ OT_MAX_THREADS ]; |
@@ -87,15 +88,24 @@ ot_vector *mutex_bucket_lock_by_hash( ot_hash *hash ) { | |||
87 | return all_torrents + bucket; | 88 | return all_torrents + bucket; |
88 | } | 89 | } |
89 | 90 | ||
90 | void mutex_bucket_unlock( int bucket ) { | 91 | void mutex_bucket_unlock( int bucket, int delta_torrentcount ) { |
91 | pthread_mutex_lock( &bucket_mutex ); | 92 | pthread_mutex_lock( &bucket_mutex ); |
92 | bucket_remove( bucket ); | 93 | bucket_remove( bucket ); |
94 | g_torrent_count += delta_torrentcount; | ||
93 | pthread_cond_broadcast( &bucket_being_unlocked ); | 95 | pthread_cond_broadcast( &bucket_being_unlocked ); |
94 | pthread_mutex_unlock( &bucket_mutex ); | 96 | pthread_mutex_unlock( &bucket_mutex ); |
95 | } | 97 | } |
96 | 98 | ||
97 | void mutex_bucket_unlock_by_hash( ot_hash *hash ) { | 99 | void mutex_bucket_unlock_by_hash( ot_hash *hash, int delta_torrentcount ) { |
98 | mutex_bucket_unlock( uint32_read_big( (char*)*hash ) >> OT_BUCKET_COUNT_SHIFT ); | 100 | mutex_bucket_unlock( uint32_read_big( (char*)*hash ) >> OT_BUCKET_COUNT_SHIFT, delta_torrentcount ); |
101 | } | ||
102 | |||
103 | size_t mutex_get_torrent_count( ) { | ||
104 | size_t torrent_count; | ||
105 | pthread_mutex_lock( &bucket_mutex ); | ||
106 | torrent_count = g_torrent_count; | ||
107 | pthread_mutex_unlock( &bucket_mutex ); | ||
108 | return torrent_count; | ||
99 | } | 109 | } |
100 | 110 | ||
101 | /* TaskQueue Magic */ | 111 | /* TaskQueue Magic */ |