Update Stellar export header and add stellar_get_current_thread_index() function

This commit is contained in:
luwenpeng
2024-04-22 20:01:15 +08:00
parent 8a41a79f06
commit 74f0504d3d
59 changed files with 134 additions and 87 deletions

View File

@@ -1,5 +1,5 @@
add_executable(stellar config.cpp stat.cpp stellar.cpp)
target_link_libraries(stellar timestamp plugin_manager session_manager ip_reassembly packet_io)
target_link_libraries(stellar timestamp plugin_manager session_manager ip_reassembly packet_io thread_idx)
target_link_libraries(stellar pthread fieldstat4 toml)
install(TARGETS stellar RUNTIME DESTINATION bin COMPONENT Program)

View File

@@ -1,15 +1,13 @@
#ifndef _STELLAR_H
#define _STELLAR_H
#ifndef _MACRO_H
#define _MACRO_H
#ifdef __cplusplus
extern "C"
{
#endif
#include <stdint.h>
#define MAX_THREAD_NUM 256
#define RX_BURST_MAX 32
#define MAX_THREAD_NUM 256 // limit by id_generator
#define ATOMIC_INC(x) __atomic_fetch_add(x, 1, __ATOMIC_RELAXED)
#define ATOMIC_DEC(x) __atomic_fetch_sub(x, 1, __ATOMIC_RELAXED)
@@ -23,16 +21,11 @@ extern "C"
#define unlikely(expr) __builtin_expect((expr), 0)
#ifdef STELLAR_GIT_VERSION
static __attribute__((__used__)) const char *__stellar_version = STELLAR_GIT_VERSION;
static __attribute__((__used__)) const char *__stellar_version = STELLAR_GIT_VERSION;
#else
static __attribute__((__used__)) const char *__stellar_version = "Unknown";
static __attribute__((__used__)) const char *__stellar_version = "Unknown";
#endif
static inline uint8_t stellar_get_current_thread_index()
{
return 0;
}
#ifdef __cplusplus
}
#endif

View File

@@ -10,11 +10,11 @@
#include "logo.h"
#include "stat.h"
#include "stellar.h"
#include "config.h"
#include "packet_private.h"
#include "packet_priv.h"
#include "packet_io.h"
#include "timestamp.h"
#include "thread_idx.h"
#include "id_generator.h"
#include "ip_reassembly.h"
#include "session_manager.h"
@@ -159,7 +159,6 @@ static void *work_thread(void *arg)
{
int nr_recv;
uint64_t now = 0;
uint16_t thr_idx = 0;
char thd_name[16] = {0};
void *plugin_ctx = NULL;
struct packet *pkt = NULL;
@@ -170,7 +169,8 @@ static void *work_thread(void *arg)
struct stellar_thread *thread = (struct stellar_thread *)arg;
struct ip_reassembly *ip_reass = thread->ip_mgr;
struct session_manager *sess_mgr = thread->sess_mgr;
thr_idx = thread->idx;
uint16_t thr_idx = thread->idx;
stellar_set_current_thread_index(thr_idx);
snprintf(thd_name, sizeof(thd_name), "stellar:%d", thr_idx);
prctl(PR_SET_NAME, (unsigned long long)thd_name, NULL, NULL, NULL);