#define XERR
#include "compiler.ih"

void Compiler::compileJobs()
{
    CompileFork compileFork;

    do
    {
        {   // this block exists to end the lock by lg:
            lock_guard lg{ d_mutex};
                                                // stop compiling on error or
            if (not d_OK or not nextSource())   // when all done
                return;

            compileFork.reset(d_fileIter++->name);  // get the next source

            if (g_options.debug())
                log() << " compiling " << compileFork.source() << '\n';
        }

        compileFork.fork();                         // compile 'source'
    }
    while (compileFork.ret() == 0);                 // continue while 
                                                    // compilation OK

    {
        lock_guard lg{ d_mutex };
        if (not d_OK)                               // other thread found an
            return;                                 // error: done

        d_OK = false;                               // error in this thread
    }

    log() << "compilation of " << compileFork.source() << " failed.\n";
    errorMessage(compileFork);
}

