diff --git a/atom b/atom index 6a33755..3d241b5 100755 --- a/atom +++ b/atom @@ -1230,41 +1230,8 @@ encodeFile::vorbis() { progressSpin } -checkFinished() { - #retrieve info from finished transcodeFile() - #update counters / metadata - : -} - -checkLoad() { - #if load > threshold - # decrease concurrency - #elif load < threshold - # increase concurrency - #fi - : -} - -readUserInput() { - #read + / - / q(uit) / p(ause) - #initiate shutdown / change load threshold / SIGSTOP all children / SIGCONT all children - : -} - -transcodeLauncher() { - checkLoad - checkFinished - #until running processes < max processes - #do - checkLoad - checkFinished - readUserInput - #done - transcodeFile & - #update counter / metadata -} - worker() { + trap "kill -USR1 $masterpid" EXIT set +e while : do @@ -1392,12 +1359,13 @@ master() { 'work') if [ -n "$quit" ] then + dyingworker=${workers[workerid]} + unset workers[workerid] eval echo AtOM:Die '>&'$((100+workerid)) - wait ${workers[workerid]} + wait $dyingworker eval $((100+workerid))'>&-' eval $((200+workerid))'<&-' rm "$tempdir"/worker${workerid}{in,out} - unset workers[workerid] elif (( active < concurrency )) then echo ' @@ -1457,12 +1425,13 @@ master() { read -u4 ready if (( remaining == 0 )) then + dyingworker=${workers[workerid]} + unset workers[workerid] eval echo AtOM:Die '>&'$((100+workerid)) - wait ${workers[workerid]} + wait $dyingworker eval $((100+workerid))'>&-' eval $((200+workerid))'<&-' rm "$tempdir"/worker${workerid}{in,out} - unset workers[workerid] continue elif (( ready == 0 )) then @@ -1475,12 +1444,13 @@ master() { fi eval echo '"$line" >&'$((100+workerid)) else + dyingworker=${workers[workerid]} + unset workers[workerid] eval echo AtOM:Die '>&'$((100+workerid)) - wait ${workers[workerid]} + wait $dyingworker eval $((100+workerid))'>&-' eval $((200+workerid))'<&-' rm "$tempdir"/worker${workerid}{in,out} - unset workers[workerid] fi ;; ?(f)'inished') @@ -1538,6 +1508,21 @@ master() { fi } +checkworkers() { + for key in ${!workers[@]} + do + if ! kill -0 ${workers[key]} + then + worker $key \ + <"$tempdir"/worker${key}in \ + >"$tempdir"/worker${key}out & + workers[key]=$! + eval exec $((100+key))'>"$tempdir"/worker${key}in' + eval exec $((200+key))'<"$tempdir"/worker${key}out' + fi + done +} + #UI if [ ! -f ~/.atom/atom.cfg ] @@ -1980,6 +1965,8 @@ done echo 'COMMIT;' >&3 echo -e "\rCreated ${count:-0} tasks for $filecount files (${copies:-0} immediate copies)" +masterpid=$$ +trap checkworkers USR1 rm -f "$tempdir"/worker* concurrency=$(( maxload / 2 )) (( concurrency )) || concurrency=1