aboutsummaryrefslogtreecommitdiffstats
path: root/openbsc/src/transaction.c
diff options
context:
space:
mode:
authorSylvain Munaut <tnt@246tNt.com>2009-12-24 13:26:17 +0100
committerHarald Welte <laforge@netfilter.org>2009-12-24 15:09:55 +0100
commit926fcecc2ddc78aee4305d50972d01906b96756c (patch)
tree2972a4ea27bddf3e2e7366fa3a7517254c34eb6e /openbsc/src/transaction.c
parentd0cf7ba687e99a46eabbfe0685cf7fd8f09c8a94 (diff)
transaction: Change id allocator method to be 'circular'
The idea is to find the highest used id and try to get the next. This way when there are transactions back to back with an overlap, we go 0 1 2 3 4 5 6 0 1 2 ... Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Diffstat (limited to 'openbsc/src/transaction.c')
-rw-r--r--openbsc/src/transaction.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/openbsc/src/transaction.c b/openbsc/src/transaction.c
index e49f75b28..c972037be 100644
--- a/openbsc/src/transaction.c
+++ b/openbsc/src/transaction.c
@@ -119,7 +119,7 @@ int trans_assign_trans_id(struct gsm_subscriber *subscr,
struct gsm_network *net = subscr->net;
struct gsm_trans *trans;
unsigned int used_tid_bitmask = 0;
- int i;
+ int i, j, h;
if (ti_flag)
ti_flag = 0x8;
@@ -133,9 +133,14 @@ int trans_assign_trans_id(struct gsm_subscriber *subscr,
used_tid_bitmask |= (1 << trans->transaction_id);
}
+ /* find a new one, trying to go in a 'circular' pattern */
+ for (h = 6; h > 0; h--)
+ if (used_tid_bitmask & (1 << (h | ti_flag)))
+ break;
for (i = 0; i < 7; i++) {
- if ((used_tid_bitmask & (1 << (i | ti_flag))) == 0)
- return i | ti_flag;
+ j = ((h + i) % 7) | ti_flag;
+ if ((used_tid_bitmask & (1 << j)) == 0)
+ return j;
}
return -1;