]> code.delx.au - pulseaudio/blobdiff - polyp/cpulimit.c
Make the whole stuff LGPL only
[pulseaudio] / polyp / cpulimit.c
index 822e1f3320379815b148cd944059038781a99654..fcbbaf3d2af089530360f759272f7348cb44044e 100644 (file)
@@ -4,7 +4,7 @@
   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.
  
@@ -13,7 +13,7 @@
   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;
@@ -77,12 +78,17 @@ static void signal_handler(int sig) {
 
     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';
@@ -115,14 +121,13 @@ static void callback(struct pa_mainloop_api*m, struct pa_io_event*e, int fd, enu
 }
 
 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;
     }
 
@@ -141,8 +146,10 @@ int pa_cpu_limit_init(struct pa_mainloop_api *m) {
     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;