You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

165 lines
4.9 KiB
C

12 months ago
/*
* Copyright (c) 2016-present The ZLMediaKit project authors. All Rights Reserved.
*
* This file is part of ZLMediaKit(https://github.com/ZLMediaKit/ZLMediaKit).
*
* Use of this source code is governed by MIT-like license that can be found in the
* LICENSE file in the root of the source tree. All contributing project authors
* may be found in the AUTHORS file in the root of the source tree.
*/
#ifndef MK_THREAD_H
#define MK_THREAD_H
#include <assert.h>
#include "mk_common.h"
#include "mk_tcp.h"
#ifdef __cplusplus
extern "C" {
#endif
///////////////////////////////////////////事件线程/////////////////////////////////////////////
typedef struct mk_thread_t *mk_thread;
/**
* tcp线
* @param ctx tcp
* @return 线
*/
API_EXPORT mk_thread API_CALL mk_thread_from_tcp_session(mk_tcp_session ctx);
/**
* tcp线
* @param ctx tcp
* @return 线
*/
API_EXPORT mk_thread API_CALL mk_thread_from_tcp_client(mk_tcp_client ctx);
/**
* 线线
* 线线
* 线io线
* @return 线
*/
API_EXPORT mk_thread API_CALL mk_thread_from_pool();
/**
* 线线
* 线线
* ZLMediaKit线dnsmp4
* @return 线
*/
API_EXPORT mk_thread API_CALL mk_thread_from_pool_work();
typedef struct mk_thread_pool_t *mk_thread_pool;
/**
* 线
* @param name 线便
* @param n_thread 线0cpu
* @param priority 线PRIORITY_LOWEST = 0,PRIORITY_LOW, PRIORITY_NORMAL, PRIORITY_HIGH, PRIORITY_HIGHEST
* @return 线
*/
API_EXPORT mk_thread_pool API_CALL mk_thread_pool_create(const char *name, size_t n_thread, int priority);
/**
* 线
* @param pool 线
* @return 0:
*/
API_EXPORT int API_CALL mk_thread_pool_release(mk_thread_pool pool);
/**
* 线线
* @param pool 线
* @return 线
*/
API_EXPORT mk_thread API_CALL mk_thread_from_thread_pool(mk_thread_pool pool);
///////////////////////////////////////////线程切换/////////////////////////////////////////////
typedef void (API_CALL *on_mk_async)(void *user_data);
/**
* 线
* @param ctx 线
* @param cb
* @param user_data
*/
API_EXPORT void API_CALL mk_async_do(mk_thread ctx, on_mk_async cb, void *user_data);
API_EXPORT void API_CALL mk_async_do2(mk_thread ctx, on_mk_async cb, void *user_data, on_user_data_free user_data_free);
/**
* 线
* @param ctx 线
* @param ms
* @param cb
* @param user_data
*/
API_EXPORT void API_CALL mk_async_do_delay(mk_thread ctx, size_t ms, on_mk_async cb, void *user_data);
API_EXPORT void API_CALL mk_async_do_delay2(mk_thread ctx, size_t ms, on_mk_async cb, void *user_data, on_user_data_free user_data_free);
/**
* 线
* @param ctx 线
* @param cb
* @param user_data
*/
API_EXPORT void API_CALL mk_sync_do(mk_thread ctx, on_mk_async cb, void *user_data);
///////////////////////////////////////////定时器/////////////////////////////////////////////
typedef struct mk_timer_t *mk_timer;
/**
*
* @return ()0
*/
typedef uint64_t (API_CALL *on_mk_timer)(void *user_data);
/**
*
* @param ctx 线
* @param delay_ms
* @param cb
* @param user_data
* @return
*/
API_EXPORT mk_timer API_CALL mk_timer_create(mk_thread ctx, uint64_t delay_ms, on_mk_timer cb, void *user_data);
API_EXPORT mk_timer API_CALL mk_timer_create2(mk_thread ctx, uint64_t delay_ms, on_mk_timer cb, void *user_data, on_user_data_free user_data_free);
/**
*
* @param ctx
*/
API_EXPORT void API_CALL mk_timer_release(mk_timer ctx);
///////////////////////////////////////////信号量/////////////////////////////////////////////
typedef struct mk_sem_t *mk_sem;
/**
*
*/
API_EXPORT mk_sem API_CALL mk_sem_create();
/**
*
*/
API_EXPORT void API_CALL mk_sem_release(mk_sem sem);
/**
* n
*/
API_EXPORT void API_CALL mk_sem_post(mk_sem sem, size_t n);
/**
* 1
* @param sem
*/
API_EXPORT void API_CALL mk_sem_wait(mk_sem sem);
#ifdef __cplusplus
}
#endif
#endif //MK_THREAD_H