aboutsummaryrefslogtreecommitdiffstats
path: root/manual/appnotes.sh
blob: 0ae52862ec1c0cf76af28863e4c7200d16f8da07 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/bin/bash

set -ex
for job in APPNOTE_010_Verilog_to_BLIF APPNOTE_011_Design_Investigation APPNOTE_012_Verilog_to_BTOR
do
	[ -f $job.ok -a $job.ok -nt $job.tex ] && continue
	if [ -f $job/make.sh ]; then
		cd $job
		bash make.sh
		cd ..
	fi
	old_md5=$([ -f $job.aux ] && md5sum < $job.aux || true)
	while
		pdflatex -shell-escape -halt-on-error $job.tex || exit
		new_md5=$(md5sum < $job.aux)
		[ "$old_md5" != "$new_md5" ]
	do
		old_md5="$new_md5"
	done
	touch $job.ok
done
color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
#
# Copyright (c) 2005 XenSource Ltd.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of version 2.1 of the GNU Lesser General Public
# License as published by the Free Software Foundation.
#
# This library 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#

#
# Serialisation
#

LOCK_SLEEPTIME=1
LOCK_SPINNING_RETRIES=5
LOCK_RETRIES=100
LOCK_BASEDIR=/var/run/xen-hotplug


claim_lock()
{
  local lockdir="$LOCK_BASEDIR/$1"
  mkdir -p "$LOCK_BASEDIR"
  _claim_lock "$lockdir"
}


release_lock()
{
  _release_lock "$LOCK_BASEDIR/$1"
}


_claim_lock()
{
  local lockdir="$1"
  local owner=$(_lock_owner "$lockdir")
  local retries=0

  while [ $retries -lt $LOCK_RETRIES ]
  do
    mkdir "$lockdir" 2>/dev/null && trap "release_lock $1; sigerr" ERR &&
      _update_lock_info "$lockdir" && return

    local new_owner=$(_lock_owner "$lockdir")
    if [ "$new_owner" != "$owner" ]
    then
      owner="$new_owner"
      retries=0
    fi

    if [ $retries -gt $LOCK_SPINNING_RETRIES ]
    then
      sleep $LOCK_SLEEPTIME
    else
      sleep 0
    fi
    retries=$(($retries + 1))
  done
  _steal_lock "$lockdir"
}


_release_lock()
{
  trap sigerr ERR
  rm -rf "$1" 2>/dev/null || true
}


_steal_lock()
{
  local lockdir="$1"
  local owner=$(cat "$lockdir/owner" 2>/dev/null || echo "unknown")
  log err "Forced to steal lock on $lockdir from $owner!"
  _release_lock "$lockdir"
  _claim_lock "$lockdir"
}


_lock_owner()
{
  cat "$1/owner" 2>/dev/null || echo "unknown"
}


_update_lock_info()
{
  echo "$$: $0" >"$1/owner"
}