2003-07-01 20:37:09 +00:00
|
|
|
// The contents of this file are subject to the BOINC Public License
|
2002-08-05 00:29:34 +00:00
|
|
|
// Version 1.0 (the "License"); you may not use this file except in
|
|
|
|
// compliance with the License. You may obtain a copy of the License at
|
2003-07-01 20:37:09 +00:00
|
|
|
// http://boinc.berkeley.edu/license_1.0.txt
|
2003-08-21 23:44:57 +00:00
|
|
|
//
|
2002-08-05 00:29:34 +00:00
|
|
|
// Software distributed under the License is distributed on an "AS IS"
|
|
|
|
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
|
|
|
// License for the specific language governing rights and limitations
|
2003-08-21 23:44:57 +00:00
|
|
|
// under the License.
|
|
|
|
//
|
|
|
|
// The Original Code is the Berkeley Open Infrastructure for Network Computing.
|
|
|
|
//
|
2002-08-05 00:29:34 +00:00
|
|
|
// The Initial Developer of the Original Code is the SETI@home project.
|
|
|
|
// Portions created by the SETI@home project are Copyright (C) 2002
|
2003-08-21 23:44:57 +00:00
|
|
|
// University of California at Berkeley. All Rights Reserved.
|
|
|
|
//
|
2002-08-05 00:29:34 +00:00
|
|
|
// Contributor(s):
|
|
|
|
//
|
|
|
|
|
2003-05-07 23:42:17 +00:00
|
|
|
// Code that's in the BOINC app library (but NOT in the core client)
|
2003-09-30 21:17:20 +00:00
|
|
|
// graphics-related code goes in graphics_api.C, not here
|
2003-05-07 23:42:17 +00:00
|
|
|
|
2003-02-19 18:55:07 +00:00
|
|
|
#ifdef _WIN32
|
2004-03-06 09:45:25 +00:00
|
|
|
#include "stdafx.h"
|
2002-08-05 00:29:34 +00:00
|
|
|
#endif
|
2002-09-18 22:19:38 +00:00
|
|
|
|
2004-03-06 09:45:25 +00:00
|
|
|
#ifndef _WIN32
|
2004-03-24 07:39:24 +00:00
|
|
|
#include "config.h"
|
2004-02-06 09:34:00 +00:00
|
|
|
#ifdef HAVE_UNISTD_H
|
2002-08-05 00:29:34 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_TIME_H
|
|
|
|
#include <sys/time.h>
|
2004-01-05 01:36:27 +00:00
|
|
|
#include <sys/resource.h>
|
2002-08-05 00:29:34 +00:00
|
|
|
#endif
|
|
|
|
|
2004-02-06 09:34:00 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <string.h>
|
2004-03-05 04:37:53 +00:00
|
|
|
#include <string>
|
2004-03-17 04:56:46 +00:00
|
|
|
#ifdef HAVE_SIGNAL_H
|
2004-01-04 06:48:40 +00:00
|
|
|
#include <signal.h>
|
2004-03-17 04:56:46 +00:00
|
|
|
#endif
|
2002-08-05 00:29:34 +00:00
|
|
|
#include <fcntl.h>
|
2004-03-05 04:37:53 +00:00
|
|
|
#include <algorithm>
|
2002-08-05 00:29:34 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
2004-03-05 04:37:53 +00:00
|
|
|
using namespace std;
|
2004-03-06 09:45:25 +00:00
|
|
|
#endif
|
2004-03-05 04:37:53 +00:00
|
|
|
|
2004-03-24 07:39:24 +00:00
|
|
|
#include "diagnostics.h"
|
2002-08-05 00:29:34 +00:00
|
|
|
#include "parse.h"
|
2003-03-17 19:24:38 +00:00
|
|
|
#include "shmem.h"
|
2002-11-18 23:09:11 +00:00
|
|
|
#include "util.h"
|
2003-12-24 00:50:51 +00:00
|
|
|
#include "filesys.h"
|
2002-08-05 00:29:34 +00:00
|
|
|
#include "error_numbers.h"
|
2003-05-07 23:42:17 +00:00
|
|
|
#include "app_ipc.h"
|
2002-08-05 00:29:34 +00:00
|
|
|
#include "boinc_api.h"
|
|
|
|
|
2004-02-09 05:11:05 +00:00
|
|
|
static APP_INIT_DATA aid;
|
|
|
|
APP_CLIENT_SHM *app_client_shm;
|
2004-02-06 09:34:00 +00:00
|
|
|
|
|
|
|
static double timer_period = 1.0/50.0; // 50 Hz timer
|
|
|
|
static double time_until_checkpoint;
|
|
|
|
static double time_until_fraction_done_update;
|
|
|
|
static double fraction_done;
|
|
|
|
static double last_checkpoint_cpu_time;
|
|
|
|
static bool ready_to_checkpoint = false;
|
|
|
|
static bool this_process_active;
|
|
|
|
static bool time_to_quit = false;
|
|
|
|
static double last_wu_cpu_time;
|
|
|
|
static bool standalone = false;
|
|
|
|
static double initial_wu_cpu_time;
|
|
|
|
static bool have_new_trickle = false;
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
2004-03-21 00:10:15 +00:00
|
|
|
HANDLE hErrorNotification;
|
|
|
|
HANDLE hQuitRequest;
|
|
|
|
HANDLE hSuspendRequest;
|
|
|
|
HANDLE hResumeRequest;
|
|
|
|
HANDLE hSharedMem;
|
|
|
|
HANDLE worker_thread_handle;
|
|
|
|
MMRESULT timer_id;
|
2004-02-06 09:34:00 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Forward declare implementation functions.
|
|
|
|
//
|
|
|
|
static void setup_shared_mem();
|
|
|
|
static void cleanup_shared_mem();
|
|
|
|
static int update_app_progress(double frac_done, double cpu_t, double cp_cpu_t, double ws_t);
|
|
|
|
static int set_timer(double period);
|
|
|
|
|
2004-03-26 18:32:57 +00:00
|
|
|
// Standard BOINC APIs
|
2004-02-06 09:34:00 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
int boinc_init(bool standalone_ /* = false */) {
|
|
|
|
FILE* f;
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
|
|
|
DuplicateHandle(
|
|
|
|
GetCurrentProcess(),
|
|
|
|
GetCurrentThread(),
|
|
|
|
GetCurrentProcess(),
|
|
|
|
&worker_thread_handle,
|
|
|
|
0,
|
|
|
|
FALSE,
|
|
|
|
DUPLICATE_SAME_ACCESS
|
|
|
|
);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Store startup mode for later use.
|
|
|
|
standalone = standalone_;
|
|
|
|
|
|
|
|
// Parse initial data file.
|
|
|
|
retval = boinc_parse_init_data_file();
|
|
|
|
if (retval) return retval;
|
|
|
|
|
|
|
|
// copy the WU CPU time to a separate var,
|
|
|
|
// since we may reread the structure again later.
|
|
|
|
//
|
|
|
|
initial_wu_cpu_time = aid.wu_cpu_time;
|
|
|
|
|
2004-04-01 06:52:42 +00:00
|
|
|
if (boinc_file_exists(FD_INIT_FILE)) {
|
|
|
|
f = boinc_fopen(FD_INIT_FILE, "r");
|
|
|
|
if (f) {
|
|
|
|
parse_fd_init_file(f);
|
|
|
|
fclose(f);
|
|
|
|
}
|
2004-02-06 09:34:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
time_until_checkpoint = aid.checkpoint_period;
|
|
|
|
last_checkpoint_cpu_time = aid.wu_cpu_time;
|
|
|
|
time_until_fraction_done_update = aid.fraction_done_update_period;
|
|
|
|
this_process_active = true;
|
|
|
|
last_wu_cpu_time = aid.wu_cpu_time;
|
|
|
|
|
|
|
|
set_timer(timer_period);
|
|
|
|
setup_shared_mem();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int boinc_finish(int status) {
|
|
|
|
double cur_mem;
|
|
|
|
|
|
|
|
boinc_thread_cpu_time(last_checkpoint_cpu_time, cur_mem);
|
|
|
|
last_checkpoint_cpu_time += aid.wu_cpu_time;
|
|
|
|
update_app_progress(fraction_done, last_checkpoint_cpu_time, last_checkpoint_cpu_time, cur_mem);
|
|
|
|
#ifdef _WIN32
|
|
|
|
// Stop the timer
|
|
|
|
timeKillEvent(timer_id);
|
2004-03-21 00:10:15 +00:00
|
|
|
CloseHandle(worker_thread_handle);
|
2002-11-21 23:27:27 +00:00
|
|
|
#endif
|
2004-02-06 09:34:00 +00:00
|
|
|
cleanup_shared_mem();
|
|
|
|
exit(status);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool boinc_is_standalone() {
|
|
|
|
return standalone;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// parse the init data file.
|
|
|
|
// This is done at startup, and also if a "reread prefs" message is received
|
|
|
|
//
|
|
|
|
int boinc_parse_init_data_file() {
|
|
|
|
FILE* f;
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
// If in standalone mode, use init files if they're there,
|
|
|
|
// but don't demand that they exist
|
|
|
|
//
|
|
|
|
f = boinc_fopen(INIT_DATA_FILE, "r");
|
|
|
|
if (!f) {
|
|
|
|
if (standalone) {
|
|
|
|
safe_strncpy(aid.app_preferences, "", sizeof(aid.app_preferences));
|
|
|
|
safe_strncpy(aid.user_name, "Unknown user", sizeof(aid.user_name));
|
|
|
|
safe_strncpy(aid.team_name, "Unknown team", sizeof(aid.team_name));
|
|
|
|
aid.wu_cpu_time = 1000;
|
|
|
|
aid.user_total_credit = 1000;
|
|
|
|
aid.user_expavg_credit = 500;
|
|
|
|
aid.host_total_credit = 1000;
|
|
|
|
aid.host_expavg_credit = 500;
|
|
|
|
aid.checkpoint_period = DEFAULT_CHECKPOINT_PERIOD;
|
|
|
|
aid.fraction_done_update_period = DEFAULT_FRACTION_DONE_UPDATE_PERIOD;
|
|
|
|
} else {
|
|
|
|
fprintf(stderr,
|
|
|
|
"boinc_parse_init_data_file(): can't open init data file\n"
|
|
|
|
);
|
|
|
|
return ERR_FOPEN;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
retval = parse_init_data_file(f, aid);
|
|
|
|
fclose(f);
|
|
|
|
if (retval) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"boinc_parse_init_data_file(): can't parse init data file\n"
|
|
|
|
);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-10-28 22:30:37 +00:00
|
|
|
|
2003-11-06 20:27:07 +00:00
|
|
|
// communicate to the core client (via shared mem)
|
|
|
|
// the current CPU time and fraction done
|
|
|
|
//
|
|
|
|
static int update_app_progress(
|
|
|
|
double frac_done, double cpu_t, double cp_cpu_t, double ws_t
|
|
|
|
) {
|
|
|
|
char msg_buf[SHM_SEG_SIZE];
|
2003-05-28 20:58:01 +00:00
|
|
|
|
2003-11-06 20:27:07 +00:00
|
|
|
if (!app_client_shm) return 0;
|
|
|
|
|
|
|
|
sprintf(msg_buf,
|
|
|
|
"<fraction_done>%2.8f</fraction_done>\n"
|
|
|
|
"<current_cpu_time>%10.4f</current_cpu_time>\n"
|
2003-11-10 06:49:45 +00:00
|
|
|
"<checkpoint_cpu_time>%.15e</checkpoint_cpu_time>\n"
|
2003-11-06 20:27:07 +00:00
|
|
|
"<working_set_size>%f</working_set_size>\n",
|
|
|
|
frac_done, cpu_t, cp_cpu_t, ws_t
|
|
|
|
);
|
2004-01-04 06:48:40 +00:00
|
|
|
if (have_new_trickle) {
|
|
|
|
strcat(msg_buf, "<have_new_trickle/>\n");
|
|
|
|
have_new_trickle = false;
|
|
|
|
}
|
2003-11-06 20:27:07 +00:00
|
|
|
|
|
|
|
return app_client_shm->send_msg(msg_buf, APP_CORE_WORKER_SEG);
|
2002-08-05 00:29:34 +00:00
|
|
|
}
|
|
|
|
|
2002-08-09 23:34:11 +00:00
|
|
|
int boinc_get_init_data(APP_INIT_DATA& app_init_data) {
|
|
|
|
app_init_data = aid;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-08-21 23:44:57 +00:00
|
|
|
|
2003-11-06 20:27:07 +00:00
|
|
|
// this can be called from the graphics thread
|
|
|
|
//
|
|
|
|
int boinc_wu_cpu_time(double& cpu_t) {
|
|
|
|
cpu_t = last_wu_cpu_time;
|
|
|
|
return 0;
|
|
|
|
}
|
2002-12-02 22:51:11 +00:00
|
|
|
|
2003-11-06 20:27:07 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
int boinc_thread_cpu_time(HANDLE thread_handle, double& cpu, double& ws) {
|
|
|
|
FILETIME creationTime,exitTime,kernelTime,userTime;
|
|
|
|
static bool first = true;
|
|
|
|
static DWORD first_count = 0;
|
2002-12-02 22:51:11 +00:00
|
|
|
|
2003-11-06 20:27:07 +00:00
|
|
|
if (first) {
|
|
|
|
first_count = GetTickCount();
|
|
|
|
first = false;
|
2002-11-18 23:09:11 +00:00
|
|
|
}
|
2003-11-06 20:27:07 +00:00
|
|
|
if (GetThreadTimes(
|
|
|
|
thread_handle, &creationTime, &exitTime, &kernelTime, &userTime)
|
|
|
|
) {
|
|
|
|
ULARGE_INTEGER tKernel, tUser;
|
|
|
|
LONGLONG totTime;
|
2002-11-18 23:09:11 +00:00
|
|
|
|
2003-11-06 20:27:07 +00:00
|
|
|
tKernel.LowPart = kernelTime.dwLowDateTime;
|
|
|
|
tKernel.HighPart = kernelTime.dwHighDateTime;
|
|
|
|
tUser.LowPart = userTime.dwLowDateTime;
|
|
|
|
tUser.HighPart = userTime.dwHighDateTime;
|
|
|
|
totTime = tKernel.QuadPart + tUser.QuadPart;
|
2003-09-05 21:26:21 +00:00
|
|
|
|
2003-11-06 20:27:07 +00:00
|
|
|
// Runtimes in 100-nanosecond units
|
|
|
|
cpu = totTime / 1.e7;
|
|
|
|
ws = 0;
|
|
|
|
} else {
|
|
|
|
// TODO: Handle timer wraparound
|
|
|
|
DWORD cur = GetTickCount();
|
|
|
|
cpu = ((cur - first_count)/1000.);
|
|
|
|
ws = 0;
|
2002-11-18 23:09:11 +00:00
|
|
|
}
|
2002-08-05 00:29:34 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-11-06 20:27:07 +00:00
|
|
|
int boinc_worker_thread_cpu_time(double& cpu, double& ws) {
|
|
|
|
return boinc_thread_cpu_time(worker_thread_handle, cpu, ws);
|
2002-08-05 00:29:34 +00:00
|
|
|
}
|
|
|
|
|
2003-11-06 20:27:07 +00:00
|
|
|
int boinc_thread_cpu_time(double& cpu, double& ws) {
|
|
|
|
return boinc_thread_cpu_time(GetCurrentThread(), cpu, ws);
|
2002-08-05 00:29:34 +00:00
|
|
|
}
|
2003-11-06 20:27:07 +00:00
|
|
|
#else
|
2002-08-05 00:29:34 +00:00
|
|
|
#ifdef HAVE_SYS_RESOURCE_H
|
2003-11-06 20:27:07 +00:00
|
|
|
int boinc_worker_thread_cpu_time(double &cpu_t, double &ws_t) {
|
2003-09-30 18:09:58 +00:00
|
|
|
int retval;
|
2002-08-05 00:29:34 +00:00
|
|
|
struct rusage ru;
|
|
|
|
retval = getrusage(RUSAGE_SELF, &ru);
|
2003-09-27 17:53:43 +00:00
|
|
|
if (retval) {
|
2003-09-30 18:09:58 +00:00
|
|
|
fprintf(stderr, "error: could not get CPU time\n");
|
2003-05-28 20:58:01 +00:00
|
|
|
return ERR_GETRUSAGE;
|
2003-11-07 01:46:38 +00:00
|
|
|
}
|
2002-10-19 05:22:02 +00:00
|
|
|
// Sum the user and system time spent in this process
|
2003-11-06 20:27:07 +00:00
|
|
|
cpu_t = (double)ru.ru_utime.tv_sec + (((double)ru.ru_utime.tv_usec) / ((double)1000000.0));
|
|
|
|
cpu_t += (double)ru.ru_stime.tv_sec + (((double)ru.ru_stime.tv_usec) / ((double)1000000.0));
|
2003-07-15 18:19:29 +00:00
|
|
|
ws_t = ru.ru_idrss; // TODO: fix this (mult by page size)
|
2003-11-07 01:46:38 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int boinc_thread_cpu_time(double& cpu, double& ws) {
|
2003-11-22 02:00:17 +00:00
|
|
|
return boinc_worker_thread_cpu_time(cpu, ws);
|
2002-08-05 00:29:34 +00:00
|
|
|
}
|
2003-11-06 20:27:07 +00:00
|
|
|
#endif
|
|
|
|
#endif // _WIN32
|
2002-08-05 00:29:34 +00:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
2003-11-06 20:27:07 +00:00
|
|
|
static void CALLBACK on_timer(UINT uTimerID, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2) {
|
2002-08-05 00:29:34 +00:00
|
|
|
#else
|
2004-03-17 04:56:46 +00:00
|
|
|
static RETSIGTYPE on_timer(int a) {
|
2002-08-05 00:29:34 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!ready_to_checkpoint) {
|
|
|
|
time_until_checkpoint -= timer_period;
|
|
|
|
if (time_until_checkpoint <= 0) {
|
|
|
|
ready_to_checkpoint = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-06 20:27:07 +00:00
|
|
|
if (this_process_active) {
|
2002-08-05 00:29:34 +00:00
|
|
|
time_until_fraction_done_update -= timer_period;
|
2002-12-02 22:51:11 +00:00
|
|
|
if (time_until_fraction_done_update <= 0) {
|
2003-11-06 20:27:07 +00:00
|
|
|
double cur_cpu;
|
|
|
|
double cur_mem;
|
|
|
|
boinc_worker_thread_cpu_time(cur_cpu, cur_mem);
|
2003-11-07 06:17:57 +00:00
|
|
|
last_wu_cpu_time = cur_cpu + initial_wu_cpu_time;
|
2003-11-06 20:27:07 +00:00
|
|
|
update_app_progress(fraction_done, last_wu_cpu_time, last_checkpoint_cpu_time, cur_mem);
|
|
|
|
time_until_fraction_done_update = aid.fraction_done_update_period;
|
2002-08-05 00:29:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-11-06 20:27:07 +00:00
|
|
|
static int set_timer(double period) {
|
2002-08-05 00:29:34 +00:00
|
|
|
int retval=0;
|
|
|
|
#ifdef _WIN32
|
2003-03-18 19:37:09 +00:00
|
|
|
char buf[256];
|
|
|
|
|
2002-10-28 22:30:37 +00:00
|
|
|
// Use Windows multimedia timer, since it is more accurate
|
|
|
|
// than SetTimer and doesn't require an associated event loop
|
2004-03-26 18:32:57 +00:00
|
|
|
//
|
2002-11-14 00:49:24 +00:00
|
|
|
timer_id = timeSetEvent(
|
2002-10-28 22:30:37 +00:00
|
|
|
(int)(period*1000), // uDelay
|
|
|
|
(int)(period*1000), // uResolution
|
|
|
|
on_timer, // lpTimeProc
|
|
|
|
NULL, // dwUser
|
|
|
|
TIME_PERIODIC // fuEvent
|
2003-09-05 21:26:21 +00:00
|
|
|
);
|
2003-03-18 19:37:09 +00:00
|
|
|
sprintf(buf, "%s%s", QUIT_PREFIX, aid.comm_obj_name);
|
|
|
|
hQuitRequest = OpenEvent(EVENT_ALL_ACCESS, FALSE, buf);
|
2002-08-05 00:29:34 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if HAVE_SIGNAL_H
|
|
|
|
#if HAVE_SYS_TIME_H
|
|
|
|
struct sigaction sa;
|
|
|
|
itimerval value;
|
2002-12-02 22:51:11 +00:00
|
|
|
sa.sa_handler = on_timer;
|
|
|
|
sa.sa_flags = SA_RESTART;
|
|
|
|
retval = sigaction(SIGALRM, &sa, NULL);
|
|
|
|
if (retval) {
|
2003-09-05 21:26:21 +00:00
|
|
|
perror("boinc set_timer() sigaction");
|
2002-12-02 22:51:11 +00:00
|
|
|
return retval;
|
|
|
|
}
|
2002-08-05 00:29:34 +00:00
|
|
|
value.it_value.tv_sec = (int)period;
|
|
|
|
value.it_value.tv_usec = ((int)(period*1000000))%1000000;
|
|
|
|
value.it_interval = value.it_value;
|
2002-10-19 05:22:02 +00:00
|
|
|
retval = setitimer(ITIMER_REAL, &value, NULL);
|
2002-12-02 22:51:11 +00:00
|
|
|
if (retval) {
|
2003-09-05 21:26:21 +00:00
|
|
|
perror("boinc set_timer() setitimer");
|
2002-12-02 22:51:11 +00:00
|
|
|
}
|
2002-08-05 00:29:34 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2003-11-06 20:27:07 +00:00
|
|
|
static void setup_shared_mem() {
|
2003-08-21 23:44:57 +00:00
|
|
|
if (standalone) {
|
2004-02-09 05:11:05 +00:00
|
|
|
fprintf(stderr, "Standalone mode, so not using shared memory.\n");
|
2003-08-21 23:44:57 +00:00
|
|
|
return;
|
|
|
|
}
|
2004-02-09 05:11:05 +00:00
|
|
|
app_client_shm = new APP_CLIENT_SHM;
|
2003-03-17 19:24:38 +00:00
|
|
|
|
2003-03-18 19:37:09 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
char buf[256];
|
|
|
|
sprintf(buf, "%s%s", SHM_PREFIX, aid.comm_obj_name);
|
2003-05-05 23:40:34 +00:00
|
|
|
hSharedMem = attach_shmem(buf, (void**)&app_client_shm->shm);
|
2003-09-05 21:26:21 +00:00
|
|
|
if (hSharedMem == NULL) {
|
2004-03-29 06:14:22 +00:00
|
|
|
delete app_client_shm;
|
2003-03-18 19:37:09 +00:00
|
|
|
app_client_shm = NULL;
|
2003-09-05 21:26:21 +00:00
|
|
|
}
|
2003-03-18 19:37:09 +00:00
|
|
|
#endif
|
|
|
|
|
2003-03-17 19:24:38 +00:00
|
|
|
#ifdef HAVE_SYS_SHM_H
|
|
|
|
#ifdef HAVE_SYS_IPC_H
|
2003-05-05 23:40:34 +00:00
|
|
|
if (attach_shmem(aid.shm_key, (void**)&app_client_shm->shm)) {
|
2004-03-29 06:14:22 +00:00
|
|
|
delete app_client_shm;
|
2003-03-17 19:24:38 +00:00
|
|
|
app_client_shm = NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2003-11-06 20:27:07 +00:00
|
|
|
static void cleanup_shared_mem() {
|
2003-06-24 20:54:05 +00:00
|
|
|
if (!app_client_shm) return;
|
2003-08-21 23:44:57 +00:00
|
|
|
|
2003-03-18 19:37:09 +00:00
|
|
|
#ifdef _WIN32
|
2004-02-09 05:11:05 +00:00
|
|
|
detach_shmem(hSharedMem, app_client_shm->shm);
|
2003-03-18 19:37:09 +00:00
|
|
|
#endif
|
|
|
|
|
2003-03-17 19:24:38 +00:00
|
|
|
#ifdef HAVE_SYS_SHM_H
|
|
|
|
#ifdef HAVE_SYS_IPC_H
|
2004-02-09 05:11:05 +00:00
|
|
|
detach_shmem(app_client_shm->shm);
|
2003-03-17 19:24:38 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
2004-03-29 06:14:22 +00:00
|
|
|
delete app_client_shm;
|
|
|
|
app_client_shm = NULL;
|
2003-03-17 19:24:38 +00:00
|
|
|
}
|
|
|
|
|
2003-11-06 20:27:07 +00:00
|
|
|
|
2004-01-04 06:48:40 +00:00
|
|
|
int boinc_trickle(char* p) {
|
|
|
|
FILE* f = boinc_fopen("trickle", "wb");
|
|
|
|
if (!f) return ERR_FOPEN;
|
|
|
|
size_t n = fwrite(p, strlen(p), 1, f);
|
|
|
|
fclose(f);
|
|
|
|
if (n != 1) return ERR_WRITE;
|
|
|
|
have_new_trickle = true;
|
|
|
|
return 0;
|
|
|
|
}
|
2003-11-06 20:27:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool boinc_time_to_checkpoint() {
|
|
|
|
#ifdef _WIN32
|
|
|
|
DWORD eventState;
|
|
|
|
// Check if core client has requested us to exit
|
|
|
|
eventState = WaitForSingleObject(hQuitRequest, 0L);
|
|
|
|
|
|
|
|
switch (eventState) {
|
|
|
|
case WAIT_OBJECT_0:
|
|
|
|
case WAIT_ABANDONED:
|
|
|
|
time_to_quit = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// If the application has received a quit request it should checkpoint
|
|
|
|
//
|
|
|
|
if (time_to_quit) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ready_to_checkpoint;
|
|
|
|
}
|
|
|
|
|
|
|
|
int boinc_checkpoint_completed() {
|
|
|
|
double cur_cpu, cur_mem;
|
|
|
|
boinc_thread_cpu_time(cur_cpu, cur_mem);
|
|
|
|
last_wu_cpu_time = cur_cpu + aid.wu_cpu_time;
|
|
|
|
last_checkpoint_cpu_time = last_wu_cpu_time;
|
|
|
|
update_app_progress(fraction_done, last_checkpoint_cpu_time, last_checkpoint_cpu_time, cur_mem);
|
|
|
|
ready_to_checkpoint = false;
|
|
|
|
time_until_checkpoint = aid.checkpoint_period;
|
|
|
|
|
|
|
|
// If it's time to quit, call boinc_finish which will exit the app properly
|
|
|
|
//
|
|
|
|
if (time_to_quit) {
|
|
|
|
fprintf(stderr, "Received quit request from core client\n");
|
|
|
|
boinc_finish(ERR_QUIT_REQUEST);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int boinc_fraction_done(double x) {
|
|
|
|
fraction_done = x;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int boinc_child_start() {
|
|
|
|
this_process_active = false;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int boinc_child_done(double cpu) {
|
|
|
|
this_process_active = true;
|
|
|
|
return 0;
|
2003-03-17 19:24:38 +00:00
|
|
|
}
|
2004-03-26 18:32:57 +00:00
|
|
|
|