Feature #1754 » 0016-Maintain-list-of-thread-specific-structures-in-requi.patch
| common/fc_interface.c | ||
|---|---|---|
|
fc_astr_init();
|
||
|
fc_support_init();
|
||
|
init_nls();
|
||
|
requirements_init();
|
||
|
if (check_fc_interface) {
|
||
|
fc_funcs = &fc_functions;
|
||
| ... | ... | |
|
free_user_home_dir();
|
||
|
free_fileinfo_data();
|
||
|
netfile_free();
|
||
|
requirements_free();
|
||
|
free_nls();
|
||
|
fc_iconv_close();
|
||
|
fc_support_free();
|
||
| common/requirements.c | ||
|---|---|---|
|
#include "requirements.h"
|
||
|
struct thr_req_data
|
||
|
{
|
||
|
fc_thread_id thr_id;
|
||
|
};
|
||
|
/* get 'struct thr_req_data_list' and related functions: */
|
||
|
#define SPECLIST_TAG thr_req_data
|
||
|
#define SPECLIST_TYPE struct thr_req_data
|
||
|
#include "speclist.h"
|
||
|
#define thr_req_data_list_iterate(trlist, ptrdata) \
|
||
|
TYPED_LIST_ITERATE(struct thr_req_data, trlist, ptrdata)
|
||
|
#define thr_req_data_list_iterate_end LIST_ITERATE_END
|
||
|
static struct thr_req_data_list *trdatas;
|
||
|
static fc_mutex trmutex;
|
||
|
/************************************************************************
|
||
|
Container for req_item_found functions
|
||
|
************************************************************************/
|
||
| ... | ... | |
|
req_unchanging_cond_cb unchanging_cond;
|
||
|
};
|
||
|
/**********************************************************************//**
|
||
|
Thread exit callback
|
||
|
**************************************************************************/
|
||
|
static void thr_exit_cb()
|
||
|
{
|
||
|
fc_thread_id self = fc_thread_self();
|
||
|
fc_mutex_allocate(&trmutex);
|
||
|
thr_req_data_list_iterate(trdatas, data) {
|
||
|
if (fc_threads_equal(self, data->thr_id)) {
|
||
|
thr_req_data_list_remove(trdatas, data);
|
||
|
free(data);
|
||
|
break;
|
||
|
}
|
||
|
} thr_req_data_list_iterate_end;
|
||
|
fc_mutex_release(&trmutex);
|
||
|
}
|
||
|
/**********************************************************************//**
|
||
|
Initialize requirements module
|
||
|
**************************************************************************/
|
||
|
void requirements_init(void)
|
||
|
{
|
||
|
trdatas = thr_req_data_list_new();
|
||
|
fc_mutex_init(&trmutex);
|
||
|
register_at_thread_exit_callback(thr_exit_cb);
|
||
|
}
|
||
|
/**********************************************************************//**
|
||
|
Deinitialize requirements module
|
||
|
**************************************************************************/
|
||
|
void requirements_free(void)
|
||
|
{
|
||
|
fc_mutex_destroy(&trmutex);
|
||
|
thr_req_data_list_destroy(trdatas);
|
||
|
}
|
||
|
/**********************************************************************//**
|
||
|
Parse requirement type (kind) and value strings into a universal
|
||
|
structure. Passing in a NULL type is considered VUT_NONE (not an error).
|
||
| ... | ... | |
|
const enum req_problem_type prob_type)
|
||
|
{
|
||
|
const struct civ_map *nmap = &(wld.map);
|
||
|
enum fc_tristate eval = tri_req_present(nmap, context, other_player, req);
|
||
|
enum fc_tristate eval;
|
||
|
fc_thread_id self = fc_thread_self();
|
||
|
struct thr_req_data *trdata = NULL;
|
||
|
fc_mutex_allocate(&trmutex);
|
||
|
thr_req_data_list_iterate(trdatas, data) {
|
||
|
if (fc_threads_equal(self, data->thr_id)) {
|
||
|
trdata = data;
|
||
|
}
|
||
|
} thr_req_data_list_iterate_end;
|
||
|
if (trdata == NULL) {
|
||
|
trdata = fc_malloc(sizeof(struct thr_req_data));
|
||
|
trdata->thr_id = self;
|
||
|
thr_req_data_list_append(trdatas, trdata);
|
||
|
}
|
||
|
fc_mutex_release(&trmutex);
|
||
|
eval = tri_req_present(nmap, context, other_player, req);
|
||
|
if (eval == TRI_MAYBE) {
|
||
|
if (prob_type == RPT_POSSIBLE) {
|
||
| ... | ... | |
|
return FALSE;
|
||
|
}
|
||
|
}
|
||
|
return req->present ? (eval != TRI_NO) : (eval != TRI_YES);
|
||
|
}
|
||
| common/requirements.h | ||
|---|---|---|
|
/* req_context-related functions */
|
||
|
const struct req_context *req_context_empty(void);
|
||
|
void requirements_init(void);
|
||
|
void requirements_free(void);
|
||
|
/* General requirement functions. */
|
||
|
struct requirement req_from_str(const char *type, const char *range,
|
||
|
bool survives, bool present, bool quiet,
|
||