Files
ETH_TCP_Demo/app/transaction.h
2026-03-04 08:50:04 +08:00

77 lines
1.7 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* transaction.h
*
* Created on: 2026-03-04
* Author: RT-Thread
*
* 功能: 事务管理模块头文件
* 依赖: RT-Thread Nano, osal
* 跨平台适配: 基于RT-Thread Nano使用标准API
*/
#ifndef TRANSACTION_H
#define TRANSACTION_H
#include <rtthread.h>
#include "osal.h"
/* 事务状态定义 */
typedef enum {
TRANSACTION_STATUS_IDLE = 0,
TRANSACTION_STATUS_ACTIVE,
TRANSACTION_STATUS_COMMITTED,
TRANSACTION_STATUS_ROLLED_BACK,
TRANSACTION_STATUS_INVALID
} transaction_status_t;
/* 回滚函数类型 */
typedef void (*transaction_rollback_func_t)(void *user_data);
/* 事务结构体 */
typedef struct {
int id; /* 事务ID */
transaction_status_t status; /* 事务状态 */
transaction_rollback_func_t rollback_func; /* 回滚函数 */
void *user_data; /* 用户数据 */
} transaction_t;
/* 最大事务数量 */
#define MAX_TRANSACTIONS 16
/**
* @brief 初始化事务管理
* @return 0 成功非0 失败
*/
int transaction_init(void);
/**
* @brief 开始事务
* @param rollback_func 回滚函数
* @param user_data 用户数据
* @return 事务ID失败返回0
*/
int transaction_begin(transaction_rollback_func_t rollback_func, void *user_data);
/**
* @brief 提交事务
* @param id 事务ID
* @return 0 成功非0 失败
*/
int transaction_commit(int id);
/**
* @brief 回滚事务
* @param id 事务ID
* @return 0 成功非0 失败
*/
int transaction_rollback(int id);
/**
* @brief 获取事务状态
* @param id 事务ID
* @return 事务状态
*/
transaction_status_t transaction_get_status(int id);
#endif /* TRANSACTION_H */