diff options
| author | erdgeist <> | 2008-12-06 00:41:12 +0000 |
|---|---|---|
| committer | erdgeist <> | 2008-12-06 00:41:12 +0000 |
| commit | 256f2c6f983ec346c00addfb3d8c6f5b8622f330 (patch) | |
| tree | 843848ed8ece632b97705dc671578879e0f9dbca | |
| parent | 258cae746fd81cb0880bfc459b44792468f3b0ac (diff) | |
Make mutex_lock_bucket_by_hash generic to any OT_BUCKET_COUNT
| -rw-r--r-- | ot_mutex.c | 9 |
1 files changed, 3 insertions, 6 deletions
| @@ -13,6 +13,7 @@ | |||
| 13 | /* Libowfat */ | 13 | /* Libowfat */ |
| 14 | #include "byte.h" | 14 | #include "byte.h" |
| 15 | #include "io.h" | 15 | #include "io.h" |
| 16 | #include "uint32.h" | ||
| 16 | 17 | ||
| 17 | /* Opentracker */ | 18 | /* Opentracker */ |
| 18 | #include "trackerlogic.h" | 19 | #include "trackerlogic.h" |
| @@ -79,12 +80,10 @@ ot_vector *mutex_bucket_lock( int bucket ) { | |||
| 79 | } | 80 | } |
| 80 | 81 | ||
| 81 | ot_vector *mutex_bucket_lock_by_hash( ot_hash *hash ) { | 82 | ot_vector *mutex_bucket_lock_by_hash( ot_hash *hash ) { |
| 82 | unsigned char *local_hash = hash[0]; | 83 | int bucket = uint32_read( *hash ) % OT_BUCKET_COUNT; |
| 83 | int bucket = ( local_hash[0] << 2 ) | ( local_hash[1] >> 6 ); | ||
| 84 | 84 | ||
| 85 | /* Can block */ | 85 | /* Can block */ |
| 86 | mutex_bucket_lock( bucket ); | 86 | mutex_bucket_lock( bucket ); |
| 87 | |||
| 88 | return all_torrents + bucket; | 87 | return all_torrents + bucket; |
| 89 | } | 88 | } |
| 90 | 89 | ||
| @@ -96,9 +95,7 @@ void mutex_bucket_unlock( int bucket ) { | |||
| 96 | } | 95 | } |
| 97 | 96 | ||
| 98 | void mutex_bucket_unlock_by_hash( ot_hash *hash ) { | 97 | void mutex_bucket_unlock_by_hash( ot_hash *hash ) { |
| 99 | unsigned char *local_hash = hash[0]; | 98 | mutex_bucket_unlock( uint32_read( *hash ) % OT_BUCKET_COUNT ); |
| 100 | int bucket = ( local_hash[0] << 2 ) | ( local_hash[1] >> 6 ); | ||
| 101 | mutex_bucket_unlock( bucket ); | ||
| 102 | } | 99 | } |
| 103 | 100 | ||
| 104 | /* TaskQueue Magic */ | 101 | /* TaskQueue Magic */ |
