static void _socket_stream_truncate(stream_t* stream, size_t size) { FOUNDATION_ASSERT(stream); FOUNDATION_ASSERT(stream->type == STREAMTYPE_SOCKET); FOUNDATION_UNUSED(stream); FOUNDATION_UNUSED(size); }
void test_exception_handler(const char* dump_file, size_t length) { FOUNDATION_UNUSED(dump_file); FOUNDATION_UNUSED(length); log_error(HASH_TEST, ERROR_EXCEPTION, STRING_CONST("Test raised exception")); process_exit(-1); }
void blast_reader_unmap(blast_reader_t* reader, void* buffer, uint64_t offset, int size) { FOUNDATION_UNUSED(reader); FOUNDATION_UNUSED(buffer); FOUNDATION_UNUSED(offset); FOUNDATION_UNUSED(size); }
static void test_log_handler(hash_t context, error_level_t severity, const char* msg, size_t length) { FOUNDATION_UNUSED(context); FOUNDATION_UNUSED(severity); if (_test_should_terminate) return; #if FOUNDATION_PLATFORM_IOS test_text_view_append(delegate_uiwindow(), 1 , msg, length); #elif FOUNDATION_PLATFORM_ANDROID jclass _test_log_class = 0; jmethodID _test_log_append = 0; const struct JNINativeInterface** jnienv = thread_attach_jvm(); _test_log_class = (*jnienv)->GetObjectClass(jnienv, android_app()->activity->clazz); if (_test_log_class) _test_log_append = (*jnienv)->GetMethodID(jnienv, _test_log_class, "appendLog", "(Ljava/lang/String;)V"); if (_test_log_append) { jstring jstr = (*jnienv)->NewStringUTF(jnienv, msg); (*jnienv)->CallVoidMethod(jnienv, android_app()->activity->clazz, _test_log_append, jstr); (*jnienv)->DeleteLocalRef(jnienv, jstr); } thread_detach_jvm(); FOUNDATION_UNUSED(length); #endif }
static stream_t* _stream_open_stdin(const char* path, size_t length, unsigned int mode) { FOUNDATION_UNUSED(path); FOUNDATION_UNUSED(length); stream_t* stream = stream_open_stdin(); stream->mode = (mode & STREAM_BINARY) | STREAM_IN; return stream; }
static void handle_log(hash_t context, error_level_t severity, const char* msg, size_t msg_length) { FOUNDATION_UNUSED(context); FOUNDATION_UNUSED(severity); string_copy(handled_log, sizeof(handled_log), msg, msg_length); if (_global_log_handler) _global_log_handler(context, severity, msg, msg_length); }
static void test_local_exception_handler(const char* dump_path, size_t length) { FOUNDATION_UNUSED(dump_path); #if !BUILD_ENABLE_LOG FOUNDATION_UNUSED(length); #endif log_infof(HASH_TEST, STRING_CONST("Exception handler called: %.*s"), (int)length, dump_path); _exception_handler_called = true; }
static void test_log_handler(hash_t context, error_level_t severity, const char* msg, size_t length) { FOUNDATION_UNUSED(context); FOUNDATION_UNUSED(severity); if (_test_should_terminate) return; if (!log_stdout()) return; test_log_view_append(msg, length); }
void test_exception_handler(const char* dump_file, size_t length) { FOUNDATION_UNUSED(dump_file); FOUNDATION_UNUSED(length); log_error(HASH_TEST, ERROR_EXCEPTION, STRING_CONST("Test raised exception")); #if (FOUNDATION_PLATFORM_IOS || FOUNDATION_PLATFORM_ANDROID) && !BUILD_ENABLE_LOG test_log_view_append(STRING_CONST("Test raised exception\n")); thread_sleep(5000); #endif process_exit(-1); }
void process_set_verb(process_t* proc, const char* verb, size_t length) { #if FOUNDATION_PLATFORM_WINDOWS if (proc->verb.length <= length) proc->verb = string_resize(proc->verb.str, proc->verb.length, proc->verb.length ? proc->verb.length + 1 : 0, length + 1, 0); proc->verb = string_copy(proc->verb.str, length + 1, verb, length); #else FOUNDATION_UNUSED(proc); FOUNDATION_UNUSED(verb); FOUNDATION_UNUSED(length); #endif }
int main_run( void* main_arg ) { FOUNDATION_UNUSED( main_arg ); log_set_suppress( HASH_TEST, ERRORLEVEL_DEBUG ); return test_run_all(); }
static int blast_client_process_ack(blast_client_t* client, uint32_t* seq, tick_t timestamp) { int ipend, psize; int iack, asize; for (iack = 0, asize = PACKET_ACK_COUNT; iack < asize; ++iack) { for (ipend = 0, psize = array_size(client->pending); ipend < psize; ++ipend) { if (client->pending[ipend].seq == seq[iack]) { array_erase(client->pending, ipend); break; } } } FOUNDATION_UNUSED(timestamp); /*log_infof( HASH_BLAST, "ACK processed, %d pending packets remaining (ack seq %d)", array_size( client->pending ), seq[0] ); if( array_size( client->pending ) ) { char* buf = 0; for( ipend = 0, psize = array_size( client->pending ); ipend < psize; ++ipend ) { buf = string_append( buf, string_from_uint_static( client->pending[ipend].seq, false, 0, 0 ) ); buf = string_append( buf, " " ); } log_infof( HASH_BLAST, " %s", buf ); string_deallocate( buf ); }*/ return 0; }
static size_t _socket_stream_size(stream_t* stream) { FOUNDATION_ASSERT(stream); FOUNDATION_ASSERT(stream->type == STREAMTYPE_SOCKET); FOUNDATION_UNUSED(stream); return 0; }
static void* test_event_thread( object_t thread, void* arg ) { event_block_t* block; event_t* event = 0; FOUNDATION_UNUSED( arg ); while( !thread_should_terminate( thread ) ) { block = event_stream_process( system_event_stream() ); event = 0; while( ( event = event_next( block, event ) ) ) { switch( event->id ) { case FOUNDATIONEVENT_TERMINATE: log_warn( HASH_TEST, WARNING_SUSPICIOUS, "Terminating test due to event" ); process_exit( -2 ); break; default: break; } } thread_sleep( 10 ); } return 0; }
int window_module_initialize(const window_config_t config) { FOUNDATION_UNUSED(config); if (_window_initialized) return 0; if (_window_event_initialize() < 0) return -1; _window_initialized = true; #if FOUNDATION_PLATFORM_MACOS || FOUNDATION_PLATFORM_IOS _window_class_reference(); #endif #if FOUNDATION_PLATFORM_IOS _window_native_initialize(); #endif #if FOUNDATION_PLATFORM_LINUX XSetErrorHandler(_x11_error_handler); #endif return 0; }
void network_poll_finalize(network_poll_t* pollobj) { #if FOUNDATION_PLATFORM_LINUX || FOUNDATION_PLATFORM_ANDROID close(pollobj->fd_poll); #else FOUNDATION_UNUSED(pollobj); #endif }
static int raise_abort(void* arg) { FOUNDATION_UNUSED(arg); exception_raise_abort(); #if !FOUNDATION_COMPILER_CLANG return 1; #endif }
//This is our custom callback point from luajit lj_clib resolver void* lj_clib_getsym_registry(lua_State* state, const char* sym, size_t length) { hash_t symhash = hash(sym, length); void* fn = hashmap_lookup(_lua_symbols, symhash); FOUNDATION_UNUSED(state); //log_debugf(HASH_LUA, STRING_CONST("Built-in lookup: %.*s -> %p", (int)length, sym, fn); return fn; }
int STDCALL WinMain(HINSTANCE instance, HINSTANCE previnst, LPSTR cline, int cmd_show) { int ret; FOUNDATION_UNUSED(instance); FOUNDATION_UNUSED(previnst); FOUNDATION_UNUSED(cline); FOUNDATION_UNUSED(cmd_show); if (main_initialize() < 0) return -1; SetConsoleCtrlHandler(_main_console_handler, TRUE); thread_set_main(); foundation_startup(); system_post_event(FOUNDATIONEVENT_START); #if BUILD_DEBUG ret = main_run(0); #else { string_t name; const application_t* app = environment_application(); string_const_t aname = app->short_name; string_const_t vstr = string_from_version_static(app->version); name = string_allocate_concat_varg( aname.length ? aname.str : "unknown", aname.length ? aname.length : 7, STRING_CONST("-"), STRING_CONST(vstr)); if (app->dump_callback) crash_guard_set(app->dump_callback, STRING_ARGS(name)); ret = crash_guard(main_run, 0, app->dump_callback, STRING_ARGS(name)); string_deallocate(name.str); } #endif main_finalize(); return ret; }
static void* _profile_stream_thread(void* arg) { FOUNDATION_UNUSED(arg); thread_yield(); while (!thread_try_wait(4)) { profile_log(STRING_CONST("Thread message")); profile_begin_block(STRING_CONST("Thread block")); { profile_update_block(); profile_begin_block(STRING_CONST("Thread subblock")); { profile_log(STRING_CONST("Sub message")); profile_trylock(STRING_CONST("Trylock")); profile_lock(STRING_CONST("Trylock")); profile_wait(STRING_CONST("Wait")); profile_signal(STRING_CONST("Signal")); thread_sleep(2); profile_unlock(STRING_CONST("Trylock")); profile_log(STRING_CONST("End sub")); } profile_end_block(); profile_begin_block(STRING_CONST("Thread second subblock")); { profile_update_block(); profile_begin_block(STRING_CONST("Thread subblock")); { } profile_end_block(); } profile_end_block(); profile_trylock(STRING_CONST("Trylock")); thread_sleep(1); profile_lock(STRING_CONST("Trylock")); thread_sleep(4); profile_unlock(STRING_CONST("Trylock")); } profile_end_block(); atomic_add64(&_profile_generated_blocks, 14); } return 0; }
static int test_profile_initialize( void ) { profile_set_output( test_profile_output ); _test_profile_buffer = memory_allocate( 0, TEST_PROFILE_BUFFER_SIZE, 0, MEMORY_PERSISTENT ); FOUNDATION_UNUSED( _test_profile_buffer_size ); return 0; }
static void* _memory_allocate_malloc(hash_t context, size_t size, unsigned int align, unsigned int hint) { void* block; FOUNDATION_UNUSED(context); align = _memory_get_align(align); block = _memory_allocate_malloc_raw(size, align, hint); if (block && (hint & MEMORY_ZERO_INITIALIZED)) memset(block, 0, (size_t)size); return block; }
int vector_module_initialize(const vector_config_t config) { FOUNDATION_UNUSED(config); if (_vector_initialized) return 0; _vector_initialized = true; return 0; }
static void* mutex_thread( object_t thread, void* arg ) { mutex_t* mutex = arg; int i; FOUNDATION_UNUSED( thread ); FOUNDATION_UNUSED( arg ); for( i = 0; i < 128; ++i ) { if( !mutex_try_lock( mutex ) ) mutex_lock( mutex ); ++thread_counter; mutex_unlock( mutex ); } return 0; }
void process_set_verb( process_t* proc, const char* verb ) { if( !proc ) return; #if FOUNDATION_PLATFORM_WINDOWS string_deallocate( proc->verb ); proc->verb = string_clone( verb ); #else FOUNDATION_UNUSED( verb ); #endif }
static int blast_client_congest_control(blast_client_t* client, tick_t current) { static float64_t mbps = 20.0; static tick_t last_ts = 0; static float64_t dt = 0.1; if (last_ts) dt = time_ticks_to_seconds(time_diff(last_ts, current)); float64_t kbytes = (mbps * 1024.0) * dt; FOUNDATION_UNUSED(client); return (int)(1024.0 * (kbytes / (float64_t)PACKET_CHUNK_SIZE)); }
static void* _profile_io( object_t thread, void* arg ) { unsigned int system_info_counter = 0; profile_block_t system_info; FOUNDATION_UNUSED( arg ); memset( &system_info, 0, sizeof( profile_block_t ) ); system_info.data.id = PROFILE_ID_SYSTEMINFO; system_info.data.start = time_ticks_per_second(); string_copy( system_info.data.name, "sysinfo", 7 ); while( !thread_should_terminate( thread ) ) { thread_sleep( _profile_wait ); if( !atomic_load32( &_profile_root ) ) continue; profile_begin_block( "profile_io" ); if( atomic_load32( &_profile_root ) ) { profile_begin_block( "process" ); //This is thread safe in the sense that only completely closed and ended //blocks will be put as children to root block, so no additional blocks //will ever be added to child subtrees while we process it here _profile_process_root_block(); profile_end_block(); } if( system_info_counter++ > 10 ) { if( _profile_write ) _profile_write( &system_info, sizeof( profile_block_t ) ); system_info_counter = 0; } profile_end_block(); } if( atomic_load32( &_profile_root ) ) _profile_process_root_block(); if( _profile_write ) { profile_block_t terminate; memset( &terminate, 0, sizeof( profile_block_t ) ); terminate.data.id = PROFILE_ID_ENDOFSTREAM; _profile_write( &terminate, sizeof( profile_block_t ) ); } return 0; }
static void* thread_wait( object_t thread, void* arg ) { mutex_t* mutex = arg; FOUNDATION_UNUSED( thread ); FOUNDATION_UNUSED( arg ); atomic_incr32( &thread_waiting ); if( mutex_wait( mutex, 30000 ) ) { atomic_incr32( &thread_waited ); mutex_unlock( mutex ); } else { log_warn( HASH_TEST, WARNING_SUSPICIOUS, "Thread timeout" ); } return 0; }
static void* uuid_thread_time( object_t thread, void* arg ) { int i; int ithread = (int)(uintptr_t)arg; FOUNDATION_UNUSED( thread ); for( i = 0; i < 8192; ++i ) uuid_thread_store[ithread][i] = uuid_generate_time(); return 0; }
static void* event_thread( object_t thread, void* arg ) { event_block_t* block; event_t* event = 0; FOUNDATION_UNUSED( arg ); while( !thread_should_terminate( thread ) ) { block = event_stream_process( system_event_stream() ); event = 0; while( ( event = event_next( block, event ) ) ) { switch( event->id ) { case FOUNDATIONEVENT_START: #if FOUNDATION_PLATFORM_IOS || FOUNDATION_PLATFORM_ANDROID log_debug( HASH_TEST, "Application start event received" ); _test_should_start = true; #endif break; case FOUNDATIONEVENT_TERMINATE: #if FOUNDATION_PLATFORM_IOS || FOUNDATION_PLATFORM_ANDROID log_debug( HASH_TEST, "Application stop/terminate event received" ); _test_should_terminate = true; #else log_warn( HASH_TEST, WARNING_SUSPICIOUS, "Terminating tests due to event" ); process_exit( -2 ); #endif break; case FOUNDATIONEVENT_FOCUS_GAIN: _test_have_focus = true; break; case FOUNDATIONEVENT_FOCUS_LOST: _test_have_focus = false; break; default: break; } } thread_sleep( 10 ); } log_debug( HASH_TEST, "Application event thread exiting" ); return 0; }