def METHOD_NAME(self, queue):
    obj = self.session.query(self.queue_cls) \
        .filter(self.queue_cls.name == queue).first()
    if not obj:
        with _MUTEX:
            obj = self.session.query(self.queue_cls) \
                .filter(self.queue_cls.name == queue).first()
            if obj:
                # Queue was created while we were waiting to
                # acquire the lock.
                return obj
            obj = self.queue_cls(queue)
            self.session.add(obj)
            try:
                self.session.commit()
            except OperationalError:
                self.session.rollback()
    return obj