#=============================================================================
#  
#  Init_semaphore - implementation of Init_semaphore for ../bin/semaphore
#  semaphore - a Korn shell implementation of a counting semaphore
#  Copyright (C) 2004 Intel Corporation
#  
#  This program is free software; you can redistribute it and/or modify it
#  under the terms of the GNU General Public License as published by the Free
#  Software Foundation; either version 2 of the License, or (at your option)
#  any later version.
#  
#  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 http://www.gnu.org/copyleft/gpl.html or
#  write to:
#  
#  The Free Software Foundation, Inc.,
#  59 Temple Place
#  Suite 330, Boston, MA 02111-1307
#  USA
#  
#  Author:
#  
#  John Spurgeon
#  5200 NE Elam Young Parkway
#  Hillsboro, OR 97124
#  
#  john.p.spurgeon@intel.com
#  
#=============================================================================

Init_semaphore()
{
	# Init_semaphore sets the number of resources for a semaphore.

	local FUNC_NAME=Init_semaphore
	${TRACE:-trace $FUNC_NAME $@}

	local semaphore=$1
	integer num_resources=$2

	if ! is_initialized $semaphore
	then
		if ! create_directories $semaphore
		then
			return 1
		fi
	fi
	${INFO:-info "Initializing semaphore $semaphore to $num_resources..."}
	set_num_resources $semaphore $num_resources
	return $?
}
