X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=src%2Fnepi%2Futil%2Fguid.py;h=45852118cc65036c978169c099cf909ede1249e0;hb=a62ad48360778748ee3d5ba65b14ea6eeb27c032;hp=3198e25b7334861369c6d06e20131894373dca33;hpb=497b7be348872efd00a41929825043b2dc2012c9;p=nepi.git diff --git a/src/nepi/util/guid.py b/src/nepi/util/guid.py index 3198e25b..45852118 100644 --- a/src/nepi/util/guid.py +++ b/src/nepi/util/guid.py @@ -1,18 +1,33 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- +# +# NEPI, a framework to manage network experiments +# Copyright (C) 2013 INRIA +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation; +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# Author: Alina Quereilhac +# FIXME: This class is not thread-safe. +# Should it be made thread-safe? class GuidGenerator(object): def __init__(self): - self._guids = list() + self._last_guid = 0 + # xxx_next_hiccup - this is used as a plain function, and only in ec.py def next(self, guid = None): - if guid != None: - if guid in self._guids: - raise RuntimeError("guid %d is already assigned" % guid) - else: - last_guid = 0 if len(self._guids) == 0 else self._guids[-1] - guid = last_guid + 1 - self._guids.append(guid) - self._guids.sort() + if guid == None: + guid = self._last_guid + 1 + + self._last_guid = self._last_guid if guid <= self._last_guid else guid + return guid