[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ns] enqueue & dequeue usage at OTCL level ?!



Hi ,
Is it possible to use the enqueue and dequeue methode of a DropTail object
directly in a OTCL class ?
I am writing the bellow source but have an error because I need a pointer to
a Packet objetc to use enqueue and dequeue.

Does anybody used signaling Agent for blocking queue (typicaly semaphore) ?

Thanks.

# Classes definition
# the semaphore class will allow user to define a ressources queue which can
control transition
# between queue or node.# In this classe 2 methods will be defined, the
Djikstra classical one,
# P() and V()

Class AbSemaphor
AbSemaphor instproc init {multiplicity} {
#	$self next
	$self instvar cpt_
	set cpt_ $multiplicity
	puts "creation d'un sem avec multiplicity = $multiplicity \n"
	# handle a queue for the non satisfied request.
	$self instvar semaQueue
	# declaration of Queue not allowd. Use Queue/Type ...
	set semaQueue [new Queue/DropTail]
	# Fix the queue limit to the requested multipicite of the Semaphore
	$semaQueue set qlim_ $multiplicity
	# par prudence de changement dans ns on force la queue a etre non
bloquante.
	$semaQueue set blocked_ 0
}

AbSemaphor instproc P {} {
	$self instvar cpt_ semaQueue
	if {$cpt_ > 0} {
		puts " Give a token because cpt_= $cpt_ "
		# The available nb of ressource is > 0 then we can give one and update
		# the counter cpt
		set cpt_ [expr $cpt_ - 1]
		# return 1 to say OK
		return 1
	} else {
		puts " Non satisfied request because cpt_=$cpt_\n"
		# enque the request in a FIFO
		set p [new Packet]
		semaQueue enque p
		# return a false to say that it does not work
		return 0
	}
}


----------------- Error ....
 Non satisfied request because cpt_=0

invalid command name "Packet"
    while executing
"Packet create _o14 "
    invoked from within
"catch "$className create $o $args" msg"
    (procedure "new" line 3)
    invoked from within
"new Packet"
    (procedure "_o10" line 13)
    (AbSemaphor P line 13)
    invoked from within
"$a P"
    (file "Semaphor.tcl" line 66)
-------------------------------
--------------------
Ahmad BADRAH   /-/ abadrah@tachys.com /-/ phone: +33(0)4 9294 4818
Performance Modelling Architect
Tachys Technologies  /-/  Les Algorithmes, ABS BP 29
06901 Sophia-Antipolis Cedex  /-/  http://www.tachys.com