Listing 5 V_semaphore()
{
# V_semaphore effectively increments the count or value of a semaphore.
# The function returns one semaphore resource iff $pid currently has
# one; otherwise the semaphore's number of resources is incremented by
# one.
local FUNC_NAME=V_semaphore
${TRACE:-trace $FUNC_NAME $@}
local semaphore=$1
integer num_resources=$2
integer pid=$3
integer resource_num=0
assert_semaphore $semaphore
${INFO:-info "Trying to return a resource to semaphore $semaphore ..."}
for resource_num in $(get_busy_resources $semaphore)
do
if return_resource $semaphore $resource_num $pid
then
${INFO:-info "PID $pid returned resource $resource_num."}
return 0
fi
done
return 1
} |