This file is part of polypaudio.
polypaudio is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published
+ it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.
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
+ You should have received a copy of the GNU Lesser General Public License
along with polypaudio; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA.
#include "cpulimit.h"
#include "util.h"
+#include "log.h"
-/* Utilize this much CPU time at most */
+/* Utilize this much CPU time at maximum */
#define CPUTIME_PERCENT 70
-#define CPUTIME_INTERVAL_SOFT (5)
+#define CPUTIME_INTERVAL_SOFT (10)
#define CPUTIME_INTERVAL_HARD (2)
static time_t last_time = 0;
if (phase == PHASE_IDLE) {
time_t now;
+
+#ifdef PRINT_CPU_LOAD
char t[256];
+#endif
time(&now);
+#ifdef PRINT_CPU_LOAD
snprintf(t, sizeof(t), "Using %0.1f%% CPU\n", (double)CPUTIME_INTERVAL_SOFT/(now-last_time)*100);
write_err(t);
+#endif
if (CPUTIME_INTERVAL_SOFT >= ((now-last_time)*(double)CPUTIME_PERCENT/100)) {
static const char c = 'X';
}
int pa_cpu_limit_init(struct pa_mainloop_api *m) {
- int r;
struct sigaction sa;
assert(m && !api && !io_event && the_pipe[0] == -1 && the_pipe[1] == -1);
time(&last_time);
if (pipe(the_pipe) < 0) {
- fprintf(stderr, "pipe() failed: %s\n", strerror(errno));
+ pa_log(__FILE__": pipe() failed: %s\n", strerror(errno));
return -1;
}
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_RESTART;
- r = sigaction(SIGXCPU, &sa, &sigaction_prev);
- assert(r >= 0);
+ if (sigaction(SIGXCPU, &sa, &sigaction_prev) < 0) {
+ pa_cpu_limit_done();
+ return -1;
+ }
installed = 1;