// Called once to init th_attr // Status is reported through the shared init_attr_status static void init_thread_attr(void) { struct sched_param sched_param; init_attr_status = pthread_attr_init(&th_attr); if (init_attr_status) { NMF_LOG("Error initializing attribute in Timer: %s (%d)\n", strerror(init_attr_status), init_attr_status); return; } #ifndef ANDROID init_attr_status = pthread_attr_setinheritsched(&th_attr, PTHREAD_EXPLICIT_SCHED); if (init_attr_status) { NMF_LOG("Error setting sched-inherit policy in Timer: %s (%d)\n", strerror(init_attr_status), init_attr_status); return; } #endif if (has_capabilities(1 << CAP_SYS_NICE)) { /* In case process has no permissions to create RT threads priority will be set once the thread is created to the highest non RT priority */ init_attr_status = pthread_attr_setschedpolicy(&th_attr, SCHED_RR); if (init_attr_status) { NMF_LOG("Error setting sched policy in Timer: %s (%d)\n", strerror(init_attr_status), init_attr_status); return; } sched_param.sched_priority = sched_get_priority_max(SCHED_RR); init_attr_status = pthread_attr_setschedparam(&th_attr, &sched_param); if (init_attr_status) { NMF_LOG("Error setting sched param in Timer: %s (%d)\n", strerror(init_attr_status), init_attr_status); return; } } pthread_attr_setdetachstate(&th_attr, PTHREAD_CREATE_DETACHED); }
static void timer_handler(sigval_t value) { timer *t; t = static_cast<timer*>(value.sival_ptr); if (t->isPrioritySet) { t->alarm.signal(); } else { #ifdef PR_SET_NAME prctl(PR_SET_NAME, (unsigned long)"timer", 0, 0, 0); #endif if (has_capabilities(1 << CAP_SYS_NICE) == 0) { if (setpriority(PRIO_PROCESS, 0, -20)) { NMF_LOG("Error: setpriority -20 failed : %s\n", strerror(errno)); } } t->isPrioritySet = true; } }
/************************************************************************** Initialize audio system and autoselect a plugin **************************************************************************/ void audio_real_init(const char *const spec_name, const char *const prefered_plugin_name) { const char *filename; char *file_capstr; char us_capstr[] = "+soundspec"; if (strcmp(prefered_plugin_name, "none") == 0) { /* We explicitly choose none plugin, silently skip the code below */ freelog(LOG_VERBOSE, "Proceeding with sound support disabled."); tagfile = NULL; return; } if (num_plugins_used == 1) { /* We only have the dummy plugin, skip the code but issue an advertise */ freelog(LOG_NORMAL, _("No real audio plugin present.")); freelog(LOG_NORMAL, _("Proceeding with sound support disabled.")); freelog(LOG_NORMAL, _("For sound support, install SDL_mixer")); freelog(LOG_NORMAL, "http://www.libsdl.org/projects/SDL_mixer/index.html"); tagfile = NULL; return; } if (!spec_name) { freelog(LOG_FATAL, "No sound spec-file given!"); exit(EXIT_FAILURE); } freelog(LOG_VERBOSE, "Initializing sound using %s...", spec_name); filename = soundspec_fullname(spec_name); if (!filename) { freelog(LOG_ERROR, "Cannot find sound spec-file \"%s\".", spec_name); freelog(LOG_NORMAL, _("To get sound you need to download a sound set!")); freelog(LOG_NORMAL, _("Get sound sets from <%s>."), "ftp://ftp.freeciv.org/freeciv/contrib/audio/soundsets"); freelog(LOG_NORMAL, _("Proceeding with sound support disabled.")); tagfile = NULL; return; } if (!section_file_load(tagfile, filename)) { freelog(LOG_FATAL, _("Could not load sound spec-file: %s"), filename); exit(EXIT_FAILURE); } file_capstr = secfile_lookup_str(tagfile, "soundspec.options"); if (!has_capabilities(us_capstr, file_capstr)) { freelog(LOG_FATAL, "sound spec-file appears incompatible:"); freelog(LOG_FATAL, " file: \"%s\"", filename); freelog(LOG_FATAL, " file options: %s", file_capstr); freelog(LOG_FATAL, " supported options: %s", us_capstr); exit(EXIT_FAILURE); } if (!has_capabilities(file_capstr, us_capstr)) { freelog(LOG_FATAL, "sound spec-file claims required option(s)" " which we don't support:"); freelog(LOG_FATAL, " file: \"%s\"", filename); freelog(LOG_FATAL, " file options: %s", file_capstr); freelog(LOG_FATAL, " supported options: %s", us_capstr); exit(EXIT_FAILURE); } free((void *) filename); atexit(audio_shutdown); if (prefered_plugin_name[0] != '\0') { if (!audio_select_plugin(prefered_plugin_name)) freelog(LOG_NORMAL, _("Proceeding with sound support disabled.")); return; } #ifdef AUDIO_SDL if (audio_select_plugin("sdl")) return; #endif freelog(LOG_NORMAL, _("No real audio subsystem managed to initialize!")); freelog(LOG_NORMAL, _("Perhaps there is some misconfiguration or bad permissions.")); freelog(LOG_NORMAL, _("Proceeding with sound support disabled.")); }
/********************************************************************** Finds and reads the toplevel themespec file based on given name. Sets global variables, including tile sizes and full names for intro files. ***********************************************************************/ struct theme *theme_read_toplevel(const char *theme_name) { struct section_file *file; char *fname; int i; size_t num_spec_files; const char **spec_filenames; const char *file_capstr; bool duplicates_ok; struct theme *t = theme_new(); const char *langname; const char *filename, *c; fname = themespec_fullname(theme_name); if (!fname) { log_error("Can't find theme \"%s\".", theme_name); theme_free(t); return NULL; } log_verbose("themespec file is \"%s\".", fname); if (!(file = secfile_load(fname, TRUE))) { log_error("Could not open '%s':\n%s", fname, secfile_error()); FC_FREE(fname); theme_free(t); return NULL; } if (!check_themespec_capabilities(file, "themespec", THEMESPEC_CAPSTR, fname)) { secfile_destroy(file); FC_FREE(fname); theme_free(t); return NULL; } file_capstr = secfile_lookup_str(file, "themespec.options"); duplicates_ok = has_capabilities("+duplicates_ok", file_capstr); (void) secfile_entry_by_path(file, "themespec.name"); /* currently unused */ sz_strlcpy(t->name, theme_name); t->priority = secfile_lookup_int_default(file, 0, "themespec.priority"); langname = get_langname(); if (langname) { if (strstr(langname, "zh_CN") != NULL) { c = secfile_lookup_str(file, "themespec.font_file_zh_CN"); } else if (strstr(langname, "ja") != NULL) { c = secfile_lookup_str(file, "themespec.font_file_ja"); } else if (strstr(langname, "ko") != NULL) { c = secfile_lookup_str(file, "themespec.font_file_ko"); } else { c = secfile_lookup_str(file, "themespec.font_file"); } } else { c = secfile_lookup_str(file, "themespec.font_file"); } if ((filename = fileinfoname(get_data_dirs(), c))) { t->font_filename = fc_strdup(filename); } else { log_fatal("Could not open font: %s", c); secfile_destroy(file); FC_FREE(fname); theme_free(t); return NULL; } log_debug("theme font file %s", t->font_filename); t->default_font_size = secfile_lookup_int_default(file, 10, "themespec.default_font_size"); log_debug("theme default font size %d", t->default_font_size); spec_filenames = secfile_lookup_str_vec(file, &num_spec_files, "themespec.files"); if (NULL == spec_filenames || 0 == num_spec_files) { log_error("No theme graphics files specified in \"%s\"", fname); secfile_destroy(file); FC_FREE(fname); theme_free(t); return NULL; } fc_assert(t->sprite_hash == NULL); t->sprite_hash = small_sprite_hash_new(); for (i = 0; i < num_spec_files; i++) { struct specfile *sf = fc_malloc(sizeof(*sf)); log_debug("spec file %s", spec_filenames[i]); sf->big_sprite = NULL; filename = fileinfoname(get_data_dirs(), spec_filenames[i]); if (!filename) { log_error("Can't find spec file \"%s\".", spec_filenames[i]); secfile_destroy(file); FC_FREE(fname); theme_free(t); return NULL; } sf->file_name = fc_strdup(filename); scan_specfile(t, sf, duplicates_ok); specfile_list_prepend(t->specfiles, sf); } FC_FREE(spec_filenames); t->background_system = theme_background_system_read(file); t->color_system = theme_color_system_read(file); secfile_check_unused(file); secfile_destroy(file); log_verbose("finished reading \"%s\".", fname); FC_FREE(fname); return t; }