comparison system/System.cpp @ 150:4b2ea82fd0ed

* Reorganising code base. This revision probably should compile once more.
author Chris Cannam
date Mon, 31 Jul 2006 14:05:22 +0000
parents
children 04baa690f90d
comparison
equal deleted inserted replaced
149:3e4c384f518e 150:4b2ea82fd0ed
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2
3 /*
4 Sonic Visualiser
5 An audio file viewer and annotation editor.
6 Centre for Digital Music, Queen Mary, University of London.
7 This file copyright 2006 Chris Cannam.
8
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License as
11 published by the Free Software Foundation; either version 2 of the
12 License, or (at your option) any later version. See the file
13 COPYING included with this distribution for more information.
14 */
15
16 #include "System.h"
17
18 #ifndef _WIN32
19 #include <signal.h>
20 #endif
21
22 #include <iostream>
23
24 #ifdef _WIN32
25
26 extern "C" {
27
28 void usleep(unsigned long usec)
29 {
30 ::Sleep(usec / 1000);
31 }
32
33 void gettimeofday(struct timeval *tv, void *tz)
34 {
35 union {
36 long long ns100;
37 FILETIME ft;
38 } now;
39
40 ::GetSystemTimeAsFileTime(&now.ft);
41 tv->tv_usec = (long)((now.ns100 / 10LL) % 1000000LL);
42 tv->tv_sec = (long)((now.ns100 - 116444736000000000LL) / 10000000LL);
43 }
44
45 }
46
47 #endif
48
49 ProcessStatus
50 GetProcessStatus(int pid)
51 {
52 #ifdef _WIN32
53 HANDLE handle = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, pid);
54 if (!handle) {
55 return ProcessNotRunning;
56 } else {
57 CloseHandle(handle);
58 return ProcessRunning;
59 }
60 #else
61 if (kill(getpid(), 0) == 0) {
62 if (kill(pid, 0) == 0) {
63 return ProcessRunning;
64 } else {
65 return ProcessNotRunning;
66 }
67 } else {
68 return UnknownProcessStatus;
69 }
70 #endif
71 }
72
73 double mod(double x, double y) { return x - (y * floor(x / y)); }
74 float modf(float x, float y) { return x - (y * floorf(x / y)); }
75
76 double princarg(double a) { return mod(a + M_PI, -2 * M_PI) + M_PI; }
77 float princargf(float a) { return modf(a + M_PI, -2 * M_PI) + M_PI; }
78