diff options
| author | lijia <[email protected]> | 2019-06-05 18:42:52 +0800 |
|---|---|---|
| committer | lijia <[email protected]> | 2019-06-05 18:42:52 +0800 |
| commit | cb2152f52cdeb84c99d5ec53e018e5ac4a6fc301 (patch) | |
| tree | 674039fd44130ff694b489bddde035c1d5ef0eb1 /include | |
| parent | 49996782de45cb78fcdc824c506a99f4d3b7126a (diff) | |
1-增加定时器, 基于Libevent实现, 依赖库静态链接到sapp;
2-增加平台运行状态;
3-插件配置文件合并, 避免经常打开多个.inf的情况,
将原来的三个:conflist_platform.inf, conflist_protocol.inf, conflist_business.inf改为一个conflist.inf,
Diffstat (limited to 'include')
| -rw-r--r-- | include/private/sapp_declaration.h | 9 | ||||
| -rw-r--r-- | include/private/sapp_global_val.h | 10 | ||||
| -rw-r--r-- | include/private/sapp_private_api.h | 1 | ||||
| -rw-r--r-- | include/private/sapp_timer_private.h | 52 | ||||
| -rw-r--r-- | include/public/sapp_api.h | 1 | ||||
| -rw-r--r-- | include/public/sapp_state.h | 13 | ||||
| -rw-r--r-- | include/public/sapp_timer.h | 75 | ||||
| -rw-r--r-- | include/public/stream_inc/stream_control.h | 1 | ||||
| -rw-r--r-- | include/support/MESA_atomic.h | 41 |
9 files changed, 196 insertions, 7 deletions
diff --git a/include/private/sapp_declaration.h b/include/private/sapp_declaration.h index 32a813b..51d71e3 100644 --- a/include/private/sapp_declaration.h +++ b/include/private/sapp_declaration.h @@ -8,8 +8,8 @@ extern "C" { #include "sapp_private_api.h" enum pkt_dump_mode{ - PKT_DUMP_LOCAL_FILE = 1, /* 写本地文�?*/ - PKT_DUMP_UDP_SOCKET = 2, /* 写到UDP 某个端口 */ + PKT_DUMP_LOCAL_FILE = 1, + PKT_DUMP_UDP_SOCKET = 2, }; enum depolyment_mode_config{ @@ -22,6 +22,7 @@ enum depolyment_mode_config{ /* ��Ƕ�ײ��̫��, ʹ�ü������ */ #define ABBR_SAPP_LOG_LEVEL sapp_global_val->config.profiling.log.level #define ABBR_SAPP_LOG_HANDLE sapp_global_val->individual_fixed.log_handle +#define ABBR_SAPP_TIMER_HANDLE sapp_global_val->individual_fixed.sapp_timer_handle #define ABBR_SAPP_START_TIME sapp_global_val->individual_fixed.sapp_start_time #define ABBR_CURRENT_TIME sapp_global_val->individual_volatile->current_time #define ABBR_CURRENT_TIME_MS sapp_global_val->individual_volatile->current_time_ms @@ -69,6 +70,10 @@ void sapp_fs2_update_length(int field_index, unsigned long long value); void sapp_fs2_set_latency(int thead_seq, long long time_cost); void sapp_gval_init(void); struct mr_instance *sapp_get_marsio_instance(void); +int __sapp_timer_platform_init(void); +void __st_pkt_proc_context_check_timeout(int tid); +void __sapp_timer_platform_run(void); +void sapp_set_current_state(enum sapp_state_t st); extern volatile unsigned int g_aiSysCounter[COUNTER_NUM]; /*newly modified ---LiLei*/ diff --git a/include/private/sapp_global_val.h b/include/private/sapp_global_val.h index 062b1a5..8c13efb 100644 --- a/include/private/sapp_global_val.h +++ b/include/private/sapp_global_val.h @@ -1,6 +1,7 @@ #ifndef _SAPP_GLOBAL_VAL_H_ #define _SAPP_GLOBAL_VAL_H_ 1 +#include <pthread.h> #include "sapp_pkt_stat.h" typedef struct{ @@ -138,11 +139,13 @@ typedef struct{ typedef struct{ void *log_handle; + void *sapp_timer_handle[SAPP_MAX_THREADS]; time_t sapp_start_time; int depolyment_mode_private; /* ��������sapp_global_val->config.packet_io.depolyment_mode_binת���õ����ڲ�ֵ,����:NET_CONN_PARALLEL */ unsigned char create_stream_mode; /* ����ԭ������, ֵ������stream.tcp.syn_mandatoryת���õ� */ int packet_io_cap_level; sapp_gval_individual_fixed_fs_t fs_para; + pthread_t pkt_process_tid[SAPP_MAX_THREADS]; }sapp_gval_individual_fixed_t; typedef struct{ @@ -159,9 +162,10 @@ typedef struct{ typedef struct{ - time_t current_time; - long long current_time_ms; - char __padding[48]; + volatile time_t current_time; + volatile long long current_time_ms; + volatile int current_state; + char __padding[44]; }sapp_gval_individual_volatile_t; diff --git a/include/private/sapp_private_api.h b/include/private/sapp_private_api.h index ba978a9..cc7060b 100644 --- a/include/private/sapp_private_api.h +++ b/include/private/sapp_private_api.h @@ -33,6 +33,7 @@ #include "private/sapp_global_val.h"
#include "private/sapp_declaration.h"
#include "private/sapp_pkt_stat.h"
+#include "private/sapp_timer_private.h"
#if IOMODE_MARSIO
#include "/opt/mrzcpd/include/marsio.h"
diff --git a/include/private/sapp_timer_private.h b/include/private/sapp_timer_private.h new file mode 100644 index 0000000..ac5c74c --- /dev/null +++ b/include/private/sapp_timer_private.h @@ -0,0 +1,52 @@ +#ifndef _SAPP_TIMER_PRIVATE_H_ +#define _SAPP_TIMER_PRIVATE_H_ 1 + +#ifdef __cplusplus +extern "C" { +#endif + +#include "support/MESA_atomic.h" +#include "sapp_timer.h" +#include "support/event2/event.h" +#include "support/event2/event_struct.h" + +/* NOTE: the two effective scope options are conflict, can't use as same time */ +enum st_ef_scope_t{ + STO_EFFECTIVE_SCOPE_STANDALONE_THREAD = 1, + STO_EFFECTIVE_SCOPE_PKT_PROCESS_THREADS = 2, +}; + + +/* + NOTE: + 1.ÿ���߳�ֻ��һ��ev_base, ����ǰ������߳�����, ����thread_cnt��, ���ԺͶ����߳�һ����. + 2.add, newֻ����event�����̵߳���, ����ֻ�ڵ�ǰ�߳���Ч. +*/ +typedef struct{ + volatile MESA_ATOMIC_T running; + enum st_ef_scope_t effective_mode; + struct event_base *libev_base; + //struct event *libev_event[SAPP_MAX_THREADS+1]; + pthread_t effective_thread_pid; + int effective_thread_index; + + //int thread_cnt; /* sappƽ̨ʵ�ʲ����߳���, �����stand_alone�߳�, ��̶��洢�����һ��index, ��SAPP_TIMER_MAX_THREADS */ +}sapp_timer_handle_inner_t; + +/* event��Ҫʹ��set_opt���ø��ֲ���, �ýṹ�彫��struct event��װ, �洢��ز��� */ +typedef struct{ + struct event *libev_event; + sapp_timer_handle_inner_t *timer_handle; + event_callback_fn libev_cb_fun; + sapp_timer_cbfun_t *sapp_plug_cb_fun; + void *user_arg; + struct timeval tval; + int callback_count; // to do +}sapp_timer_event_inner_t; + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/include/public/sapp_api.h b/include/public/sapp_api.h index bdd1423..bfe69e0 100644 --- a/include/public/sapp_api.h +++ b/include/public/sapp_api.h @@ -53,6 +53,7 @@ #include "sapp_limits.h"
#include "sapp_state.h"
#include "sapp_cla.h"
+#include "sapp_timer.h"
#include "stream.h"
diff --git a/include/public/sapp_state.h b/include/public/sapp_state.h index b862d1e..6fd6e2f 100644 --- a/include/public/sapp_state.h +++ b/include/public/sapp_state.h @@ -1,18 +1,27 @@ #ifndef _SAPP_STATE_H_ #define _SAPP_STATE_H_ 1 +#ifdef __cplusplus +extern "C" { +#endif enum sapp_state_t{ SAPP_STATE_JUST_START, /* main() called by shell command */ SAPP_STATE_CONFIG_PARSE, SAPP_STATE_PLATFORM_INITING, SAPP_STATE_PLATFORM_INITED, - SAPP_STATE_PLUG_INITING, - SAPP_STATE_PLUG_INITED, SAPP_STATE_PKT_IO_INITING, SAPP_STATE_PKT_IO_INITED, + SAPP_STATE_PLUG_INITING, + SAPP_STATE_PLUG_INITED, SAPP_STATE_PROCESSING, SAPP_STATE_READY_TO_EXIT, /* only for pcap dumpfile */ }; +enum sapp_state_t sapp_get_current_state(void); + +#ifdef __cplusplus +} +#endif + #endif diff --git a/include/public/sapp_timer.h b/include/public/sapp_timer.h new file mode 100644 index 0000000..66bcce1 --- /dev/null +++ b/include/public/sapp_timer.h @@ -0,0 +1,75 @@ +#ifndef _SAPP_TIMER_H_ +#define _SAPP_TIMER_H_ 1 + +#ifdef __cplusplus +extern "C" { +#endif + +#include "sapp_limits.h" + +#if 0 + + +typedef enum{ + STO_EFFECTIVE_SCOPE, /* value type is int, refer to STO_EFFECTIVE_SCOPE_xxx */ + STO_PKT_PROCESS_THREAD_NUM, /* value type is int */ +}sapp_timer_opt; + +#endif + +enum st_return_errno{ + ST_RET_SUCC = 0, + ST_RET_ERROR = -1, + ST_RET_CANT_OP_PLATFORM_TIMER = -2, + ST_RET_INVALID_ARGS = -3, + ST_RET_NEED_MANDATORY_OPT = -4, + ST_RET_DIFF_THREAD_CONTEXT = -5, +}; + + +typedef enum{ + STEO_EFFECTIVE_THREAD_ID, /* value type is int */ + STEO_TIMEOUT_VAL, /* value type is struct timeval, refer to <linux/time.h> */ + STEO_CALLBACK_FUN, /* value type is sapp_timer_cbfun_t* */ + STEO_CALLBACK_FUN_ARG, /* value type is void* */ + STEO_CALLBACK_COUNT, /* value type is int */ +}sapp_event_opt; + +typedef void * sapp_timer_handle; +typedef void * sapp_timer_event; + +/* NOTE: this timer is active in a standalone thread context, is single thread. */ +sapp_timer_handle sapp_standalone_timer_new(void); + +/* NOTE: this timer is active in sapp packet process threads context, is multithread. */ +sapp_timer_handle sapp_get_platform_timer(int tid); + +/* + NOTE: + In sapp platform packet process thread context, the pkt_process_thread_id is in region: [0, max_thread_num-1]; + In stand_alone thread context, the pkt_process_thread_id is -1; +*/ +typedef void sapp_timer_cbfun_t(sapp_timer_handle h, sapp_timer_event ev, int pkt_process_thread_id, void *user_arg); + +/* + NOTE: + If you want use sapp platform timer, must call sapp_get_platform_timer(), not sapp_timer_new(). + If you want a independent private timer, must call sapp_timer_new(). +*/ +sapp_timer_event sapp_timer_event_new(sapp_timer_handle h); + +//int sapp_timer_set_opt(sapp_timer_handle h, sapp_timer_opt t_opt, void *t_value, int t_value_len); +int sapp_event_set_opt(sapp_timer_event ev, sapp_event_opt ev_opt, void *ev_value, int ev_value_len); + + +int sapp_timer_add(sapp_timer_handle h, sapp_timer_event ev); +int sapp_timer_del(sapp_timer_handle h, sapp_timer_event ev); +int sapp_timer_start(sapp_timer_handle h); +int sapp_timer_destroy(sapp_timer_handle h); + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/include/public/stream_inc/stream_control.h b/include/public/stream_inc/stream_control.h index 5384a31..506bf3d 100644 --- a/include/public/stream_inc/stream_control.h +++ b/include/public/stream_inc/stream_control.h @@ -223,6 +223,7 @@ int tcp_set_single_stream_max_unorder(const struct streaminfo *stream, UCHAR dir int tcp_set_single_stream_needack(const struct streaminfo *pstream);
int tcp_set_single_stream_takeoverflag(const struct streaminfo *pstream,int flag);
int stream_set_single_stream_timeout(const struct streaminfo *pstream,unsigned short timeout);
+int get_thread_count(void);
/****************************************************************************************
****************************************************************************************
****************************************************************************************/
diff --git a/include/support/MESA_atomic.h b/include/support/MESA_atomic.h new file mode 100644 index 0000000..7cddd08 --- /dev/null +++ b/include/support/MESA_atomic.h @@ -0,0 +1,41 @@ +#ifndef _MESA_ATOMIC_H_
+#define _MESA_ATOMIC_H_
+
+#ifdef __x86_64__
+
+#if(__GNUC__ * 100 + __GNUC_MINOR__ * 10 + __GNUC_PATCHLEVEL__ >= 411)
+typedef unsigned long MESA_ATOMIC_T;
+#define MESA_ATOMIC_SET(v, i) __sync_lock_test_and_set((&v), i)
+#define MESA_ATOMIC_READ(v) __sync_or_and_fetch((&v), 0)
+#define MESA_ATOMIC_INC(v) __sync_add_and_fetch((&v),1)
+#define MESA_ATOMIC_DEC(v) __sync_sub_and_fetch((&v),1)
+#define MESA_ATOMIC_ADD(v,add) __sync_add_and_fetch((&v),(add))
+#define MESA_ATOMIC_SUB(v,sub) __sync_sub_and_fetch((&v),(sub))
+#define MESA_EQUAL_SET(v, old_val, new_val) __sync_val_compare_and_swap((&v), old_val, new_val); /* if(v == old_val){v = new_val}; return old_val; */
+#else
+#include <alsa/iatomic.h>
+typedef atomic_t MESA_ATOMIC_T;
+#define MESA_ATOMIC_SET(v, i) atomic_set((&v), i)
+#define MESA_ATOMIC_READ(v) atomic_read((&v))
+#define MESA_ATOMIC_INC(v) atomic_inc((&v))
+#define MESA_ATOMIC_DEC(v) atomic_dec((&v))
+#define MESA_ATOMIC_ADD(v, add) atomic_add((add),(&v))
+#define MESA_ATOMIC_SUB(v, sub) atomic_sub((sub),(&v))
+#endif
+
+#endif /* __x86_64__ */
+
+
+#ifdef __tilegx__
+#include <arch/atomic.h>
+typedef int MESA_ATOMIC_T;
+#define MESA_ATOMIC_SET(v, i) arch_atomic_exchange((&v), i)
+#define MESA_ATOMIC_READ(v) arch_atomic_or((&v), 0)
+#define MESA_ATOMIC_INC(v) arch_atomic_add((&v), 1)
+#define MESA_ATOMIC_DEC(v) arch_atomic_sub((&v), 1)
+#define MESA_ATOMIC_ADD(v, add) arch_atomic_add((&v), add)
+#define MESA_ATOMIC_SUB(v, sub) arch_atomic_sub((&v), sub)
+#endif
+
+
+#endif
|
