SpectMorph

lib/smjobqueue.hh

00001 /*
00002  * Copyright (C) 2010 Stefan Westerfeld
00003  *
00004  * This library is free software; you can redistribute it and/or modify it
00005  * under the terms of the GNU Lesser General Public License as published by the
00006  * Free Software Foundation; either version 3 of the License, or (at your
00007  * option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful, but WITHOUT
00010  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00011  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
00012  * for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public License
00015  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 
00018 #ifndef SPECTMORPH_JOB_QUEUE_HH
00019 #define SPECTMORPH_JOB_QUEUE_HH
00020 
00021 #include <stdlib.h>
00022 #include <unistd.h>
00023 #include <stdio.h>
00024 #include <sys/types.h>
00025 #include <sys/wait.h>
00026 
00027 #include <string>
00028 #include <vector>
00029 
00030 namespace SpectMorph
00031 {
00032 
00033 class JobQueue
00034 {
00035   size_t             max_jobs;
00036   std::vector<pid_t> active_pids;
00037   bool               all_exit_ok;
00038 
00039   void wait_for_one();
00040 
00041 public:
00042   JobQueue (size_t max_jobs = 1);
00043 
00044   bool run (const std::string& cmdline);
00045   bool wait_for_all();
00046 
00047   ~JobQueue();
00048 };
00049 
00050 } // namespace SpectMorph
00051 
00052 #endif
 All Classes Functions Variables Enumerations Enumerator