tls_ct_q.h

Go to the documentation of this file.
00001 /* 
00002  * Copyright (C) 2010 iptelorg GmbH
00003  *
00004  * Permission to use, copy, modify, and distribute this software for any
00005  * purpose with or without fee is hereby granted, provided that the above
00006  * copyright notice and this permission notice appear in all copies.
00007  *
00008  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
00009  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
00010  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
00011  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
00012  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
00013  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
00014  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
00015  */
00016 
00026 /*
00027  * History:
00028  * --------
00029  *  2010-03-31  initial version (andrei)
00030 */
00031 
00032 #ifndef __tls_ct_q_h
00033 #define __tls_ct_q_h
00034 
00035 #include "sbufq.h"
00036 #include "../../compiler_opt.h"
00037 
00038 typedef struct sbuffer_queue tls_ct_q;
00039 
00040 
00041 #define tls_ct_q_empty(bq) ((bq)==0 || (bq)->first==0)
00042 #define tls_ct_q_non_empty(bq) ((bq) && (bq)->first!=0)
00043 
00044 
00055 inline static int tls_ct_q_add(tls_ct_q** ct_q, const void* data,
00056                                                                 unsigned int size, unsigned int min_buf_size)
00057 {
00058         tls_ct_q* q;
00059         
00060         q = *ct_q;
00061         if (likely(q == 0)){
00062                 q=shm_malloc(sizeof(tls_ct_q));
00063                 if (unlikely(q==0))
00064                         goto error;
00065                 memset(q, 0, sizeof(tls_ct_q));
00066                 *ct_q = q;
00067         }
00068         return sbufq_add(q, data, size, min_buf_size);
00069 error:
00070         return -1;
00071 }
00072 
00073 
00074 
00084 inline static unsigned int tls_ct_q_destroy(tls_ct_q** ct_q)
00085 {
00086         unsigned int ret;
00087         
00088         ret = 0;
00089         if (likely(ct_q && *ct_q)) {
00090                 ret = sbufq_destroy(*ct_q);
00091                 shm_free(*ct_q);
00092                 *ct_q = 0;
00093         }
00094         return ret;
00095 }
00096 
00097 
00098 
00124 inline static int tls_ct_q_flush(tls_ct_q** tc_q, int* flags,
00125                                                                 int (*flush_f)(void* p1, void* p2,
00126                                                                                                 const void* buf,
00127                                                                                                 unsigned size),
00128                                                                 void* flush_p1, void* flush_p2)
00129 {
00130         return *tc_q?sbufq_flush(*tc_q, flags, flush_f, flush_p1, flush_p2):0;
00131 }
00132 
00133 
00134 
00135 #endif /*__tls_ct_q_h*/
00136 
00137 /* vi: set ts=4 sw=4 tw=79:ai:cindent: */