2008-08-06 18:36:30 +00:00
|
|
|
// This file is part of BOINC.
|
2005-01-20 23:22:22 +00:00
|
|
|
// http://boinc.berkeley.edu
|
2008-08-06 18:36:30 +00:00
|
|
|
// Copyright (C) 2008 University of California
|
2004-11-14 08:29:32 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is free software; you can redistribute it and/or modify it
|
|
|
|
// under the terms of the GNU Lesser General Public License
|
|
|
|
// as published by the Free Software Foundation,
|
|
|
|
// either version 3 of the License, or (at your option) any later version.
|
2003-07-02 20:57:59 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
2005-01-20 23:22:22 +00:00
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// See the GNU Lesser General Public License for more details.
|
2002-04-30 22:22:54 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2003-07-02 02:02:18 +00:00
|
|
|
#ifndef UTIL_H
|
|
|
|
#define UTIL_H
|
|
|
|
|
2003-06-09 23:50:49 +00:00
|
|
|
#include <cstdlib>
|
2003-08-21 23:27:57 +00:00
|
|
|
#include <ctime>
|
|
|
|
#include <cmath>
|
2003-08-22 18:51:53 +00:00
|
|
|
#include <cctype>
|
2003-08-21 23:27:57 +00:00
|
|
|
#include <cstring>
|
2003-08-27 23:35:44 +00:00
|
|
|
#include <algorithm>
|
2003-09-02 23:26:38 +00:00
|
|
|
#include <string>
|
2007-01-23 22:29:19 +00:00
|
|
|
#include <vector>
|
2003-06-10 18:50:43 +00:00
|
|
|
|
2006-06-15 18:19:06 +00:00
|
|
|
#ifdef HAVE_PTHREAD
|
|
|
|
#include <pthread.h>
|
|
|
|
#endif
|
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
extern double dtime();
|
2005-04-04 06:02:36 +00:00
|
|
|
extern double dday();
|
2003-03-11 22:18:01 +00:00
|
|
|
extern void boinc_sleep(double);
|
2007-01-23 22:29:19 +00:00
|
|
|
extern void push_unique(std::string, std::vector<std::string>&);
|
2006-09-26 16:22:36 +00:00
|
|
|
|
2003-07-03 00:48:43 +00:00
|
|
|
// NOTE: use #include <functional> to get max,min
|
2002-08-09 21:43:19 +00:00
|
|
|
|
2002-09-16 20:11:52 +00:00
|
|
|
#define SECONDS_PER_DAY 86400
|
2003-06-09 23:50:49 +00:00
|
|
|
|
|
|
|
static inline double drand() {
|
|
|
|
return (double)rand()/(double)RAND_MAX;
|
|
|
|
}
|
|
|
|
|
2004-02-04 19:14:39 +00:00
|
|
|
#ifdef _WIN32
|
2004-07-09 10:34:26 +00:00
|
|
|
#include <windows.h>
|
2006-05-16 21:14:18 +00:00
|
|
|
|
2004-12-10 19:17:32 +00:00
|
|
|
extern char* windows_error_string(char* pszBuf, int iSize);
|
|
|
|
extern char* windows_format_error_string(
|
2004-05-24 17:51:08 +00:00
|
|
|
unsigned long dwError, char* pszBuf, int iSize
|
|
|
|
);
|
2004-12-10 19:17:32 +00:00
|
|
|
extern int boinc_thread_cpu_time(HANDLE thread_handle, double& cpu);
|
2006-05-01 05:54:52 +00:00
|
|
|
extern int boinc_process_cpu_time(double& cpu);
|
2007-03-20 19:55:53 +00:00
|
|
|
#else
|
|
|
|
// setpriority(2) arg to run in background
|
|
|
|
// (don't use 20 because
|
2007-10-05 16:47:07 +00:00
|
|
|
//
|
2007-03-20 19:55:53 +00:00
|
|
|
static const int PROCESS_IDLE_PRIORITY = 19;
|
2007-03-20 23:12:22 +00:00
|
|
|
extern double linux_cpu_time(int pid);
|
2004-02-04 19:14:39 +00:00
|
|
|
#endif
|
|
|
|
|
2004-04-07 06:51:42 +00:00
|
|
|
extern void update_average(double, double, double, double&, double&);
|
|
|
|
|
2004-12-05 23:52:17 +00:00
|
|
|
extern int boinc_calling_thread_cpu_time(double&);
|
2004-11-05 19:52:19 +00:00
|
|
|
|
2004-12-27 21:14:18 +00:00
|
|
|
// convert UNIX time to MySQL timestamp (yyyymmddhhmmss)
|
|
|
|
//
|
|
|
|
extern void mysql_timestamp(double, char*);
|
|
|
|
|
2007-05-23 21:02:19 +00:00
|
|
|
extern void boinc_crash();
|
2007-09-03 23:00:22 +00:00
|
|
|
extern int read_file_malloc(const char* path, char*&, int max_len=0, bool tail=false);
|
|
|
|
extern int read_file_string(const char* path, std::string&, int max_len=0, bool tail=false);
|
2006-12-14 00:42:43 +00:00
|
|
|
|
2008-03-10 22:36:22 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
|
|
|
|
extern int run_program(
|
|
|
|
const char* path, const char* cdir, int argc, char *const argv[], double, HANDLE&
|
|
|
|
);
|
|
|
|
|
|
|
|
extern void kill_program(HANDLE);
|
|
|
|
extern int get_exit_status(HANDLE);
|
|
|
|
extern bool process_exists(HANDLE);
|
|
|
|
|
|
|
|
#else
|
|
|
|
extern int run_program(
|
|
|
|
const char* path, const char* cdir, int argc, char *const argv[], double, int&
|
|
|
|
);
|
|
|
|
extern void kill_program(int);
|
|
|
|
extern int get_exit_status(int);
|
|
|
|
extern bool process_exists(int);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
extern int wait_client_mutex(const char* dir, double timeout);
|
2003-06-10 18:50:43 +00:00
|
|
|
#endif
|