提交 3e023421 authored 作者: Anthony Minessale's avatar Anthony Minessale

use more of apr-utils in the event stuff

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@191 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 e60fbc22
...@@ -61,6 +61,10 @@ extern "C" { ...@@ -61,6 +61,10 @@ extern "C" {
#include <apr_poll.h> #include <apr_poll.h>
#include <apr_queue.h> #include <apr_queue.h>
#include <apr_uuid.h> #include <apr_uuid.h>
#include <apr_strmatch.h>
#define APR_WANT_STDIO
#define APR_WANT_STRFUNC
#include <apr_want.h>
#include <assert.h> #include <assert.h>
#include <sqlite3.h> #include <sqlite3.h>
......
...@@ -42,6 +42,7 @@ extern "C" { ...@@ -42,6 +42,7 @@ extern "C" {
struct switch_core_thread_session { struct switch_core_thread_session {
int running; int running;
void *objs[MAX_CORE_THREAD_SESSION_OBJS]; void *objs[MAX_CORE_THREAD_SESSION_OBJS];
switch_memory_pool *pool;
}; };
struct switch_core_session; struct switch_core_session;
...@@ -73,7 +74,7 @@ SWITCH_DECLARE(switch_status) switch_core_hash_insert(switch_hash *hash, char *k ...@@ -73,7 +74,7 @@ SWITCH_DECLARE(switch_status) switch_core_hash_insert(switch_hash *hash, char *k
SWITCH_DECLARE(switch_status) switch_core_hash_insert_dup(switch_hash *hash, char *key, void *data); SWITCH_DECLARE(switch_status) switch_core_hash_insert_dup(switch_hash *hash, char *key, void *data);
SWITCH_DECLARE(switch_status) switch_core_hash_delete(switch_hash *hash, char *key); SWITCH_DECLARE(switch_status) switch_core_hash_delete(switch_hash *hash, char *key);
SWITCH_DECLARE(void *) switch_core_hash_find(switch_hash *hash, char *key); SWITCH_DECLARE(void *) switch_core_hash_find(switch_hash *hash, char *key);
SWITCH_DECLARE(void) switch_core_launch_module_thread(void *(*func)(switch_thread *, void*), void *obj); SWITCH_DECLARE(void) switch_core_launch_thread(void *(*func)(switch_thread *, void*), void *obj);
SWITCH_DECLARE(FILE *) switch_core_data_channel(switch_text_channel channel); SWITCH_DECLARE(FILE *) switch_core_data_channel(switch_text_channel channel);
SWITCH_DECLARE(void) switch_core_session_launch_thread(switch_core_session *session, void *(*func)(switch_thread *, void *), void *obj); SWITCH_DECLARE(void) switch_core_session_launch_thread(switch_core_session *session, void *(*func)(switch_thread *, void *), void *obj);
SWITCH_DECLARE(switch_status) switch_core_timer_init(switch_timer *timer, char *timer_name, int interval, int samples); SWITCH_DECLARE(switch_status) switch_core_timer_init(switch_timer *timer, char *timer_name, int interval, int samples);
......
...@@ -193,6 +193,7 @@ typedef switch_status (*switch_api_function)(char *in, char *out, size_t outlen) ...@@ -193,6 +193,7 @@ typedef switch_status (*switch_api_function)(char *in, char *out, size_t outlen)
The pieces of apr we allow ppl to pass around between modules we typedef into our namespace and wrap all the functions The pieces of apr we allow ppl to pass around between modules we typedef into our namespace and wrap all the functions
any other apr code should be as hidden as possible. any other apr code should be as hidden as possible.
*/ */
typedef apr_strmatch_pattern switch_strmatch_pattern;
typedef apr_uuid_t switch_uuid_t; typedef apr_uuid_t switch_uuid_t;
typedef apr_queue_t switch_queue_t; typedef apr_queue_t switch_queue_t;
typedef apr_hash_t switch_hash; typedef apr_hash_t switch_hash;
...@@ -228,6 +229,9 @@ typedef apr_hash_index_t switch_hash_index_t; ...@@ -228,6 +229,9 @@ typedef apr_hash_index_t switch_hash_index_t;
#define switch_thread_cond_broadcast apr_thread_cond_broadcast #define switch_thread_cond_broadcast apr_thread_cond_broadcast
#define switch_thread_cond_destroy apr_thread_cond_destroy #define switch_thread_cond_destroy apr_thread_cond_destroy
#define switch_pool_clear apr_pool_clear
#define switch_strmatch_precompile apr_strmatch_precompile
#define switch_strmatch apr_strmatch
#define switch_uuid_format apr_uuid_format #define switch_uuid_format apr_uuid_format
#define switch_uuid_get apr_uuid_get #define switch_uuid_get apr_uuid_get
#define switch_uuid_parse apr_uuid_parse #define switch_uuid_parse apr_uuid_parse
......
...@@ -60,6 +60,50 @@ static switch_loadable_module_interface event_test_module_interface = { ...@@ -60,6 +60,50 @@ static switch_loadable_module_interface event_test_module_interface = {
#define MY_EVENT_COOL "test::cool" #define MY_EVENT_COOL "test::cool"
//#define TORTURE_ME
#ifdef TORTURE_ME
#define TTHREADS 500
static int THREADS = 0;
static void *torture_thread(switch_thread *thread, void *obj)
{
int y = 0;
int z = 0;
switch_core_thread_session *ts = obj;
switch_event *event;
z = THREADS++;
while(THREADS > 0) {
int x;
for(x = 0; x < 1; x++) {
if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, MY_EVENT_COOL) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header(event, "event_info", "hello world %d %d", z, y++);
switch_event_fire(&event);
}
}
switch_yield(100000);
}
if (ts->pool) {
switch_memory_pool *pool = ts->pool;
switch_core_destroy_memory_pool(&pool);
}
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Thread Ended\n");
}
SWITCH_MOD_DECLARE(switch_status) switch_module_shutdown(void)
{
THREADS = -1;
switch_yield(100000);
return SWITCH_STATUS_SUCCESS;
}
#endif
SWITCH_MOD_DECLARE(switch_status) switch_module_load(switch_loadable_module_interface **interface, char *filename) { SWITCH_MOD_DECLARE(switch_status) switch_module_load(switch_loadable_module_interface **interface, char *filename) {
/* connect my internal structure to the blank pointer passed to me */ /* connect my internal structure to the blank pointer passed to me */
*interface = &event_test_module_interface; *interface = &event_test_module_interface;
...@@ -69,32 +113,21 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_load(switch_loadable_module_inte ...@@ -69,32 +113,21 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_load(switch_loadable_module_inte
return SWITCH_STATUS_GENERR; return SWITCH_STATUS_GENERR;
} }
#ifdef TORTURE_ME
if (switch_event_bind((char *)modname, SWITCH_EVENT_ALL, SWITCH_EVENT_SUBCLASS_ANY, event_handler, NULL) != SWITCH_STATUS_SUCCESS) { if (switch_event_bind((char *)modname, SWITCH_EVENT_ALL, SWITCH_EVENT_SUBCLASS_ANY, event_handler, NULL) != SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Couldn't bind!\n"); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Couldn't bind!\n");
return SWITCH_STATUS_GENERR; return SWITCH_STATUS_GENERR;
} }
if (1) {
int x = 0;
for(x = 0 ; x < TTHREADS ; x++) {
switch_core_launch_thread(torture_thread, NULL);
}
}
#endif
/* indicate that the module should continue to be loaded */ /* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
//#define TORTURE_ME
#ifdef TORTURE_ME
SWITCH_MOD_DECLARE(switch_status) switch_module_runtime(void)
{
int y = 0;
switch_event *event;
for(;;) {
int x;
for(x = 0; x < 100; x++) {
if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, MY_EVENT_COOL) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header(event, "event_info", "hello world %d", y++);
switch_event_fire(&event);
}
}
switch_yield(100000);
}
}
#endif
...@@ -1408,19 +1408,33 @@ SWITCH_DECLARE(void *) switch_core_hash_find(switch_hash *hash, char *key) ...@@ -1408,19 +1408,33 @@ SWITCH_DECLARE(void *) switch_core_hash_find(switch_hash *hash, char *key)
*/ */
SWITCH_DECLARE(void) switch_core_launch_module_thread(switch_thread_start_t func, void *obj) SWITCH_DECLARE(void) switch_core_launch_thread(switch_thread_start_t func, void *obj)
{ {
switch_thread *thread; switch_thread *thread;
switch_threadattr_t *thd_attr;; switch_threadattr_t *thd_attr;;
switch_threadattr_create(&thd_attr, runtime.memory_pool); switch_threadattr_create(&thd_attr, runtime.memory_pool);
switch_threadattr_detach_set(thd_attr, 1); switch_threadattr_detach_set(thd_attr, 1);
switch_core_thread_session *ts;
switch_memory_pool *pool = NULL;
switch_thread_create(&thread, if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) {
thd_attr, switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Could not allocate memory pool\n");
func, return;
obj, }
runtime.memory_pool
); if (!(ts = switch_core_alloc(pool, sizeof(*ts)))) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Could not allocate memory\n");
} else {
ts->pool = pool;
ts->objs[0] = obj;
switch_thread_create(&thread,
thd_attr,
func,
ts,
ts->pool
);
}
} }
......
差异被折叠。
...@@ -70,7 +70,8 @@ static struct switch_loadable_module_container loadable_modules; ...@@ -70,7 +70,8 @@ static struct switch_loadable_module_container loadable_modules;
static void *switch_loadable_module_exec(switch_thread *thread, void *obj) static void *switch_loadable_module_exec(switch_thread *thread, void *obj)
{ {
switch_status status = SWITCH_STATUS_SUCCESS; switch_status status = SWITCH_STATUS_SUCCESS;
switch_loadable_module *module = obj; switch_core_thread_session *ts = obj;
switch_loadable_module *module = ts->objs[0];
int restarts; int restarts;
assert(module != NULL); assert(module != NULL);
...@@ -79,6 +80,12 @@ static void *switch_loadable_module_exec(switch_thread *thread, void *obj) ...@@ -79,6 +80,12 @@ static void *switch_loadable_module_exec(switch_thread *thread, void *obj)
status = module->switch_module_runtime(); status = module->switch_module_runtime();
} }
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Thread ended for %s\n", module->interface->module_name); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Thread ended for %s\n", module->interface->module_name);
if (ts->pool) {
switch_memory_pool *pool = ts->pool;
switch_core_destroy_memory_pool(&pool);
}
return NULL; return NULL;
} }
...@@ -165,7 +172,7 @@ static switch_status switch_loadable_module_load_file(char *filename, switch_mem ...@@ -165,7 +172,7 @@ static switch_status switch_loadable_module_load_file(char *filename, switch_mem
module->lib = dso; module->lib = dso;
if (module->switch_module_runtime) { if (module->switch_module_runtime) {
switch_core_launch_module_thread(switch_loadable_module_exec, module); switch_core_launch_thread(switch_loadable_module_exec, module);
} }
*new_module = module; *new_module = module;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论