From 2df09905f5540fee096d48a92cb0c42558498a12 Mon Sep 17 00:00:00 2001 From: erdgeist <> Date: Fri, 2 Jan 2009 08:57:53 +0000 Subject: * opentracker now drops permissions in correct order and really chroots() if ran as root * lock passing between add_peer_to_torrent and return_peers_for_torrent is now avoided by providing a more general add_peer_to_torrent_and_return_peers function that can be used with NULL parameters to not return any peers (in sync case) * in order to keep a fast overview how many torrents opentracker maintains, every mutex_bucket_unlock operation expects an additional integer parameter that tells ot_mutex.c how many torrents have been added or removed. A function mutex_get_torrent_count has been introduced. --- ot_mutex.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'ot_mutex.c') diff --git a/ot_mutex.c b/ot_mutex.c index a28144b..8094e99 100644 --- a/ot_mutex.c +++ b/ot_mutex.c @@ -24,6 +24,7 @@ /* Our global all torrents list */ static ot_vector all_torrents[OT_BUCKET_COUNT]; +static size_t g_torrent_count; /* Bucket Magic */ static int bucket_locklist[ OT_MAX_THREADS ]; @@ -87,15 +88,24 @@ ot_vector *mutex_bucket_lock_by_hash( ot_hash *hash ) { return all_torrents + bucket; } -void mutex_bucket_unlock( int bucket ) { +void mutex_bucket_unlock( int bucket, int delta_torrentcount ) { pthread_mutex_lock( &bucket_mutex ); bucket_remove( bucket ); + g_torrent_count += delta_torrentcount; pthread_cond_broadcast( &bucket_being_unlocked ); pthread_mutex_unlock( &bucket_mutex ); } -void mutex_bucket_unlock_by_hash( ot_hash *hash ) { - mutex_bucket_unlock( uint32_read_big( (char*)*hash ) >> OT_BUCKET_COUNT_SHIFT ); +void mutex_bucket_unlock_by_hash( ot_hash *hash, int delta_torrentcount ) { + mutex_bucket_unlock( uint32_read_big( (char*)*hash ) >> OT_BUCKET_COUNT_SHIFT, delta_torrentcount ); +} + +size_t mutex_get_torrent_count( ) { + size_t torrent_count; + pthread_mutex_lock( &bucket_mutex ); + torrent_count = g_torrent_count; + pthread_mutex_unlock( &bucket_mutex ); + return torrent_count; } /* TaskQueue Magic */ -- cgit v1.2.3