ZLMediaKit/api/include/mk_thread.h

162 lines
4.4 KiB
C++
Raw Normal View History

2019-12-27 10:46:40 +08:00
/*
2020-04-04 20:30:09 +08:00
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
2019-12-27 10:46:40 +08:00
*
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
2019-12-27 10:46:40 +08:00
*
2020-04-04 20:30:09 +08:00
* Use of this source code is governed by MIT 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.
2019-12-27 10:46:40 +08:00
*/
#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 void* 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);
2020-05-08 09:52:05 +08:00
/**
* 线线
* 线线
* 线io事件线程
* @return 线
*/
API_EXPORT mk_thread API_CALL mk_thread_from_pool();
/**
* 线线
* 线线
* ZLMediaKit中后台线程用于dns解析mp4点播时的文件解复用
* @return 线
*/
API_EXPORT mk_thread API_CALL mk_thread_from_pool_work();
2022-05-25 15:38:32 +08:00
typedef void* 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);
2019-12-27 10:46:40 +08:00
///////////////////////////////////////////线程切换/////////////////////////////////////////////
typedef void (API_CALL *on_mk_async)(void *user_data);
/**
* 线
* @param ctx 线
* @param cb
* @param user_data
*/
2022-05-25 15:38:32 +08:00
API_EXPORT void API_CALL mk_async_do(mk_thread ctx, on_mk_async cb, void *user_data);
/**
* 线
* @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);
2019-12-27 10:46:40 +08:00
/**
* 线
* @param ctx 线
* @param cb
* @param user_data
*/
2022-05-25 15:38:32 +08:00
API_EXPORT void API_CALL mk_sync_do(mk_thread ctx, on_mk_async cb, void *user_data);
2019-12-27 10:46:40 +08:00
///////////////////////////////////////////定时器/////////////////////////////////////////////
typedef void* 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
*/
2022-05-25 15:38:32 +08:00
API_EXPORT mk_timer API_CALL mk_timer_create(mk_thread ctx, uint64_t delay_ms, on_mk_timer cb, void *user_data);
2019-12-27 10:46:40 +08:00
/**
*
* @param ctx
*/
API_EXPORT void API_CALL mk_timer_release(mk_timer ctx);
2022-05-25 15:38:32 +08:00
///////////////////////////////////////////信号量/////////////////////////////////////////////
typedef void* 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);
2019-12-27 10:46:40 +08:00
#ifdef __cplusplus
}
#endif
#endif //MK_THREAD_H