svn commit: samba r6687 - in branches/SAMBA_4_0/source/lib: .

tridge at samba.org tridge at samba.org
Tue May 10 01:55:18 GMT 2005


Author: tridge
Date: 2005-05-10 01:55:18 +0000 (Tue, 10 May 2005)
New Revision: 6687

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=6687

Log:
added a idr helper function for creating random IDs

Modified:
   branches/SAMBA_4_0/source/lib/idtree.c


Changeset:
Modified: branches/SAMBA_4_0/source/lib/idtree.c
===================================================================
--- branches/SAMBA_4_0/source/lib/idtree.c	2005-05-10 01:32:43 UTC (rev 6686)
+++ branches/SAMBA_4_0/source/lib/idtree.c	2005-05-10 01:55:18 UTC (rev 6687)
@@ -345,6 +345,24 @@
 }
 
 /*
+  allocate a new id randomly in the given range
+*/
+int idr_get_new_random(struct idr_context *idp, void *ptr, int limit)
+{
+	int id;
+
+	/* first try a random starting point in the whole range, and if that fails,
+	   then start randomly in the bottom half of the range. This can only
+	   fail if the range is over half full */
+	id = idr_get_new_above(idp, ptr, 1+(generate_random() % limit), limit);
+	if (id == -1) {
+		id = idr_get_new_above(idp, ptr, 1+(generate_random()%(limit/2)), limit);
+	}
+	
+	return id;
+}
+
+/*
   find a pointer value previously set with idr_get_new given an id
 */
 void *idr_find(struct idr_context *idp, int id)



More information about the samba-cvs mailing list