00001 00007 #ifndef _TXC_BUFFER_H 00008 #define _TXC_BUFFER_H 00009 00010 #include <misc/result.h> 00011 00012 #define TXC_BUFFER_CIRCULAR_SIZE 1024*(64*2)*64 00013 #define TXC_BUFFER_CIRCULAR_NUM 32 00014 #define TXC_BUFFER_LINEAR_SIZE 1024*256 00015 #define TXC_BUFFER_LINEAR_NUM 32 00016 00017 typedef enum { 00018 TXC_BUFFER_STATE_NON_SPECULATIVE = 0, 00019 TXC_BUFFER_STATE_SPECULATIVE = 1 00020 } txc_buffer_state_t; 00021 00022 typedef struct txc_buffermgr_s txc_buffermgr_t; 00023 typedef struct txc_buffer_circular_s txc_buffer_circular_t; 00024 typedef struct txc_buffer_linear_s txc_buffer_linear_t; 00025 typedef struct txc_buffer_circular_memento_s txc_buffer_circular_memento_t; 00026 typedef struct txc_buffer_linear_memento_s txc_buffer_linear_memento_t; 00027 00028 extern txc_buffermgr_t *txc_g_buffermgr; 00029 00030 /* 00031 * Break the abstraction and make the buffer's internal structure visible 00032 * for better performance. 00033 */ 00034 00035 struct txc_buffer_circular_s { 00036 txc_buffermgr_t *manager; 00037 char *buf; 00038 unsigned int size_max; 00039 unsigned int primary_head; 00040 unsigned int primary_tail; 00041 unsigned int secondary_head; 00042 unsigned int secondary_tail; 00043 unsigned int speculative_primary_head; 00044 unsigned int speculative_primary_tail; 00045 unsigned int speculative_secondary_head; 00046 unsigned int speculative_secondary_tail; 00047 txc_buffer_state_t state; 00048 }; 00049 00050 00054 struct txc_buffer_linear_s { 00055 txc_buffermgr_t *manager; 00056 char *buf; 00057 unsigned int size_max; 00058 unsigned int cur_len; 00059 txc_buffer_state_t state; 00060 }; 00061 00062 00063 00064 txc_result_t txc_buffermgr_create(txc_buffermgr_t **); 00065 void txc_buffermgr_destroy(txc_buffermgr_t **); 00066 00067 txc_result_t txc_buffer_circular_create(txc_buffermgr_t *buffermgr, txc_buffer_circular_t **bufferp); 00068 void txc_buffer_circular_destroy(txc_buffer_circular_t **bufferp); 00069 txc_result_t txc_buffer_circular_init(txc_buffer_circular_t *buffer); 00070 00071 txc_result_t txc_buffer_linear_create(txc_buffermgr_t *buffermgr, txc_buffer_linear_t **bufferp); 00072 void txc_buffer_linear_destroy(txc_buffer_linear_t **bufferp); 00073 txc_result_t txc_buffer_linear_init(txc_buffer_linear_t *buffer); 00074 void *txc_buffer_linear_malloc(txc_buffer_linear_t *buffer, unsigned int size); 00075 void txc_buffer_linear_free(txc_buffer_linear_t *buffer, unsigned int size); 00076 00077 #endif