예제 #1
0
파일: sdl_handler.c 프로젝트: golems/amino
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);
}
예제 #2
0
mccp_result_t
mccp_hashmap_statistics(mccp_hashmap_t *hmptr, const char **msgptr) {
  mccp_result_t ret = MCCP_RESULT_ANY_FAILURES;

  if (hmptr != NULL &&
      *hmptr != NULL &&
      msgptr != NULL) {

    *msgptr = NULL;

    s_read_lock(*hmptr);
    {
      if ((*hmptr)->m_is_operational == true) {
        *msgptr = (const char *)HashStats(&((*hmptr)->m_hashtable));
        if (*msgptr != NULL) {
          ret = MCCP_RESULT_OK;
        } else {
          ret = MCCP_RESULT_NO_MEMORY;
        }
      } else {
        ret = MCCP_RESULT_NOT_OPERATIONAL;
      }
    }
    s_unlock(*hmptr);

  } else {
    ret = MCCP_RESULT_INVALID_ARGS;
  }

  return ret;
}
예제 #3
0
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;
}
예제 #4
0
mccp_result_t
mccp_hashmap_clear(mccp_hashmap_t *hmptr, bool free_values) {
  mccp_result_t ret = MCCP_RESULT_ANY_FAILURES;

  if (hmptr != NULL &&
      *hmptr != NULL) {

    s_write_lock(*hmptr);
    {
      if ((*hmptr)->m_is_operational == true) {
        (*hmptr)->m_is_operational = false;
        s_reinit(*hmptr, free_values);
        (*hmptr)->m_is_operational = true;
        ret = MCCP_RESULT_OK;
      } else {
        ret = MCCP_RESULT_NOT_OPERATIONAL;
      }
    }
    s_unlock(*hmptr);

  } else {
    ret = MCCP_RESULT_INVALID_ARGS;
  }

  return ret;
}
예제 #5
0
mccp_result_t
mccp_hashmap_iterate(mccp_hashmap_t *hmptr,
                     mccp_hashmap_iteration_proc_t proc,
                     void *arg) {
  mccp_result_t ret = MCCP_RESULT_ANY_FAILURES;

  if (hmptr != NULL &&
      *hmptr != NULL &&
      proc != NULL) {

    /*
     * The proc could modify hash values so we use write lock.
     */
    s_write_lock(*hmptr);
    {
      ret = s_iterate(hmptr, proc, arg);
    }
    s_unlock(*hmptr);

  } else {
    ret = MCCP_RESULT_INVALID_ARGS;
  }

  return ret;
}
예제 #6
0
lagopus_result_t
lagopus_hashmap_iterate(lagopus_hashmap_t *hmptr,
                        lagopus_hashmap_iteration_proc_t proc,
                        void *arg) {
  lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES;

  if (hmptr != NULL &&
      *hmptr != NULL &&
      proc != NULL) {
    int cstate;

    /*
     * The proc could modify hash values so we use write lock.
     */
    s_write_lock(*hmptr, &cstate);
    {
      ret = s_iterate(hmptr, proc, arg);
    }
    s_unlock(*hmptr, cstate);

  } else {
    ret = LAGOPUS_RESULT_INVALID_ARGS;
  }

  return ret;
}
예제 #7
0
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;
}
예제 #8
0
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;
}
예제 #9
0
파일: logger.c 프로젝트: D-TOKIOKA/lagopus
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);
}
예제 #10
0
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;
}
예제 #11
0
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;
}
예제 #12
0
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();
}
예제 #13
0
파일: module.c 프로젝트: D-TOKIOKA/lagopus
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;
}
예제 #14
0
파일: module.c 프로젝트: D-TOKIOKA/lagopus
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;
}
예제 #15
0
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;
}
예제 #16
0
void
lagopus_cbuffer_cancel_janitor(lagopus_cbuffer_t *cbptr) {
  if (cbptr != NULL &&
      *cbptr != NULL) {
    s_unlock(*cbptr);
  }
}
예제 #17
0
파일: gstate.c 프로젝트: 1514louluo/lagopus
void
global_state_reset(void) {
  s_lock();
  {
    s_gs = GLOBAL_STATE_UNKNOWN;
  }
  s_unlock();
}
예제 #18
0
파일: acct.c 프로젝트: asyn/openvims
/**
 * Drop a given AAAAcctSession.
 * @param s the accounting session to drop
 */
void AAADropAcctSession(AAAAcctSession* s) {
	LOG(L_INFO, "INF: AAADropAcctSession\n");
	if (s) {
		AAAAcctSession *s1 = get_acc_session(s->dlgid);
		if (!s1) {
			LOG(L_ERR, "ERR: AAADropAcctSession: AAAAcctSession does not exist\n");
			return;
		}
		unsigned int hash = get_acc_session_hash(s1->dlgid);
		//del_acc_session(s);
		s_unlock(hash);
	}
}
예제 #19
0
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;
}
예제 #20
0
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();

  }
}
예제 #21
0
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);

  }
}
예제 #22
0
파일: acct.c 프로젝트: asyn/openvims
/**
 * Get an AAAAcctSession based on the application-level id.
 * @param dlgid app-level id 
 * @returns the AAAAcctSession* if found, else NULL
 */
AAAAcctSession* AAAGetAcctSession(str *dlgid) 
{
	AAAAcctSession* s;
	
	LOG(L_INFO, "INF: AAAGetAcctSession\n");
	s = get_acc_session(dlgid);
	if (!s) {
		LOG(L_ERR, "ERR: AAAGetAcctSession: AAAAcctSession does not exist\n");
		return 0;
	}
	unsigned int hash = get_acc_session_hash(dlgid);
	s_unlock(hash);
	
	return s;
}
예제 #23
0
void
mccp_hashmap_shutdown(mccp_hashmap_t *hmptr, bool free_values) {
  if (hmptr != NULL &&
      *hmptr != NULL) {

    s_write_lock(*hmptr);
    {
      if ((*hmptr)->m_is_operational == true) {
        (*hmptr)->m_is_operational = false;
        s_clean(*hmptr, free_values);
      }
    }
    s_unlock(*hmptr);

  }
}
예제 #24
0
파일: acct.c 프로젝트: asyn/openvims
/**
 * 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);
}
예제 #25
0
파일: acct.c 프로젝트: asyn/openvims
/**
 * 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;
}
예제 #26
0
void
lagopus_hashmap_shutdown(lagopus_hashmap_t *hmptr, bool free_values) {
  if (hmptr != NULL &&
      *hmptr != NULL) {
    int cstate;

    s_write_lock(*hmptr, &cstate);
    {
      if ((*hmptr)->m_is_operational == true) {
        (*hmptr)->m_is_operational = false;
        s_clean(*hmptr, free_values);
      }
    }
    s_unlock(*hmptr, cstate);

  }
}
예제 #27
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;
}
예제 #28
0
파일: sdl_handler.c 프로젝트: golems/amino
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();
}
예제 #29
0
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;
}
예제 #30
0
파일: gstate.c 프로젝트: 1514louluo/lagopus
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;
}