lagopus_result_t lagopus_cbuffer_clear(lagopus_cbuffer_t *cbptr, bool free_values) { lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES; if (cbptr != NULL && *cbptr != NULL) { s_lock(*cbptr); { s_clean(*cbptr, free_values); if ((*cbptr)->m_qmuxer != NULL && NEED_WAIT_READABLE((*cbptr)->m_type) == true) { qmuxer_notify((*cbptr)->m_qmuxer); } (void)lagopus_cond_notify(&((*cbptr)->m_cond_put), true); } s_unlock(*cbptr); ret = LAGOPUS_RESULT_OK; } else { ret = LAGOPUS_RESULT_INVALID_ARGS; } return ret; }
static inline void s_do_log(lagopus_log_level_t l, const char *msg) { FILE *fd; int o_cancel_state; (void)pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &o_cancel_state); s_lock(); switch (s_log_dst) { case LAGOPUS_LOG_EMIT_TO_FILE: case LAGOPUS_LOG_EMIT_TO_UNKNOWN: { fd = (s_log_fd != NULL) ? s_log_fd : stderr; (void)fprintf(fd, "%s", msg); (void)fflush(fd); break; } case LAGOPUS_LOG_EMIT_TO_SYSLOG: { int prio = s_get_syslog_priority(l); syslog(prio, "%s", msg); } } s_unlock(); (void)pthread_setcancelstate(o_cancel_state, NULL); }
lagopus_result_t lagopus_cbuffer_wait_puttable(lagopus_cbuffer_t *cbptr, lagopus_chrono_t nsec) { lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES; int64_t remains; if (cbptr != NULL && *cbptr != NULL) { s_lock(*cbptr); { remains = (*cbptr)->m_n_max_elements - (*cbptr)->m_n_elements; if (remains > 0) { ret = (lagopus_result_t)remains; } else { ret = s_wait_puttable(*cbptr, nsec); if (ret == LAGOPUS_RESULT_OK) { ret = (*cbptr)->m_n_max_elements - (*cbptr)->m_n_elements; } } } s_unlock(*cbptr); } else { ret = LAGOPUS_RESULT_INVALID_ARGS; } return ret; }
shared_ptr<GlobalVariable> VariableRegistry::createGlobalVariable(VariableProperties *props) { boost::mutex::scoped_lock s_lock(lock); shared_ptr<GlobalVariable> var = addGlobalVariable(props); return var; }
shared_ptr<SelectionVariable> VariableRegistry::createSelectionVariable(VariableProperties *props){ boost::mutex::scoped_lock s_lock(lock); shared_ptr<SelectionVariable> var = addSelectionVariable(props); return var; }
static lagopus_result_t dummy_module_shutdown(shutdown_grace_level_t l) { lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES; lagopus_msg_debug(5, "called.\n"); if (s_thd != NULL) { s_lock(); { if (s_is_initialized == true) { if (l == SHUTDOWN_GRACEFULLY) { s_is_gracefull = true; } s_do_loop = false; ret = LAGOPUS_RESULT_OK; } else { ret = LAGOPUS_RESULT_INVALID_STATE_TRANSITION; } } s_unlock(); } else { ret = LAGOPUS_RESULT_INVALID_OBJECT; } return ret; }
static lagopus_result_t dummy_module_start(void) { lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES; lagopus_msg_debug(5, "called.\n"); if (s_thd != NULL) { s_lock(); { if (s_is_initialized == true) { ret = lagopus_thread_start(&s_thd, false); if (ret == LAGOPUS_RESULT_OK) { s_do_loop = true; } } else { ret = LAGOPUS_RESULT_INVALID_STATE_TRANSITION; } } s_unlock(); } else { ret = LAGOPUS_RESULT_INVALID_OBJECT; } return ret; }
void gallus_module_finalize_all(void) { s_lock(); { s_gstate = MODULE_GLOBAL_STATE_FINALIZING; if (s_n_modules > 0) { size_t i; a_module *mptr; /* * Reverse order. */ for (i = 0; i < s_n_modules; i++) { mptr = &(s_modules[s_n_modules - i - 1]); s_finalize_module(mptr); } } s_gstate = MODULE_GLOBAL_STATE_FINALIZED; s_wakeup(); } s_unlock(); }
gallus_result_t gallus_module_register(const char *name, gallus_module_initialize_proc_t init_proc, void *extarg, gallus_module_start_proc_t start_proc, gallus_module_shutdown_proc_t shutdown_proc, gallus_module_stop_proc_t stop_proc, gallus_module_finalize_proc_t finalize_proc, gallus_module_usage_proc_t usage_proc) { gallus_result_t ret = GALLUS_RESULT_ANY_FAILURES; s_lock(); { ret = s_register_module(name, init_proc, extarg, start_proc, shutdown_proc, stop_proc, finalize_proc, usage_proc); } s_unlock(); return ret; }
lagopus_result_t lagopus_module_start_all(void) { lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES; s_lock(); { if (s_n_modules > 0) { size_t i; a_module *mptr; for (ret = LAGOPUS_RESULT_OK, i = 0; ret == LAGOPUS_RESULT_OK && i < s_n_modules; i++) { mptr = &(s_modules[i]); ret = s_start_module(mptr); if (ret != LAGOPUS_RESULT_OK) { lagopus_perror(ret); lagopus_msg_error("can't start module \"%s\".\n", mptr->m_name); } } } else { ret = LAGOPUS_RESULT_OK; } } s_unlock(); return ret; }
lagopus_result_t lagopus_module_initialize_all(int argc, const char *const argv[]) { lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES; s_lock(); { if (s_n_modules > 0) { size_t i; a_module *mptr; for (ret = LAGOPUS_RESULT_OK, i = 0; ret == LAGOPUS_RESULT_OK && i < s_n_modules; i++) { mptr = &(s_modules[i]); ret = s_initialize_module(mptr, argc, argv); if (ret != LAGOPUS_RESULT_OK) { lagopus_perror(ret); lagopus_msg_error("can't initialize module \"%s\".\n", mptr->m_name); } } } else { ret = LAGOPUS_RESULT_OK; } } s_unlock(); return ret; }
AA_API int aa_sdl_handle_event( const SDL_Event *event, struct aa_sdl_display_params *params) { s_lock(); struct handler *r = NULL; if( SDL_KEYDOWN == event->type ) { /* search for key */ SDL_Keycode key = event->key.keysym.sym; for( size_t i = 0; !r && i < s_key_vector.size; i ++ ) { struct handler *h = s_key_vector.data[i]; if( key == h->key ) r = h; } } else { /* search for event */ for( size_t i = 0; !r && i < s_event_vector.size; i ++ ) { struct handler *h = s_event_vector.data[i]; if( event->type == h->event_type ) r = h; } } s_unlock(); return (r ? r->handler(r->cx, params) : -1); }
lagopus_result_t lagopus_cbuffer_is_empty(lagopus_cbuffer_t *cbptr, bool *retptr) { lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES; if (cbptr != NULL && *cbptr != NULL && retptr != NULL) { *retptr = false; s_lock(*cbptr); { if ((*cbptr)->m_is_operational == true) { *retptr = ((*cbptr)->m_n_elements == 0) ? true : false; ret = LAGOPUS_RESULT_OK; } else { ret = LAGOPUS_RESULT_NOT_OPERATIONAL; } } s_unlock(*cbptr); } else { ret = LAGOPUS_RESULT_INVALID_ARGS; } return ret; }
void VariableRegistry::announceAll() { boost::mutex::scoped_lock s_lock(lock); vector< shared_ptr<Variable> >::iterator i; for(i = master_variable_list.begin(); i != master_variable_list.end(); i++){ (*i)->announce(); } }
void global_state_reset(void) { s_lock(); { s_gs = GLOBAL_STATE_UNKNOWN; } s_unlock(); }
shared_ptr<ScopedVariable> VariableRegistry::createScopedVariable(weak_ptr<ScopedVariableEnvironment> env, VariableProperties *props) { boost::mutex::scoped_lock s_lock(lock); shared_ptr<ScopedVariable> var = addScopedVariable(env, props); return var; }
/** * Creates and adds an accounting session to the hash table. * \note Locks the hash slot if OK! Call s_unlock(acc_session->hash) when you are finished) * @param s - AAAAcctSession to add * @returns the new AAAAcctSession* or NULL */ AAAAcctSession* add_acc_session(AAAAcctSession* s) { s_lock(s->hash); s->next = 0; s->prev = acc_sessions[s->hash].tail; if (s->prev) s->prev->next = s; acc_sessions[s->hash].tail = s; if (!acc_sessions[s->hash].head) acc_sessions[s->hash].head = s; return s; }
gallus_result_t gallus_module_shutdown_all(shutdown_grace_level_t level) { gallus_result_t ret = GALLUS_RESULT_ANY_FAILURES; if (IS_VALID_SHUTDOWN(level) == true) { s_lock(); { s_gstate = MODULE_GLOBAL_STATE_SHUTTINGDOWN; if (s_n_modules > 0) { gallus_result_t first_err = GALLUS_RESULT_OK; size_t i; a_module *mptr; /* * Reverse order. */ for (i = 0; i < s_n_modules; i++) { mptr = &(s_modules[s_n_modules - i - 1]); ret = s_shutdown_module(mptr, level); if (ret != GALLUS_RESULT_OK) { gallus_perror(ret); gallus_msg_error("can't shutdown module \"%s\".\n", mptr->m_name); if (first_err == GALLUS_RESULT_OK) { first_err = ret; } } /* * Just carry on shutting down no matter what kind of errors * occur. */ } ret = first_err; } else { ret = GALLUS_RESULT_OK; } } s_unlock(); } else { ret = GALLUS_RESULT_INVALID_ARGS; } return ret; }
static void dummy_module_finalize(void) { lagopus_msg_debug(5, "called.\n"); if (s_thd != NULL) { s_lock(); { lagopus_thread_destroy(&s_thd); } s_unlock(); } }
void lagopus_cbuffer_shutdown(lagopus_cbuffer_t *cbptr, bool free_values) { if (cbptr != NULL && *cbptr != NULL) { s_lock(*cbptr); { s_shutdown(*cbptr, free_values); } s_unlock(*cbptr); } }
// There is potential room for speed up with a hash_map, though this would // require const char * machinations, as hash_map cannot have string keys shared_ptr<Variable> VariableRegistry::getVariable(const std::string& tagname) const{ boost::mutex::scoped_lock s_lock(lock); map< string, shared_ptr<Variable> >::const_iterator it; it = master_variable_dictionary.find(tagname); if(it == master_variable_dictionary.end()){ return shared_ptr<Variable>(); } else { return it->second; } // This one line is how it would have been written if the stx parser guy // didn't have a const-correctness stick up his butt //return master_variable_dictionary[tagname]; }
std::vector<std::string> VariableRegistry::getVariableTagNames() { boost::mutex::scoped_lock s_lock(lock); std::vector<std::string> tagnames; vector< shared_ptr<Variable> >::iterator i; for(i = master_variable_list.begin(); i != master_variable_list.end(); i++){ shared_ptr<Variable> var = (*i); if(var) { tagnames.push_back(var->getVariableName()); } } return tagnames; }
Datum VariableRegistry::generateCodecDatum() { ScarabDatum *codec = NULL; shared_ptr<Variable> var; boost::mutex::scoped_lock s_lock(lock); int dictSize = master_variable_list.size(); codec = scarab_dict_new(dictSize, &scarab_dict_times2); for(int i = 0; i < dictSize; i++) { var = master_variable_list[i]; if(var == NULL) { continue; } int codec_code = var->getCodecCode(); if(codec_code == RESERVED_CODEC_CODE) { continue; } VariableProperties *props = var->getProperties(); if(props == NULL){ continue; } Datum serialized_var(props->operator Datum()); if(serialized_var.isUndefined()) { mdebug("local parameter null value at param (%d)", i); } ScarabDatum *codec_key = scarab_new_integer(codec_code); scarab_dict_put(codec, codec_key, serialized_var.getScarabDatum()); scarab_free_datum(codec_key); } Datum returnCodec(codec); scarab_free_datum(codec); return returnCodec; }
/** * Destroy the accounting sessions hash table. */ void acc_sessions_destroy() { int i; AAAAcctSession *s,*ns; for(i=0;i<acc_sessions_hash_size;i++){ s_lock(i); s = acc_sessions[i].head; while(s){ ns = s->next; free_acc_session(s); s = ns; } s_unlock(i); lock_dealloc(acc_sessions[i].lock); } shm_free(acc_sessions); }
/** * Finds and returns an accounting session from the hash table. * \note Locks the hash slot if ok! Call s_unlock(acc_session->hash) when you are finished) * @param dlgid - the app-level id (e.g. SIP dialog) * @returns the acc_session* or NULL if not found */ AAAAcctSession* get_acc_session(str* dlgid) { AAAAcctSession *s=0; unsigned int hash = get_acc_session_hash(dlgid); s_lock(hash); s = acc_sessions[hash].head; while(s){ if (s->dlgid->len == dlgid->len && strncasecmp(s->dlgid->s,dlgid->s,dlgid->len)==0) { return s; } s = s->next; } s_unlock(hash); return 0; }
gallus_result_t gallus_module_stop_all(void) { gallus_result_t ret = GALLUS_RESULT_ANY_FAILURES; s_lock(); { s_gstate = MODULE_GLOBAL_STATE_STOPPING; if (s_n_modules > 0) { gallus_result_t first_err = GALLUS_RESULT_OK; size_t i; a_module *mptr; /* * Reverse order. */ for (i = 0; i < s_n_modules; i++) { mptr = &(s_modules[s_n_modules - i - 1]); ret = s_stop_module(mptr); if (ret != GALLUS_RESULT_OK) { gallus_perror(ret); gallus_msg_error("can't stop module \"%s\".\n", mptr->m_name); if (first_err == GALLUS_RESULT_OK) { first_err = ret; } } /* * Just carry on stopping no matter what kind of errors * occur. */ } ret = first_err; } else { ret = GALLUS_RESULT_OK; } } s_unlock(); return ret; }
AA_API void aa_sdl_bind_event( SDL_EventType event_type, aa_sdl_handler_function handler, void *cx ) { s_lock(); s_init(); struct handler *h = AA_NEW(struct handler); h->cx = cx; h->event_type = event_type; h->handler = handler; handler_vector_push(&s_event_vector, h); s_unlock(); }
static lagopus_result_t dummy_module_initialize(int argc, const char *const argv[], void *extarg, lagopus_thread_t **thdptr) { lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES; (void)extarg; lagopus_msg_debug(5, "called.\n"); if (thdptr != NULL) { *thdptr = NULL; } s_lock(); { if (s_is_initialized == false) { int i; lagopus_msg_debug(5, "argc: %d\n", argc); for (i = 0; i < argc; i++) { lagopus_msg_debug(5, "%5d: '%s'\n", i, argv[i]); } ret = lagopus_thread_create(&s_thd, s_dummy_thd_main, s_dummy_thd_finalize, s_dummy_thd_destroy, "dummy", NULL); if (ret == LAGOPUS_RESULT_OK) { s_is_initialized = true; if (thdptr != NULL) { *thdptr = &s_thd; } } } else { ret = LAGOPUS_RESULT_OK; } } s_unlock(); return ret; }
lagopus_result_t global_state_wait_for(global_state_t s_wait_for, global_state_t *cur_sptr, shutdown_grace_level_t *cur_gptr, lagopus_chrono_t nsec) { lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES; if (IS_VALID_GLOBAL_STATE(s_wait_for) == true) { s_lock(); { recheck: if ((int)s_gs < (int)s_wait_for && IS_GLOBAL_STATE_SHUTDOWN(s_gs) == false) { ret = lagopus_cond_wait(&s_cond, &s_lck, nsec); if (ret == LAGOPUS_RESULT_OK) { goto recheck; } } else { if (cur_sptr != NULL) { *cur_sptr = s_gs; } if (cur_gptr != NULL) { *cur_gptr = s_gl; } if ((int)s_gs >= (int)s_wait_for) { ret = LAGOPUS_RESULT_OK; } else if (IS_GLOBAL_STATE_SHUTDOWN(s_gs) == true && IS_GLOBAL_STATE_SHUTDOWN(s_wait_for) == false) { ret = LAGOPUS_RESULT_NOT_OPERATIONAL; } else { ret = LAGOPUS_RESULT_OK; } } } s_unlock(); } else { ret = LAGOPUS_RESULT_INVALID_ARGS; } return ret; }
void lagopus_module_finalize_all(void) { s_lock(); { if (s_n_modules > 0) { size_t i; a_module *mptr; /* * Reverse order. */ for (i = 0; i < s_n_modules; i++) { mptr = &(s_modules[s_n_modules - i - 1]); s_finalize_module(mptr); } } } s_unlock(); }