// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2008 University of California
//
// 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.
//
// BOINC is distributed in the hope that it will be useful,
// 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.
//
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC. If not, see .
#ifndef UTIL_H
#define UTIL_H
#include
#include
#include
extern double dtime();
extern double dday();
extern void boinc_sleep(double);
extern void push_unique(std::string, std::vector&);
// NOTE: use #include to get max,min
#define SECONDS_PER_DAY 86400
#define KILO (1024.0)
#define MEGA (1048576.0)
#define GIGA (1024.*1048576.0)
static inline double drand() {
return (double)rand()/(double)RAND_MAX;
}
extern double rand_normal();
#ifdef _WIN32
#include
extern int boinc_thread_cpu_time(HANDLE thread_handle, double& cpu);
extern int boinc_process_cpu_time(HANDLE process_handle, double& cpu);
#else
// setpriority(2) arg to run in background
// (don't use 20 because
//
static const int PROCESS_IDLE_PRIORITY = 19;
static const int PROCESS_MEDIUM_PRIORITY = 10;
extern double linux_cpu_time(int pid);
#endif
extern void update_average(double, double, double, double, double&, double&);
extern int boinc_calling_thread_cpu_time(double&);
inline bool in_vector(int n, std::vector& v) {
for (unsigned int i=0; i