<commit_before>/* base.cpp - main function for Franklin
 * vim: set foldmethod=marker :
 * Copyright 2014-2016 Michigan Technological University
 * Copyright 2016 <NAME> <<EMAIL>>
 * Author: <NAME> <<EMAIL>>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program 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 Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#define EXTERN	// This must be done in exactly one source file.
#include "cdriver.h"
#include <execinfo.h>

//#define cdebug debug
#define cdebug(...) do {} while (0)

#ifdef SERIAL
// Only for connections that can fail.
void disconnect(bool notify) { // {{{
	// Hardware has disconnected.  Notify host and wait for reconnect.
	arch_disconnect();
	if (notify) {
		prepare_interrupt();
		send_to_parent(CMD_DISCONNECT);
	}
}
// }}}
#endif

void debug_backtrace() {
	void *array[10];
	size_t size;

	// get void*'s for all entries on the stack
	size = backtrace(array, 10);

	// print out all the frames to stderr
	debug("Stack backtrace:");
	char **frames = backtrace_symbols(array, size);
	if (frames == NULL) {
		debug("unable to print stack backtrace");
		return;
	}
	for (size_t i = 0; i < size; ++i) {
		debug("frame %d: %s", i, frames[i]);
	}
	free(frames);
}

// Time handling.  {{{
static void get_current_times(int32_t *current_time, int32_t *longtime) {
	struct timeval tv;
	gettimeofday(&tv, NULL);
	if (current_time)
		*current_time = tv.tv_sec * 1000000 + tv.tv_usec;
	if (longtime)
		*longtime = tv.tv_sec * 1000 + tv.tv_usec / 1000;
	//fprintf(stderr, "current times: %d %d\n", *current_time, *longtime);
}

int32_t utime() {
	int32_t ret;
	get_current_times(&ret, NULL);
	return ret;
}

int32_t millis() {
	int32_t ret;
	get_current_times(NULL, &ret);<commit_msg>fix for 32bit compile<commit_after>/* base.cpp - main function for Franklin
 * vim: set foldmethod=marker :
 * Copyright 2014-2016 Michigan Technological University
 * Copyright 2016 <NAME> <<EMAIL>>
 * Author: <NAME> <<EMAIL>>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program 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 Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#define EXTERN	// This must be done in exactly one source file.
#include "cdriver.h"
#include <execinfo.h>

//#define cdebug debug
#define cdebug(...) do {} while (0)

#ifdef SERIAL
// Only for connections that can fail.
void disconnect(bool notify) { // {{{
	// Hardware has disconnected.  Notify host and wait for reconnect.
	arch_disconnect();
	if (notify) {
		prepare_interrupt();
		send_to_parent(CMD_DISCONNECT);
	}
}
// }}}
#endif

void debug_backtrace() {
	void *array[10];
	size_t size;

	// get void*'s for all entries on the stack
	size = backtrace(array, 10);

	// print out all the frames to stderr
	debug("Stack backtrace:");
	char **frames = backtrace_symbols(array, size);
	if (frames == NULL) {
		debug("unable to print stack backtrace");
		return;
	}
	for (size_t i = 0; i < size; ++i) {
		debug("frame %ld: %s", i, frames[i]);
	}
	free(frames);
}

// Time handling.  {{{
static void get_current_times(int32_t *current_time, int32_t *longtime) {
	struct timeval tv;
	gettimeofday(&tv, NULL);
	if (current_time)
		*current_time = tv.tv_sec * 1000000 + tv.tv_usec;
	if (longtime)
		*longtime = tv.tv_sec * 1000 + tv.tv_usec / 1000;
	//fprintf(stderr, "current times: %d %d\n", *current_time, *longtime);
}

int32_t utime() {
	int32_t ret;
	get_current_times(&ret, NULL);
	return ret;
}

int32_t millis() {
	int32_t ret;
	get_current_times(NULL, &ret);
{'fraction_non_alphanumeric': 0.11962039284926065, 'fraction_numerical': 0.02074597219156919, 'mean_word_length': 3.9802197802197803, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1967869', 'n_tokens_mistral': 1577, 'n_tokens_neox': 1478, 'n_words': 544}