summaryrefslogtreecommitdiff
path: root/ot_mutex.c
diff options
context:
space:
mode:
authorDirk Engling <erdgeist@erdgeist.org>2008-12-06 00:41:12 +0000
committerDirk Engling <erdgeist@erdgeist.org>2008-12-06 00:41:12 +0000
commitcec9b447388c564c3786040d3c4c02c2391992c0 (patch)
tree12012ffd1ca0edc8acdf2649518ba4c10d1e5976 /ot_mutex.c
parentd46a8a5d06d862b4068ed6d70d288f6c2ef65a5d (diff)
downloadopentracker-cec9b447388c564c3786040d3c4c02c2391992c0.tar.gz
opentracker-cec9b447388c564c3786040d3c4c02c2391992c0.zip
Make mutex_lock_bucket_by_hash generic to any OT_BUCKET_COUNT
Diffstat (limited to 'ot_mutex.c')
-rw-r--r--ot_mutex.c11
1 files changed, 4 insertions, 7 deletions
diff --git a/ot_mutex.c b/ot_mutex.c
index b6bbd56..00d0668 100644
--- a/ot_mutex.c
+++ b/ot_mutex.c
@@ -13,6 +13,7 @@
/* Libowfat */
#include "byte.h"
#include "io.h"
+#include "uint32.h"
/* Opentracker */
#include "trackerlogic.h"
@@ -79,12 +80,10 @@ ot_vector *mutex_bucket_lock( int bucket ) {
}
ot_vector *mutex_bucket_lock_by_hash( ot_hash *hash ) {
- unsigned char *local_hash = hash[0];
- int bucket = ( local_hash[0] << 2 ) | ( local_hash[1] >> 6 );
+ int bucket = uint32_read( *hash ) % OT_BUCKET_COUNT;
/* Can block */
mutex_bucket_lock( bucket );
-
return all_torrents + bucket;
}
@@ -96,9 +95,7 @@ void mutex_bucket_unlock( int bucket ) {
}
void mutex_bucket_unlock_by_hash( ot_hash *hash ) {
- unsigned char *local_hash = hash[0];
- int bucket = ( local_hash[0] << 2 ) | ( local_hash[1] >> 6 );
- mutex_bucket_unlock( bucket );
+ mutex_bucket_unlock( uint32_read( *hash ) % OT_BUCKET_COUNT );
}
/* TaskQueue Magic */
@@ -319,4 +316,4 @@ void mutex_deinit( ) {
byte_zero( all_torrents, sizeof( all_torrents ) );
}
-const char *g_version_mutex_c = "$Source: /home/cvsroot/opentracker/ot_mutex.c,v $: $Revision: 1.13 $\n";
+const char *g_version_mutex_c = "$Source: /home/cvsroot/opentracker/ot_mutex.c,v $: $Revision: 1.14 $\n";