1 #ifndef __TCP_STREAM_QUEUE_ 2 #define __TCP_STREAM_QUEUE_ 3 4 #include <stdint.h> 5 6 /* Lock definitions for stream queue */ 7 #if LOCK_STREAM_QUEUE 8 9 #if USE_SPIN_LOCK 10 #define SQ_LOCK_INIT(lock, errmsg, action); \ 11 if (pthread_spin_init(lock, PTHREAD_PROCESS_PRIVATE)) { \ 12 perror("pthread_spin_init" errmsg); \ 13 action; \ 14 } 15 #define SQ_LOCK_DESTROY(lock) pthread_spin_destroy(lock) 16 #define SQ_LOCK(lock) pthread_spin_lock(lock) 17 #define SQ_UNLOCK(lock) pthread_spin_unlock(lock) 18 #else 19 #define SQ_LOCK_INIT(lock, errmsg, action); \ 20 if (pthread_mutex_init(lock, NULL)) { \ 21 perror("pthread_mutex_init" errmsg); \ 22 action; \ 23 } 24 #define SQ_LOCK_DESTROY(lock) pthread_mutex_destroy(lock) 25 #define SQ_LOCK(lock) pthread_mutex_lock(lock) 26 #define SQ_UNLOCK(lock) pthread_mutex_unlock(lock) 27 #endif /* USE_SPIN_LOCK */ 28 29 #else /* LOCK_STREAM_QUEUE */ 30 #define SQ_LOCK_INIT(lock, errmsg, action) (void) 0 31 #define SQ_LOCK_DESTROY(lock) (void) 0 32 #define SQ_LOCK(lock) (void) 0 33 #define SQ_UNLOCK(lock) (void) 0 34 #endif /* LOCK_STREAM_QUEUE */ 35 36 /*---------------------------------------------------------------------------*/ 37 typedef struct stream_queue* stream_queue_t; 38 /*---------------------------------------------------------------------------*/ 39 typedef struct stream_queue_int 40 { 41 struct tcp_stream **array; 42 int size; 43 44 int first; 45 int last; 46 int count; 47 48 } stream_queue_int; 49 /*---------------------------------------------------------------------------*/ 50 stream_queue_int * 51 CreateInternalStreamQueue(int size); 52 /*---------------------------------------------------------------------------*/ 53 void 54 DestroyInternalStreamQueue(stream_queue_int *sq); 55 /*---------------------------------------------------------------------------*/ 56 int 57 StreamInternalEnqueue(stream_queue_int *sq, struct tcp_stream *stream); 58 /*---------------------------------------------------------------------------*/ 59 struct tcp_stream * 60 StreamInternalDequeue(stream_queue_int *sq); 61 /*---------------------------------------------------------------------------*/ 62 stream_queue_t 63 CreateStreamQueue(int size); 64 /*---------------------------------------------------------------------------*/ 65 void 66 DestroyStreamQueue(stream_queue_t sq); 67 /*---------------------------------------------------------------------------*/ 68 int 69 StreamEnqueue(stream_queue_t sq, struct tcp_stream *stream); 70 /*---------------------------------------------------------------------------*/ 71 struct tcp_stream * 72 StreamDequeue(stream_queue_t sq); 73 /*---------------------------------------------------------------------------*/ 74 int 75 StreamQueueIsEmpty(stream_queue_t sq); 76 /*---------------------------------------------------------------------------*/ 77 78 #endif /* __TCP_STREAM_QUEUE_ */ 79