Changing mutex/spinlocks/conditions naming types

remotes/origin/master-1.0.x
Pablo Rincon 17 years ago committed by Victor Julien
parent 406ee2ce70
commit e26833be3f

@ -73,7 +73,7 @@ TmEcode AlertDebuglogIPv4(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq
CreateTimeString(&p->ts, timebuf, sizeof(timebuf)); CreateTimeString(&p->ts, timebuf, sizeof(timebuf));
sc_mutex_lock(&aft->file_ctx->fp_mutex); SCMutexLock(&aft->file_ctx->fp_mutex);
fprintf(aft->file_ctx->fp, "+================\n"); fprintf(aft->file_ctx->fp, "+================\n");
fprintf(aft->file_ctx->fp, "TIME: %s\n", timebuf); fprintf(aft->file_ctx->fp, "TIME: %s\n", timebuf);
@ -137,7 +137,7 @@ TmEcode AlertDebuglogIPv4(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq
PrintRawDataFp(aft->file_ctx->fp, p->pkt, p->pktlen); PrintRawDataFp(aft->file_ctx->fp, p->pkt, p->pktlen);
fflush(aft->file_ctx->fp); fflush(aft->file_ctx->fp);
sc_mutex_unlock(&aft->file_ctx->fp_mutex); SCMutexUnlock(&aft->file_ctx->fp_mutex);
return TM_ECODE_OK; return TM_ECODE_OK;
} }
@ -155,7 +155,7 @@ TmEcode AlertDebuglogIPv6(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq
CreateTimeString(&p->ts, timebuf, sizeof(timebuf)); CreateTimeString(&p->ts, timebuf, sizeof(timebuf));
sc_mutex_lock(&aft->file_ctx->fp_mutex); SCMutexLock(&aft->file_ctx->fp_mutex);
for (i = 0; i < p->alerts.cnt; i++) { for (i = 0; i < p->alerts.cnt; i++) {
PacketAlert *pa = &p->alerts.alerts[i]; PacketAlert *pa = &p->alerts.alerts[i];
char srcip[46], dstip[46]; char srcip[46], dstip[46];
@ -167,7 +167,7 @@ TmEcode AlertDebuglogIPv6(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq
timebuf, pa->gid, pa->sid, pa->rev, pa->msg, pa->prio, IPV6_GET_L4PROTO(p), srcip, p->sp, dstip, p->dp); timebuf, pa->gid, pa->sid, pa->rev, pa->msg, pa->prio, IPV6_GET_L4PROTO(p), srcip, p->sp, dstip, p->dp);
} }
fflush(aft->file_ctx->fp); fflush(aft->file_ctx->fp);
sc_mutex_unlock(&aft->file_ctx->fp_mutex); SCMutexUnlock(&aft->file_ctx->fp_mutex);
return TM_ECODE_OK; return TM_ECODE_OK;
} }

@ -91,7 +91,7 @@ TmEcode AlertFastlogIPv4(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq)
CreateTimeString(&p->ts, timebuf, sizeof(timebuf)); CreateTimeString(&p->ts, timebuf, sizeof(timebuf));
sc_mutex_lock(&aft->file_ctx->fp_mutex); SCMutexLock(&aft->file_ctx->fp_mutex);
for (i = 0; i < p->alerts.cnt; i++) { for (i = 0; i < p->alerts.cnt; i++) {
PacketAlert *pa = &p->alerts.alerts[i]; PacketAlert *pa = &p->alerts.alerts[i];
@ -104,7 +104,7 @@ TmEcode AlertFastlogIPv4(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq)
timebuf, pa->gid, pa->sid, pa->rev, pa->msg, pa->prio, IPV4_GET_IPPROTO(p), srcip, p->sp, dstip, p->dp); timebuf, pa->gid, pa->sid, pa->rev, pa->msg, pa->prio, IPV4_GET_IPPROTO(p), srcip, p->sp, dstip, p->dp);
} }
fflush(aft->file_ctx->fp); fflush(aft->file_ctx->fp);
sc_mutex_unlock(&aft->file_ctx->fp_mutex); SCMutexUnlock(&aft->file_ctx->fp_mutex);
return TM_ECODE_OK; return TM_ECODE_OK;
} }
@ -122,7 +122,7 @@ TmEcode AlertFastlogIPv6(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq)
CreateTimeString(&p->ts, timebuf, sizeof(timebuf)); CreateTimeString(&p->ts, timebuf, sizeof(timebuf));
sc_mutex_lock(&aft->file_ctx->fp_mutex); SCMutexLock(&aft->file_ctx->fp_mutex);
for (i = 0; i < p->alerts.cnt; i++) { for (i = 0; i < p->alerts.cnt; i++) {
PacketAlert *pa = &p->alerts.alerts[i]; PacketAlert *pa = &p->alerts.alerts[i];
@ -136,7 +136,7 @@ TmEcode AlertFastlogIPv6(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq)
fflush(aft->file_ctx->fp); fflush(aft->file_ctx->fp);
} }
sc_mutex_unlock(&aft->file_ctx->fp_mutex); SCMutexUnlock(&aft->file_ctx->fp_mutex);
return TM_ECODE_OK; return TM_ECODE_OK;
} }

@ -150,15 +150,15 @@ TmEcode AlertUnifiedAlert (ThreadVars *tv, Packet *p, void *data, PacketQueue *p
} }
/** check and enforce the filesize limit, thread safe */ /** check and enforce the filesize limit, thread safe */
sc_mutex_lock(&aun->file_ctx->fp_mutex); SCMutexLock(&aun->file_ctx->fp_mutex);
if ((aun->size_current + sizeof(hdr)) > aun->size_limit) { if ((aun->size_current + sizeof(hdr)) > aun->size_limit) {
if (AlertUnifiedAlertRotateFile(tv,aun) < 0) if (AlertUnifiedAlertRotateFile(tv,aun) < 0)
{ {
sc_mutex_unlock(&aun->file_ctx->fp_mutex); SCMutexUnlock(&aun->file_ctx->fp_mutex);
return TM_ECODE_FAILED; return TM_ECODE_FAILED;
} }
} }
sc_mutex_unlock(&aun->file_ctx->fp_mutex); SCMutexUnlock(&aun->file_ctx->fp_mutex);
/* XXX which one to add to this alert? Lets see how Snort solves this. /* XXX which one to add to this alert? Lets see how Snort solves this.
* For now just take last alert. */ * For now just take last alert. */

@ -156,15 +156,15 @@ TmEcode AlertUnifiedLog (ThreadVars *tv, Packet *p, void *data, PacketQueue *pq)
/* check and enforce the filesize limit */ /* check and enforce the filesize limit */
/** Wait for the mutex. We dont want all the threads rotating the file /** Wait for the mutex. We dont want all the threads rotating the file
* at the same time :) */ * at the same time :) */
sc_mutex_lock(&aun->file_ctx->fp_mutex); SCMutexLock(&aun->file_ctx->fp_mutex);
if ((aun->size_current + sizeof(hdr) + p->pktlen + ethh_offset) > aun->size_limit) { if ((aun->size_current + sizeof(hdr) + p->pktlen + ethh_offset) > aun->size_limit) {
if (AlertUnifiedLogRotateFile(tv,aun) < 0) if (AlertUnifiedLogRotateFile(tv,aun) < 0)
{ {
sc_mutex_unlock(&aun->file_ctx->fp_mutex); SCMutexUnlock(&aun->file_ctx->fp_mutex);
return TM_ECODE_FAILED; return TM_ECODE_FAILED;
} }
} }
sc_mutex_unlock(&aun->file_ctx->fp_mutex); SCMutexUnlock(&aun->file_ctx->fp_mutex);
/* XXX which one to add to this alert? Lets see how Snort solves this. /* XXX which one to add to this alert? Lets see how Snort solves this.
* For now just take last alert. */ * For now just take last alert. */

@ -217,15 +217,15 @@ int Unified2PacketTypeAlert (ThreadVars *t, Packet *p, void *data)
memcpy(write_buffer,&hdr,sizeof(Unified2AlertFileHeader)); memcpy(write_buffer,&hdr,sizeof(Unified2AlertFileHeader));
sc_mutex_lock(&aun->file_ctx->fp_mutex); SCMutexLock(&aun->file_ctx->fp_mutex);
if ((aun->size_current + (sizeof(hdr) + sizeof(phdr))) > aun->size_limit) { if ((aun->size_current + (sizeof(hdr) + sizeof(phdr))) > aun->size_limit) {
if (Unified2AlertRotateFile(t,aun) < 0) if (Unified2AlertRotateFile(t,aun) < 0)
{ {
sc_mutex_unlock(&aun->file_ctx->fp_mutex); SCMutexUnlock(&aun->file_ctx->fp_mutex);
return -1; return -1;
} }
} }
sc_mutex_unlock(&aun->file_ctx->fp_mutex); SCMutexUnlock(&aun->file_ctx->fp_mutex);
phdr.sensor_id = 0; phdr.sensor_id = 0;
phdr.linktype = htonl(p->datalink); phdr.linktype = htonl(p->datalink);
@ -292,15 +292,15 @@ int Unified2IPv6TypeAlert (ThreadVars *t, Packet *p, void *data, PacketQueue *pq
} }
/* check and enforce the filesize limit */ /* check and enforce the filesize limit */
sc_mutex_lock(&aun->file_ctx->fp_mutex); SCMutexLock(&aun->file_ctx->fp_mutex);
if ((aun->size_current +(sizeof(hdr) + sizeof(phdr))) > aun->size_limit) { if ((aun->size_current +(sizeof(hdr) + sizeof(phdr))) > aun->size_limit) {
if (Unified2AlertRotateFile(t,aun) < 0) if (Unified2AlertRotateFile(t,aun) < 0)
{ {
sc_mutex_unlock(&aun->file_ctx->fp_mutex); SCMutexUnlock(&aun->file_ctx->fp_mutex);
return -1; return -1;
} }
} }
sc_mutex_unlock(&aun->file_ctx->fp_mutex); SCMutexUnlock(&aun->file_ctx->fp_mutex);
/* XXX which one to add to this alert? Lets see how Snort solves this. /* XXX which one to add to this alert? Lets see how Snort solves this.
* For now just take last alert. */ * For now just take last alert. */
@ -403,15 +403,15 @@ int Unified2IPv4TypeAlert (ThreadVars *tv, Packet *p, void *data, PacketQueue *p
} }
/* check and enforce the filesize limit */ /* check and enforce the filesize limit */
sc_mutex_lock(&aun->file_ctx->fp_mutex); SCMutexLock(&aun->file_ctx->fp_mutex);
if ((aun->size_current +(sizeof(hdr) + sizeof(phdr))) > aun->size_limit) { if ((aun->size_current +(sizeof(hdr) + sizeof(phdr))) > aun->size_limit) {
if (Unified2AlertRotateFile(tv,aun) < 0) if (Unified2AlertRotateFile(tv,aun) < 0)
{ {
sc_mutex_unlock(&aun->file_ctx->fp_mutex); SCMutexUnlock(&aun->file_ctx->fp_mutex);
return -1; return -1;
} }
} }
sc_mutex_unlock(&aun->file_ctx->fp_mutex); SCMutexUnlock(&aun->file_ctx->fp_mutex);
/* XXX which one to add to this alert? Lets see how Snort solves this. /* XXX which one to add to this alert? Lets see how Snort solves this.
* For now just take last alert. */ * For now just take last alert. */

@ -307,12 +307,12 @@ int AppLayerHandleMsg(StreamMsg *smsg, char need_lock)
uint16_t alproto = ALPROTO_UNKNOWN; uint16_t alproto = ALPROTO_UNKNOWN;
int r = 0; int r = 0;
if (need_lock == TRUE) sc_mutex_lock(&smsg->flow->m); if (need_lock == TRUE) SCMutexLock(&smsg->flow->m);
TcpSession *ssn = smsg->flow->protoctx; TcpSession *ssn = smsg->flow->protoctx;
if (ssn != NULL) { if (ssn != NULL) {
alproto = ssn->alproto; alproto = ssn->alproto;
} }
if (need_lock == TRUE) sc_mutex_unlock(&smsg->flow->m); if (need_lock == TRUE) SCMutexUnlock(&smsg->flow->m);
if (ssn != NULL) { if (ssn != NULL) {
if (smsg->flags & STREAM_START) { if (smsg->flags & STREAM_START) {
@ -327,10 +327,10 @@ int AppLayerHandleMsg(StreamMsg *smsg, char need_lock)
smsg->data.data, smsg->data.data_len, smsg->flags); smsg->data.data, smsg->data.data_len, smsg->flags);
if (alproto != ALPROTO_UNKNOWN) { if (alproto != ALPROTO_UNKNOWN) {
/* store the proto and setup the L7 data array */ /* store the proto and setup the L7 data array */
if (need_lock == TRUE) sc_mutex_lock(&smsg->flow->m); if (need_lock == TRUE) SCMutexLock(&smsg->flow->m);
StreamL7DataPtrInit(ssn,StreamL7GetStorageSize()); StreamL7DataPtrInit(ssn,StreamL7GetStorageSize());
ssn->alproto = alproto; ssn->alproto = alproto;
if (need_lock == TRUE) sc_mutex_unlock(&smsg->flow->m); if (need_lock == TRUE) SCMutexUnlock(&smsg->flow->m);
r = AppLayerParse(smsg->flow, alproto, smsg->flags, r = AppLayerParse(smsg->flow, alproto, smsg->flags,
smsg->data.data, smsg->data.data_len, need_lock); smsg->data.data, smsg->data.data_len, need_lock);
@ -354,9 +354,9 @@ int AppLayerHandleMsg(StreamMsg *smsg, char need_lock)
} }
} }
if (need_lock == TRUE) sc_mutex_lock(&smsg->flow->m); if (need_lock == TRUE) SCMutexLock(&smsg->flow->m);
smsg->flow->use_cnt--; smsg->flow->use_cnt--;
if (need_lock == TRUE) sc_mutex_unlock(&smsg->flow->m); if (need_lock == TRUE) SCMutexUnlock(&smsg->flow->m);
/* return the used message to the queue */ /* return the used message to the queue */
StreamMsgReturnToPool(smsg); StreamMsgReturnToPool(smsg);

@ -30,7 +30,7 @@
#include "app-layer-htp.h" #include "app-layer-htp.h"
#ifdef DEBUG #ifdef DEBUG
static sc_mutex_t htp_state_mem_lock = PTHREAD_MUTEX_INITIALIZER; static SCMutex htp_state_mem_lock = PTHREAD_MUTEX_INITIALIZER;
static uint64_t htp_state_memuse = 0; static uint64_t htp_state_memuse = 0;
static uint64_t htp_state_memcnt = 0; static uint64_t htp_state_memcnt = 0;
#endif #endif
@ -50,10 +50,10 @@ static void *HTPStateAlloc(void)
((HtpState *)(s))->connp = htp_connp_create(cfg); ((HtpState *)(s))->connp = htp_connp_create(cfg);
#ifdef DEBUG #ifdef DEBUG
sc_mutex_lock(&htp_state_mem_lock); SCMutexLock(&htp_state_mem_lock);
htp_state_memcnt++; htp_state_memcnt++;
htp_state_memuse+=sizeof(HtpState); htp_state_memuse+=sizeof(HtpState);
sc_mutex_unlock(&htp_state_mem_lock); SCMutexUnlock(&htp_state_mem_lock);
#endif #endif
return s; return s;
} }
@ -70,10 +70,10 @@ static void HTPStateFree(void *s)
free(s); free(s);
#ifdef DEBUG #ifdef DEBUG
sc_mutex_lock(&htp_state_mem_lock); SCMutexLock(&htp_state_mem_lock);
htp_state_memcnt--; htp_state_memcnt--;
htp_state_memuse-=sizeof(HtpState); htp_state_memuse-=sizeof(HtpState);
sc_mutex_unlock(&htp_state_mem_lock); SCMutexUnlock(&htp_state_mem_lock);
#endif #endif
} }

@ -376,7 +376,7 @@ static int HTTPParseResponse(void *http_state, AppLayerParserState *pstate, uint
} }
#ifdef DEBUG #ifdef DEBUG
static sc_mutex_t http_state_mem_lock = PTHREAD_MUTEX_INITIALIZER; static SCMutex http_state_mem_lock = PTHREAD_MUTEX_INITIALIZER;
static uint64_t http_state_memuse = 0; static uint64_t http_state_memuse = 0;
static uint64_t http_state_memcnt = 0; static uint64_t http_state_memcnt = 0;
#endif #endif
@ -389,10 +389,10 @@ static void *HTTPStateAlloc(void) {
memset(s, 0, sizeof(HttpState)); memset(s, 0, sizeof(HttpState));
#ifdef DEBUG #ifdef DEBUG
sc_mutex_lock(&http_state_mem_lock); SCMutexLock(&http_state_mem_lock);
http_state_memcnt++; http_state_memcnt++;
http_state_memuse+=sizeof(HttpState); http_state_memuse+=sizeof(HttpState);
sc_mutex_unlock(&http_state_mem_lock); SCMutexUnlock(&http_state_mem_lock);
#endif #endif
return s; return s;
} }
@ -400,10 +400,10 @@ static void *HTTPStateAlloc(void) {
static void HTTPStateFree(void *s) { static void HTTPStateFree(void *s) {
free(s); free(s);
#ifdef DEBUG #ifdef DEBUG
sc_mutex_lock(&http_state_mem_lock); SCMutexLock(&http_state_mem_lock);
http_state_memcnt--; http_state_memcnt--;
http_state_memuse-=sizeof(HttpState); http_state_memuse-=sizeof(HttpState);
sc_mutex_unlock(&http_state_mem_lock); SCMutexUnlock(&http_state_mem_lock);
#endif #endif
} }
@ -422,9 +422,9 @@ void RegisterHTTPParsers(void) {
void HTTPAtExitPrintStats(void) { void HTTPAtExitPrintStats(void) {
#ifdef DEBUG #ifdef DEBUG
sc_mutex_lock(&http_state_mem_lock); SCMutexLock(&http_state_mem_lock);
SCLogDebug("http_state_memcnt %"PRIu64", http_state_memuse %"PRIu64"", http_state_memcnt, http_state_memuse); SCLogDebug("http_state_memcnt %"PRIu64", http_state_memuse %"PRIu64"", http_state_memcnt, http_state_memuse);
sc_mutex_unlock(&http_state_mem_lock); SCMutexUnlock(&http_state_mem_lock);
#endif #endif
} }

@ -681,9 +681,9 @@ int AppLayerParse(Flow *f, uint8_t proto, uint8_t flags, uint8_t *input,
if (parser_state_store == NULL) if (parser_state_store == NULL)
goto error; goto error;
if (need_lock == TRUE) sc_mutex_lock(&f->m); if (need_lock == TRUE) SCMutexLock(&f->m);
ssn->aldata[app_layer_sid] = (void *)parser_state_store; ssn->aldata[app_layer_sid] = (void *)parser_state_store;
if (need_lock == TRUE) sc_mutex_unlock(&f->m); if (need_lock == TRUE) SCMutexUnlock(&f->m);
} }
} else { } else {
SCLogDebug("No App Layer Data"); SCLogDebug("No App Layer Data");
@ -725,18 +725,18 @@ int AppLayerParse(Flow *f, uint8_t proto, uint8_t flags, uint8_t *input,
/* See if we already have a 'app layer' state */ /* See if we already have a 'app layer' state */
void *app_layer_state = NULL; void *app_layer_state = NULL;
if (need_lock == TRUE) sc_mutex_lock(&f->m); if (need_lock == TRUE) SCMutexLock(&f->m);
app_layer_state = ssn->aldata[p->storage_id]; app_layer_state = ssn->aldata[p->storage_id];
if (need_lock == TRUE) sc_mutex_unlock(&f->m); if (need_lock == TRUE) SCMutexUnlock(&f->m);
if (app_layer_state == NULL) { if (app_layer_state == NULL) {
app_layer_state = p->StateAlloc(); app_layer_state = p->StateAlloc();
if (app_layer_state == NULL) if (app_layer_state == NULL)
goto error; goto error;
if (need_lock == TRUE) sc_mutex_lock(&f->m); if (need_lock == TRUE) SCMutexLock(&f->m);
ssn->aldata[p->storage_id] = app_layer_state; ssn->aldata[p->storage_id] = app_layer_state;
if (need_lock == TRUE) sc_mutex_unlock(&f->m); if (need_lock == TRUE) SCMutexUnlock(&f->m);
} }
/* invoke the recursive parser */ /* invoke the recursive parser */
@ -748,9 +748,9 @@ int AppLayerParse(Flow *f, uint8_t proto, uint8_t flags, uint8_t *input,
/* set the packets to no inspection and reassembly for the TLS sessions */ /* set the packets to no inspection and reassembly for the TLS sessions */
if (parser_state->flags & APP_LAYER_PARSER_NO_INSPECTION) { if (parser_state->flags & APP_LAYER_PARSER_NO_INSPECTION) {
if (need_lock == TRUE) sc_mutex_lock(&f->m); if (need_lock == TRUE) SCMutexLock(&f->m);
FlowSetNoPayloadInspectionFlag(f); FlowSetNoPayloadInspectionFlag(f);
if (need_lock == TRUE) sc_mutex_unlock(&f->m); if (need_lock == TRUE) SCMutexUnlock(&f->m);
/* Set the no reassembly flag for both the stream in this TcpSession */ /* Set the no reassembly flag for both the stream in this TcpSession */
if (parser_state->flags & APP_LAYER_PARSER_NO_REASSEMBLY) { if (parser_state->flags & APP_LAYER_PARSER_NO_REASSEMBLY) {

@ -92,7 +92,7 @@ static void SCPerfInitOPCtx(void)
sc_perf_op_ctx->club_tm = 1; sc_perf_op_ctx->club_tm = 1;
/* init the lock used by SCPerfClubTMInst */ /* init the lock used by SCPerfClubTMInst */
if (sc_mutex_init(&sc_perf_op_ctx->pctmi_lock, NULL) != 0) { if (SCMutexInit(&sc_perf_op_ctx->pctmi_lock, NULL) != 0) {
SCLogError(SC_INITIALIZATION_ERROR, "error initializing pctmi mutex"); SCLogError(SC_INITIALIZATION_ERROR, "error initializing pctmi mutex");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
@ -156,9 +156,9 @@ static void *SCPerfMgmtThread(void *arg)
cond_time.tv_sec = time(NULL) + SC_PERF_MGMTT_TTS; cond_time.tv_sec = time(NULL) + SC_PERF_MGMTT_TTS;
cond_time.tv_nsec = 0; cond_time.tv_nsec = 0;
sc_mutex_lock(tv_local->m); SCMutexLock(tv_local->m);
sc_cond_timedwait(tv_local->cond, tv_local->m, &cond_time); SCCondTimedwait(tv_local->cond, tv_local->m, &cond_time);
sc_mutex_unlock(tv_local->m); SCMutexUnlock(tv_local->m);
SCPerfOutputCounters(); SCPerfOutputCounters();
@ -200,9 +200,9 @@ static void *SCPerfWakeupThread(void *arg)
cond_time.tv_sec = time(NULL) + SC_PERF_WUT_TTS; cond_time.tv_sec = time(NULL) + SC_PERF_WUT_TTS;
cond_time.tv_nsec = 0; cond_time.tv_nsec = 0;
sc_mutex_lock(tv_local->m); SCMutexLock(tv_local->m);
sc_cond_timedwait(tv_local->cond, tv_local->m, &cond_time); SCCondTimedwait(tv_local->cond, tv_local->m, &cond_time);
sc_mutex_unlock(tv_local->m); SCMutexUnlock(tv_local->m);
tv = tv_root[TVT_PPT]; tv = tv_root[TVT_PPT];
while (tv != NULL) { while (tv != NULL) {
@ -217,7 +217,7 @@ static void *SCPerfWakeupThread(void *arg)
* not, it should be okay */ * not, it should be okay */
tv->sc_perf_pctx.perf_flag = 1; tv->sc_perf_pctx.perf_flag = 1;
sc_cond_signal(&q->cond_q); SCCondSignal(&q->cond_q);
tv = tv->next; tv = tv->next;
} }
@ -701,7 +701,7 @@ static int SCPerfOutputCounterFileIface()
tv = tv_root[i]; tv = tv_root[i];
while (tv != NULL) { while (tv != NULL) {
sc_mutex_lock(&tv->sc_perf_pctx.m); SCMutexLock(&tv->sc_perf_pctx.m);
pc = tv->sc_perf_pctx.head; pc = tv->sc_perf_pctx.head;
while (pc != NULL) { while (pc != NULL) {
@ -728,7 +728,7 @@ static int SCPerfOutputCounterFileIface()
pc = pc->next; pc = pc->next;
} }
sc_mutex_unlock(&tv->sc_perf_pctx.m); SCMutexUnlock(&tv->sc_perf_pctx.m);
tv = tv->next; tv = tv->next;
} }
fflush(sc_perf_op_ctx->fp); fflush(sc_perf_op_ctx->fp);
@ -748,7 +748,7 @@ static int SCPerfOutputCounterFileIface()
for (i = 0; i < pctmi->size; i++) { for (i = 0; i < pctmi->size; i++) {
pc_heads[i] = pctmi->head[i]->head; pc_heads[i] = pctmi->head[i]->head;
sc_mutex_lock(&pctmi->head[i]->m); SCMutexLock(&pctmi->head[i]->m);
while(strcmp(pctmi->tm_name, pc_heads[i]->name->tm_name)) while(strcmp(pctmi->tm_name, pc_heads[i]->name->tm_name))
pc_heads[i] = pc_heads[i]->next; pc_heads[i] = pc_heads[i]->next;
@ -799,7 +799,7 @@ static int SCPerfOutputCounterFileIface()
} }
for (i = 0; i < pctmi->size; i++) for (i = 0; i < pctmi->size; i++)
sc_mutex_unlock(&pctmi->head[i]->m); SCMutexUnlock(&pctmi->head[i]->m);
pctmi = pctmi->next; pctmi = pctmi->next;
@ -1088,7 +1088,7 @@ int SCPerfAddToClubbedTMTable(char *tm_name, SCPerfContext *pctx)
return 0; return 0;
} }
sc_mutex_lock(&sc_perf_op_ctx->pctmi_lock); SCMutexLock(&sc_perf_op_ctx->pctmi_lock);
pctmi = sc_perf_op_ctx->pctmi; pctmi = sc_perf_op_ctx->pctmi;
prev = pctmi; prev = pctmi;
@ -1120,7 +1120,7 @@ int SCPerfAddToClubbedTMTable(char *tm_name, SCPerfContext *pctx)
else else
prev->next = temp; prev->next = temp;
sc_mutex_unlock(&sc_perf_op_ctx->pctmi_lock); SCMutexUnlock(&sc_perf_op_ctx->pctmi_lock);
return 1; return 1;
} }
@ -1129,7 +1129,7 @@ int SCPerfAddToClubbedTMTable(char *tm_name, SCPerfContext *pctx)
if (hpctx[i] != pctx) if (hpctx[i] != pctx)
continue; continue;
sc_mutex_unlock(&sc_perf_op_ctx->pctmi_lock); SCMutexUnlock(&sc_perf_op_ctx->pctmi_lock);
return 1; return 1;
} }
@ -1148,7 +1148,7 @@ int SCPerfAddToClubbedTMTable(char *tm_name, SCPerfContext *pctx)
} }
pctmi->size++; pctmi->size++;
sc_mutex_unlock(&sc_perf_op_ctx->pctmi_lock); SCMutexUnlock(&sc_perf_op_ctx->pctmi_lock);
return 1; return 1;
} }
@ -1504,7 +1504,7 @@ int SCPerfUpdateCounterArray(SCPerfCounterArray *pca, SCPerfContext *pctx,
pcae = pca->head; pcae = pca->head;
sc_mutex_lock(&pctx->m); SCMutexLock(&pctx->m);
pc = pctx->head; pc = pctx->head;
for (i = 1; i <= pca->size; i++) { for (i = 1; i <= pca->size; i++) {
@ -1523,7 +1523,7 @@ int SCPerfUpdateCounterArray(SCPerfCounterArray *pca, SCPerfContext *pctx,
} }
} }
sc_mutex_unlock(&pctx->m); SCMutexUnlock(&pctx->m);
pctx->perf_flag = 0; pctx->perf_flag = 0;

@ -119,7 +119,7 @@ typedef struct SCPerfContext_ {
uint16_t curr_id; uint16_t curr_id;
/* mutex to prevent simultaneous access during update_counter/output_stat */ /* mutex to prevent simultaneous access during update_counter/output_stat */
sc_mutex_t m; SCMutex m;
} SCPerfContext; } SCPerfContext;
/** /**
@ -187,7 +187,7 @@ typedef struct SCPerfOPIfaceContext_ {
uint32_t club_tm; uint32_t club_tm;
SCPerfClubTMInst *pctmi; SCPerfClubTMInst *pctmi;
sc_mutex_t pctmi_lock; SCMutex pctmi_lock;
} SCPerfOPIfaceContext; } SCPerfOPIfaceContext;

@ -201,7 +201,7 @@ typedef struct Packet_
uint8_t rtv_cnt; uint8_t rtv_cnt;
/* tunnel packet ref count */ /* tunnel packet ref count */
uint8_t tpr_cnt; uint8_t tpr_cnt;
sc_mutex_t mutex_rtv_cnt; SCMutex mutex_rtv_cnt;
/* tunnel stuff */ /* tunnel stuff */
uint8_t tunnel_proto; uint8_t tunnel_proto;
/* tunnel XXX convert to bitfield*/ /* tunnel XXX convert to bitfield*/
@ -297,8 +297,8 @@ typedef struct PacketQueue_ {
Packet *top; Packet *top;
Packet *bot; Packet *bot;
uint16_t len; uint16_t len;
sc_mutex_t mutex_q; SCMutex mutex_q;
sc_cond_t cond_q; SCCondT cond_q;
#ifdef DBG_PERF #ifdef DBG_PERF
uint16_t dbg_maxlen; uint16_t dbg_maxlen;
#endif /* DBG_PERF */ #endif /* DBG_PERF */
@ -382,22 +382,22 @@ typedef struct DecodeThreadVars_
#define TUNNEL_INCR_PKT_RTV(p) \ #define TUNNEL_INCR_PKT_RTV(p) \
{ \ { \
sc_mutex_lock((p)->root ? &(p)->root->mutex_rtv_cnt : &(p)->mutex_rtv_cnt); \ SCMutexLock((p)->root ? &(p)->root->mutex_rtv_cnt : &(p)->mutex_rtv_cnt); \
((p)->root ? (p)->root->rtv_cnt++ : (p)->rtv_cnt++); \ ((p)->root ? (p)->root->rtv_cnt++ : (p)->rtv_cnt++); \
sc_mutex_unlock((p)->root ? &(p)->root->mutex_rtv_cnt : &(p)->mutex_rtv_cnt); \ SCMutexUnlock((p)->root ? &(p)->root->mutex_rtv_cnt : &(p)->mutex_rtv_cnt); \
} }
#define TUNNEL_INCR_PKT_TPR(p) \ #define TUNNEL_INCR_PKT_TPR(p) \
{ \ { \
sc_mutex_lock((p)->root ? &(p)->root->mutex_rtv_cnt : &(p)->mutex_rtv_cnt); \ SCMutexLock((p)->root ? &(p)->root->mutex_rtv_cnt : &(p)->mutex_rtv_cnt); \
((p)->root ? (p)->root->tpr_cnt++ : (p)->tpr_cnt++); \ ((p)->root ? (p)->root->tpr_cnt++ : (p)->tpr_cnt++); \
sc_mutex_unlock((p)->root ? &(p)->root->mutex_rtv_cnt : &(p)->mutex_rtv_cnt); \ SCMutexUnlock((p)->root ? &(p)->root->mutex_rtv_cnt : &(p)->mutex_rtv_cnt); \
} }
#define TUNNEL_DECR_PKT_TPR(p) \ #define TUNNEL_DECR_PKT_TPR(p) \
{ \ { \
sc_mutex_lock((p)->root ? &(p)->root->mutex_rtv_cnt : &(p)->mutex_rtv_cnt); \ SCMutexLock((p)->root ? &(p)->root->mutex_rtv_cnt : &(p)->mutex_rtv_cnt); \
((p)->root ? (p)->root->tpr_cnt-- : (p)->tpr_cnt--); \ ((p)->root ? (p)->root->tpr_cnt-- : (p)->tpr_cnt--); \
sc_mutex_unlock((p)->root ? &(p)->root->mutex_rtv_cnt : &(p)->mutex_rtv_cnt); \ SCMutexUnlock((p)->root ? &(p)->root->mutex_rtv_cnt : &(p)->mutex_rtv_cnt); \
} }
#define TUNNEL_DECR_PKT_TPR_NOLOCK(p) \ #define TUNNEL_DECR_PKT_TPR_NOLOCK(p) \
{ \ { \

@ -75,13 +75,13 @@ typedef struct _DefragContext {
uint64_t ip6_frags; /**< Number of IPv6 fragments seen. */ uint64_t ip6_frags; /**< Number of IPv6 fragments seen. */
HashListTable *frag_table; /**< Hash (list) table of fragment trackers. */ HashListTable *frag_table; /**< Hash (list) table of fragment trackers. */
sc_mutex_t frag_table_lock; SCMutex frag_table_lock;
Pool *tracker_pool; /**< Pool of trackers. */ Pool *tracker_pool; /**< Pool of trackers. */
sc_mutex_t tracker_pool_lock; SCMutex tracker_pool_lock;
Pool *frag_pool; /**< Pool of fragments. */ Pool *frag_pool; /**< Pool of fragments. */
sc_mutex_t frag_pool_lock; SCMutex frag_pool_lock;
time_t timeout; /**< Default timeout. */ time_t timeout; /**< Default timeout. */
@ -133,7 +133,7 @@ typedef struct _DefragTracker {
uint8_t seen_last; /**< Has this tracker seen the last fragment? */ uint8_t seen_last; /**< Has this tracker seen the last fragment? */
sc_mutex_t lock; /**< Mutex for locking list operations on SCMutex lock; /**< Mutex for locking list operations on
* this tracker. */ * this tracker. */
TAILQ_HEAD(frag_tailq, _frag) frags; /**< Head of list of fragments. */ TAILQ_HEAD(frag_tailq, _frag) frags; /**< Head of list of fragments. */
@ -285,7 +285,7 @@ DefragTrackerFreeFrags(DefragTracker *tracker)
Frag *frag; Frag *frag;
/* Lock the frag pool as we'll be return items to it. */ /* Lock the frag pool as we'll be return items to it. */
sc_mutex_lock(&tracker->dc->frag_pool_lock); SCMutexLock(&tracker->dc->frag_pool_lock);
while ((frag = TAILQ_FIRST(&tracker->frags)) != NULL) { while ((frag = TAILQ_FIRST(&tracker->frags)) != NULL) {
TAILQ_REMOVE(&tracker->frags, frag, next); TAILQ_REMOVE(&tracker->frags, frag, next);
@ -295,7 +295,7 @@ DefragTrackerFreeFrags(DefragTracker *tracker)
PoolReturn(frag->dc->frag_pool, frag); PoolReturn(frag->dc->frag_pool, frag);
} }
sc_mutex_unlock(&tracker->dc->frag_pool_lock); SCMutexUnlock(&tracker->dc->frag_pool_lock);
} }
/** /**
@ -305,7 +305,7 @@ static void
DefragTrackerReset(DefragTracker *tracker) DefragTrackerReset(DefragTracker *tracker)
{ {
DefragContext *saved_dc = tracker->dc; DefragContext *saved_dc = tracker->dc;
sc_mutex_t saved_lock = tracker->lock; SCMutex saved_lock = tracker->lock;
DefragTrackerFreeFrags(tracker); DefragTrackerFreeFrags(tracker);
memset(tracker, 0, sizeof(*tracker)); memset(tracker, 0, sizeof(*tracker));
@ -332,7 +332,7 @@ DefragTrackerNew(void *arg)
tracker = calloc(1, sizeof(*tracker)); tracker = calloc(1, sizeof(*tracker));
if (tracker == NULL) if (tracker == NULL)
return NULL; return NULL;
if (sc_mutex_init(&tracker->lock, NULL) != 0) if (SCMutexInit(&tracker->lock, NULL) != 0)
return NULL; return NULL;
tracker->dc = dc; tracker->dc = dc;
TAILQ_INIT(&tracker->frags); TAILQ_INIT(&tracker->frags);
@ -349,7 +349,7 @@ DefragTrackerFree(void *arg)
{ {
DefragTracker *tracker = arg; DefragTracker *tracker = arg;
sc_mutex_destroy(&tracker->lock); SCMutexDestroy(&tracker->lock);
DefragTrackerFreeFrags(tracker); DefragTrackerFreeFrags(tracker);
free(tracker); free(tracker);
} }
@ -377,7 +377,7 @@ DefragContextNew(void)
"Defrag: Failed to initialize hash table."); "Defrag: Failed to initialize hash table.");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (sc_mutex_init(&dc->frag_table_lock, NULL) != 0) { if (SCMutexInit(&dc->frag_table_lock, NULL) != 0) {
SCLogError(SC_ERR_MEM_ALLOC, SCLogError(SC_ERR_MEM_ALLOC,
"Defrag: Failed to initialize hash table mutex."); "Defrag: Failed to initialize hash table mutex.");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
@ -395,7 +395,7 @@ DefragContextNew(void)
"Defrag: Failed to initialize tracker pool."); "Defrag: Failed to initialize tracker pool.");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (sc_mutex_init(&dc->tracker_pool_lock, NULL) != 0) { if (SCMutexInit(&dc->tracker_pool_lock, NULL) != 0) {
SCLogError(SC_ERR_MEM_ALLOC, SCLogError(SC_ERR_MEM_ALLOC,
"Defrag: Failed to initialize tracker pool mutex."); "Defrag: Failed to initialize tracker pool mutex.");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
@ -411,7 +411,7 @@ DefragContextNew(void)
"Defrag: Failed to initialize fragment pool."); "Defrag: Failed to initialize fragment pool.");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (sc_mutex_init(&dc->frag_pool_lock, NULL) != 0) { if (SCMutexInit(&dc->frag_pool_lock, NULL) != 0) {
SCLogError(SC_ERR_MEM_ALLOC, SCLogError(SC_ERR_MEM_ALLOC,
"Defrag: Failed to initialize frag pool mutex."); "Defrag: Failed to initialize frag pool mutex.");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
@ -479,7 +479,7 @@ Defrag4InsertFrag(DefragContext *dc, DefragTracker *tracker, Packet *p)
* instead of after. */ * instead of after. */
/* Lock this tracker as we'll be doing list operations on it. */ /* Lock this tracker as we'll be doing list operations on it. */
sc_mutex_lock(&tracker->lock); SCMutexLock(&tracker->lock);
/* Update timeout. */ /* Update timeout. */
tracker->timeout = p->ts; tracker->timeout = p->ts;
@ -618,16 +618,16 @@ insert:
} }
/* Allocate frag and insert. */ /* Allocate frag and insert. */
sc_mutex_lock(&dc->frag_pool_lock); SCMutexLock(&dc->frag_pool_lock);
new = PoolGet(dc->frag_pool); new = PoolGet(dc->frag_pool);
sc_mutex_unlock(&dc->frag_pool_lock); SCMutexUnlock(&dc->frag_pool_lock);
if (new == NULL) if (new == NULL)
goto done; goto done;
new->pkt = malloc(len); new->pkt = malloc(len);
if (new->pkt == NULL) { if (new->pkt == NULL) {
sc_mutex_lock(&dc->frag_pool_lock); SCMutexLock(&dc->frag_pool_lock);
PoolReturn(dc->frag_pool, new); PoolReturn(dc->frag_pool, new);
sc_mutex_unlock(&dc->frag_pool_lock); SCMutexUnlock(&dc->frag_pool_lock);
goto done; goto done;
} }
BUG_ON(ltrim > len); BUG_ON(ltrim > len);
@ -651,13 +651,13 @@ insert:
if (remove) { if (remove) {
TAILQ_REMOVE(&tracker->frags, prev, next); TAILQ_REMOVE(&tracker->frags, prev, next);
DefragFragReset(prev); DefragFragReset(prev);
sc_mutex_lock(&dc->frag_pool_lock); SCMutexLock(&dc->frag_pool_lock);
PoolReturn(dc->frag_pool, prev); PoolReturn(dc->frag_pool, prev);
sc_mutex_unlock(&dc->frag_pool_lock); SCMutexUnlock(&dc->frag_pool_lock);
} }
done: done:
sc_mutex_unlock(&tracker->lock); SCMutexUnlock(&tracker->lock);
} }
/** /**
@ -676,7 +676,7 @@ Defrag4Reassemble(ThreadVars *tv, DefragContext *dc, DefragTracker *tracker,
int len = 0; int len = 0;
/* Lock the tracker. */ /* Lock the tracker. */
sc_mutex_lock(&tracker->lock); SCMutexLock(&tracker->lock);
/* Should not be here unless we have seen the last fragment. */ /* Should not be here unless we have seen the last fragment. */
if (!tracker->seen_last) if (!tracker->seen_last)
@ -719,13 +719,13 @@ Defrag4Reassemble(ThreadVars *tv, DefragContext *dc, DefragTracker *tracker,
if (rp == NULL) { if (rp == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Failed to allocate packet for fragmentation re-assembly, dumping fragments."); SCLogError(SC_ERR_MEM_ALLOC, "Failed to allocate packet for fragmentation re-assembly, dumping fragments.");
sc_mutex_lock(&dc->frag_table_lock); SCMutexLock(&dc->frag_table_lock);
HashListTableRemove(dc->frag_table, tracker, sizeof(tracker)); HashListTableRemove(dc->frag_table, tracker, sizeof(tracker));
sc_mutex_unlock(&dc->frag_table_lock); SCMutexUnlock(&dc->frag_table_lock);
DefragTrackerReset(tracker); DefragTrackerReset(tracker);
sc_mutex_lock(&dc->tracker_pool_lock); SCMutexLock(&dc->tracker_pool_lock);
PoolReturn(dc->tracker_pool, tracker); PoolReturn(dc->tracker_pool, tracker);
sc_mutex_unlock(&dc->tracker_pool_lock); SCMutexUnlock(&dc->tracker_pool_lock);
goto done; goto done;
} }
@ -786,12 +786,12 @@ Defrag4Reassemble(ThreadVars *tv, DefragContext *dc, DefragTracker *tracker,
/* Remove the frag tracker. */ /* Remove the frag tracker. */
HashListTableRemove(dc->frag_table, tracker, sizeof(tracker)); HashListTableRemove(dc->frag_table, tracker, sizeof(tracker));
DefragTrackerReset(tracker); DefragTrackerReset(tracker);
sc_mutex_lock(&dc->tracker_pool_lock); SCMutexLock(&dc->tracker_pool_lock);
PoolReturn(dc->tracker_pool, tracker); PoolReturn(dc->tracker_pool, tracker);
sc_mutex_unlock(&dc->tracker_pool_lock); SCMutexUnlock(&dc->tracker_pool_lock);
done: done:
sc_mutex_unlock(&tracker->lock); SCMutexUnlock(&tracker->lock);
return rp; return rp;
} }
@ -864,18 +864,18 @@ Defrag4(ThreadVars *tv, DefragContext *dc, Packet *p)
lookup.id = IPV4_GET_IPID(p); lookup.id = IPV4_GET_IPID(p);
lookup.src_addr = p->src; lookup.src_addr = p->src;
lookup.dst_addr = p->dst; lookup.dst_addr = p->dst;
sc_mutex_lock(&dc->frag_table_lock); SCMutexLock(&dc->frag_table_lock);
tracker = HashListTableLookup(dc->frag_table, &lookup, sizeof(lookup)); tracker = HashListTableLookup(dc->frag_table, &lookup, sizeof(lookup));
sc_mutex_unlock(&dc->frag_table_lock); SCMutexUnlock(&dc->frag_table_lock);
if (tracker == NULL) { if (tracker == NULL) {
sc_mutex_lock(&dc->tracker_pool_lock); SCMutexLock(&dc->tracker_pool_lock);
tracker = PoolGet(dc->tracker_pool); tracker = PoolGet(dc->tracker_pool);
if (tracker == NULL) { if (tracker == NULL) {
/* Timeout trackers and try again. */ /* Timeout trackers and try again. */
DefragTimeoutTracker(dc, p); DefragTimeoutTracker(dc, p);
tracker = PoolGet(dc->tracker_pool); tracker = PoolGet(dc->tracker_pool);
} }
sc_mutex_unlock(&dc->tracker_pool_lock); SCMutexUnlock(&dc->tracker_pool_lock);
if (tracker == NULL) { if (tracker == NULL) {
/* Report memory error - actually a pool allocation error. */ /* Report memory error - actually a pool allocation error. */
SCLogError(SC_ERR_MEM_ALLOC, "Defrag: Failed to allocate tracker."); SCLogError(SC_ERR_MEM_ALLOC, "Defrag: Failed to allocate tracker.");
@ -890,15 +890,15 @@ Defrag4(ThreadVars *tv, DefragContext *dc, Packet *p)
/* XXX Do policy lookup. */ /* XXX Do policy lookup. */
tracker->policy = dc->default_policy; tracker->policy = dc->default_policy;
sc_mutex_lock(&dc->frag_table_lock); SCMutexLock(&dc->frag_table_lock);
if (HashListTableAdd(dc->frag_table, tracker, sizeof(*tracker)) != 0) { if (HashListTableAdd(dc->frag_table, tracker, sizeof(*tracker)) != 0) {
/* Failed to add new tracker. */ /* Failed to add new tracker. */
sc_mutex_unlock(&dc->frag_table_lock); SCMutexUnlock(&dc->frag_table_lock);
SCLogError(SC_ERR_MEM_ALLOC, SCLogError(SC_ERR_MEM_ALLOC,
"Defrag: Failed to add new tracker to hash table."); "Defrag: Failed to add new tracker to hash table.");
return NULL; return NULL;
} }
sc_mutex_unlock(&dc->frag_table_lock); SCMutexUnlock(&dc->frag_table_lock);
} }
if (!more_frags) { if (!more_frags) {

@ -63,7 +63,7 @@ int DetectFlowvarMatch (ThreadVars *t, DetectEngineThreadCtx *det_ctx, Packet *p
DetectFlowvarData *fd = (DetectFlowvarData *)m->ctx; DetectFlowvarData *fd = (DetectFlowvarData *)m->ctx;
/* we need a lock */ /* we need a lock */
sc_mutex_lock(&p->flow->m); SCMutexLock(&p->flow->m);
FlowVar *fv = FlowVarGet(p->flow, fd->idx); FlowVar *fv = FlowVarGet(p->flow, fd->idx);
if (fv != NULL) { if (fv != NULL) {
@ -71,7 +71,7 @@ int DetectFlowvarMatch (ThreadVars *t, DetectEngineThreadCtx *det_ctx, Packet *p
if (ptr != NULL) if (ptr != NULL)
ret = 1; ret = 1;
} }
sc_mutex_unlock(&p->flow->m); SCMutexUnlock(&p->flow->m);
return ret; return ret;
} }

@ -98,7 +98,7 @@ int DetectTlsVersionMatch (ThreadVars *t, DetectEngineThreadCtx *det_ctx, Flow *
} }
int ret = 0; int ret = 0;
sc_mutex_lock(&f->m); SCMutexLock(&f->m);
SCLogDebug("looking for tls_data->ver 0x%02X (flags 0x%02X)", tls_data->ver, flags); SCLogDebug("looking for tls_data->ver 0x%02X (flags 0x%02X)", tls_data->ver, flags);
if (flags & STREAM_TOCLIENT) { if (flags & STREAM_TOCLIENT) {
@ -110,7 +110,7 @@ int DetectTlsVersionMatch (ThreadVars *t, DetectEngineThreadCtx *det_ctx, Flow *
if (tls_data->ver == tls_state->client_version) if (tls_data->ver == tls_state->client_version)
ret = 1; ret = 1;
} }
sc_mutex_unlock(&f->m); SCMutexUnlock(&f->m);
SCReturnInt(ret); SCReturnInt(ret);
} }

@ -130,9 +130,9 @@ Packet *SetupPktWait (void)
Packet *p = NULL; Packet *p = NULL;
int r = 0; int r = 0;
do { do {
r = sc_mutex_lock(&packet_q.mutex_q); r = SCMutexLock(&packet_q.mutex_q);
p = PacketDequeue(&packet_q); p = PacketDequeue(&packet_q);
sc_mutex_unlock(&packet_q.mutex_q); SCMutexUnlock(&packet_q.mutex_q);
if (p == NULL) { if (p == NULL) {
//TmqDebugList(); //TmqDebugList();
@ -153,9 +153,9 @@ Packet *SetupPkt (void)
Packet *p = NULL; Packet *p = NULL;
int r = 0; int r = 0;
r = sc_mutex_lock(&packet_q.mutex_q); r = SCMutexLock(&packet_q.mutex_q);
p = PacketDequeue(&packet_q); p = PacketDequeue(&packet_q);
r = sc_mutex_unlock(&packet_q.mutex_q); r = SCMutexUnlock(&packet_q.mutex_q);
if (p == NULL) { if (p == NULL) {
TmqDebugList(); TmqDebugList();
@ -168,7 +168,7 @@ Packet *SetupPkt (void)
memset(p, 0, sizeof(Packet)); memset(p, 0, sizeof(Packet));
r = sc_mutex_init(&p->mutex_rtv_cnt, NULL); r = SCMutexInit(&p->mutex_rtv_cnt, NULL);
SCLogDebug("allocated a new packet..."); SCLogDebug("allocated a new packet...");
} }
@ -187,8 +187,8 @@ void GlobalInits()
int blah; int blah;
int r = 0; int r = 0;
for(blah=0;blah<256;blah++) { for(blah=0;blah<256;blah++) {
r |= sc_mutex_init(&trans_q[blah].mutex_q, NULL); r |= SCMutexInit(&trans_q[blah].mutex_q, NULL);
r |= sc_cond_init(&trans_q[blah].cond_q, NULL); r |= SCCondInit(&trans_q[blah].cond_q, NULL);
} }
if (r != 0) { if (r != 0) {
@ -196,13 +196,13 @@ void GlobalInits()
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
sc_mutex_init(&mutex_pending, NULL); SCMutexInit(&mutex_pending, NULL);
sc_cond_init(&cond_pending, NULL); SCCondInit(&cond_pending, NULL);
/* initialize packet queues Here! */ /* initialize packet queues Here! */
memset(&packet_q,0,sizeof(packet_q)); memset(&packet_q,0,sizeof(packet_q));
sc_mutex_init(&packet_q.mutex_q, NULL); SCMutexInit(&packet_q.mutex_q, NULL);
sc_cond_init(&packet_q.cond_q, NULL); SCCondInit(&packet_q.cond_q, NULL);
} }
@ -216,9 +216,9 @@ Packet *TunnelPktSetup(ThreadVars *t, DecodeThreadVars *dtv, Packet *parent, uin
int r = 0; int r = 0;
#if 0 #if 0
do { do {
r = sc_mutex_lock(&packet_q.mutex_q); r = SCMutexLock(&packet_q.mutex_q);
p = PacketDequeue(&packet_q); p = PacketDequeue(&packet_q);
sc_mutex_unlock(&packet_q.mutex_q); SCMutexUnlock(&packet_q.mutex_q);
if (p == NULL) { if (p == NULL) {
//TmqDebugList(); //TmqDebugList();
@ -229,13 +229,13 @@ Packet *TunnelPktSetup(ThreadVars *t, DecodeThreadVars *dtv, Packet *parent, uin
} }
} while (p == NULL); } while (p == NULL);
#endif #endif
r = sc_mutex_lock(&mutex_pending); r = SCMutexLock(&mutex_pending);
pending++; pending++;
#ifdef DBG_PERF #ifdef DBG_PERF
if (pending > dbg_maxpending) if (pending > dbg_maxpending)
dbg_maxpending = pending; dbg_maxpending = pending;
#endif /* DBG_PERF */ #endif /* DBG_PERF */
sc_mutex_unlock(&mutex_pending); SCMutexUnlock(&mutex_pending);
/* set the root ptr to the lowest layer */ /* set the root ptr to the lowest layer */
if (parent->root != NULL) if (parent->root != NULL)
@ -543,7 +543,7 @@ int main(int argc, char **argv)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
memset(p, 0, sizeof(Packet)); memset(p, 0, sizeof(Packet));
sc_mutex_init(&p->mutex_rtv_cnt, NULL); SCMutexInit(&p->mutex_rtv_cnt, NULL);
PacketEnqueue(&packet_q,p); PacketEnqueue(&packet_q,p);
} }
@ -633,10 +633,10 @@ int main(int argc, char **argv)
if (sigflags & EIDPS_SIGTERM || sigflags & EIDPS_KILL) if (sigflags & EIDPS_SIGTERM || sigflags & EIDPS_KILL)
break; break;
sc_mutex_lock(&mutex_pending); SCMutexLock(&mutex_pending);
if (pending == 0) if (pending == 0)
done = 1; done = 1;
sc_mutex_unlock(&mutex_pending); SCMutexUnlock(&mutex_pending);
if (done == 0) { if (done == 0) {
usleep(100); usleep(100);

@ -28,8 +28,8 @@ uint32_t pending;
#ifdef DBG_PERF #ifdef DBG_PERF
uint32_t dbg_maxpending; uint32_t dbg_maxpending;
#endif /* DBG_PERF */ #endif /* DBG_PERF */
sc_mutex_t mutex_pending; SCMutex mutex_pending;
sc_cond_t cond_pending; SCCondT cond_pending;
/* preallocated packet structures here /* preallocated packet structures here
* XXX move to the packetpool queue handler code * XXX move to the packetpool queue handler code

@ -48,12 +48,12 @@ static void FlowBitAdd(Flow *f, uint16_t idx) {
//printf("FlowBitAdd: adding flowbit with idx %" PRIu32 "\n", idx); //printf("FlowBitAdd: adding flowbit with idx %" PRIu32 "\n", idx);
#ifdef FLOWBITS_STATS #ifdef FLOWBITS_STATS
sc_mutex_lock(&flowbits_mutex); SCMutexLock(&flowbits_mutex);
flowbits_added++; flowbits_added++;
flowbits_memuse += sizeof(FlowBit); flowbits_memuse += sizeof(FlowBit);
if (flowbits_memuse > flowbits_memuse_max) if (flowbits_memuse > flowbits_memuse_max)
flowbits_memuse_max = flowbits_memuse; flowbits_memuse_max = flowbits_memuse;
sc_mutex_unlock(&flowbits_mutex); SCMutexUnlock(&flowbits_mutex);
#endif /* FLOWBITS_STATS */ #endif /* FLOWBITS_STATS */
} }
} }
@ -67,7 +67,7 @@ static void FlowBitRemove(Flow *f, uint16_t idx) {
//printf("FlowBitRemove: remove flowbit with idx %" PRIu32 "\n", idx); //printf("FlowBitRemove: remove flowbit with idx %" PRIu32 "\n", idx);
#ifdef FLOWBITS_STATS #ifdef FLOWBITS_STATS
sc_mutex_lock(&flowbits_mutex); SCMutexLock(&flowbits_mutex);
flowbits_removed++; flowbits_removed++;
if (flowbits_memuse >= sizeof(FlowBit)) if (flowbits_memuse >= sizeof(FlowBit))
flowbits_memuse -= sizeof(FlowBit); flowbits_memuse -= sizeof(FlowBit);
@ -75,34 +75,34 @@ static void FlowBitRemove(Flow *f, uint16_t idx) {
printf("ERROR: flowbits memory usage going below 0!\n"); printf("ERROR: flowbits memory usage going below 0!\n");
flowbits_memuse = 0; flowbits_memuse = 0;
} }
sc_mutex_unlock(&flowbits_mutex); SCMutexUnlock(&flowbits_mutex);
#endif /* FLOWBITS_STATS */ #endif /* FLOWBITS_STATS */
} }
void FlowBitSet(Flow *f, uint16_t idx) { void FlowBitSet(Flow *f, uint16_t idx) {
sc_mutex_lock(&f->m); SCMutexLock(&f->m);
FlowBit *fb = FlowBitGet(f, idx); FlowBit *fb = FlowBitGet(f, idx);
if (fb == NULL) { if (fb == NULL) {
FlowBitAdd(f, idx); FlowBitAdd(f, idx);
} }
sc_mutex_unlock(&f->m); SCMutexUnlock(&f->m);
} }
void FlowBitUnset(Flow *f, uint16_t idx) { void FlowBitUnset(Flow *f, uint16_t idx) {
sc_mutex_lock(&f->m); SCMutexLock(&f->m);
FlowBit *fb = FlowBitGet(f, idx); FlowBit *fb = FlowBitGet(f, idx);
if (fb != NULL) { if (fb != NULL) {
FlowBitRemove(f, idx); FlowBitRemove(f, idx);
} }
sc_mutex_unlock(&f->m); SCMutexUnlock(&f->m);
} }
void FlowBitToggle(Flow *f, uint16_t idx) { void FlowBitToggle(Flow *f, uint16_t idx) {
sc_mutex_lock(&f->m); SCMutexLock(&f->m);
FlowBit *fb = FlowBitGet(f, idx); FlowBit *fb = FlowBitGet(f, idx);
if (fb != NULL) { if (fb != NULL) {
@ -111,32 +111,32 @@ void FlowBitToggle(Flow *f, uint16_t idx) {
FlowBitAdd(f, idx); FlowBitAdd(f, idx);
} }
sc_mutex_unlock(&f->m); SCMutexUnlock(&f->m);
} }
int FlowBitIsset(Flow *f, uint16_t idx) { int FlowBitIsset(Flow *f, uint16_t idx) {
int r = 0; int r = 0;
sc_mutex_lock(&f->m); SCMutexLock(&f->m);
FlowBit *fb = FlowBitGet(f, idx); FlowBit *fb = FlowBitGet(f, idx);
if (fb != NULL) { if (fb != NULL) {
r = 1; r = 1;
} }
sc_mutex_unlock(&f->m); SCMutexUnlock(&f->m);
return r; return r;
} }
int FlowBitIsnotset(Flow *f, uint16_t idx) { int FlowBitIsnotset(Flow *f, uint16_t idx) {
int r = 0; int r = 0;
sc_mutex_lock(&f->m); SCMutexLock(&f->m);
FlowBit *fb = FlowBitGet(f, idx); FlowBit *fb = FlowBitGet(f, idx);
if (fb == NULL) { if (fb == NULL) {
r = 1; r = 1;
} }
sc_mutex_unlock(&f->m); SCMutexUnlock(&f->m);
return r; return r;
} }
@ -147,7 +147,7 @@ void FlowBitFree(FlowBit *fb) {
free(fb); free(fb);
#ifdef FLOWBITS_STATS #ifdef FLOWBITS_STATS
sc_mutex_lock(&flowbits_mutex); SCMutexLock(&flowbits_mutex);
flowbits_removed++; flowbits_removed++;
if (flowbits_memuse >= sizeof(FlowBit)) if (flowbits_memuse >= sizeof(FlowBit))
flowbits_memuse -= sizeof(FlowBit); flowbits_memuse -= sizeof(FlowBit);
@ -155,7 +155,7 @@ void FlowBitFree(FlowBit *fb) {
printf("ERROR: flowbits memory usage going below 0!\n"); printf("ERROR: flowbits memory usage going below 0!\n");
flowbits_memuse = 0; flowbits_memuse = 0;
} }
sc_mutex_unlock(&flowbits_mutex); SCMutexUnlock(&flowbits_mutex);
#endif /* FLOWBITS_STATS */ #endif /* FLOWBITS_STATS */
} }

@ -77,7 +77,7 @@ Flow *FlowGetFlowFromHash (Packet *p)
uint32_t key = FlowGetKey(p); uint32_t key = FlowGetKey(p);
/* get our hash bucket and lock it */ /* get our hash bucket and lock it */
FlowBucket *fb = &flow_hash[key]; FlowBucket *fb = &flow_hash[key];
sc_mutex_lock(&fb->m); SCMutexLock(&fb->m);
SCLogDebug("FlowGetFlowFromHash: fb %p fb->f %p", fb, fb->f); SCLogDebug("FlowGetFlowFromHash: fb %p fb->f %p", fb, fb->f);
@ -90,7 +90,7 @@ Flow *FlowGetFlowFromHash (Packet *p)
f = fb->f = FlowAlloc(); f = fb->f = FlowAlloc();
if (f == NULL) { if (f == NULL) {
sc_mutex_unlock(&fb->m); SCMutexUnlock(&fb->m);
return NULL; return NULL;
} }
} }
@ -99,25 +99,25 @@ Flow *FlowGetFlowFromHash (Packet *p)
f->hprev = NULL; f->hprev = NULL;
/* got one, now lock, initialize and return */ /* got one, now lock, initialize and return */
sc_mutex_lock(&f->m); SCMutexLock(&f->m);
FlowInit(f,p); FlowInit(f,p);
FlowRequeue(f, NULL, &flow_new_q[f->protomap]); FlowRequeue(f, NULL, &flow_new_q[f->protomap]);
f->flags |= FLOW_NEW_LIST; f->flags |= FLOW_NEW_LIST;
f->fb = fb; f->fb = fb;
sc_mutex_unlock(&fb->m); SCMutexUnlock(&fb->m);
return f; return f;
} }
/* ok, we have a flow in the bucket. Let's find out if it is our flow */ /* ok, we have a flow in the bucket. Let's find out if it is our flow */
f = fb->f; f = fb->f;
/* lock the 'root' flow */ /* lock the 'root' flow */
sc_mutex_lock(&f->m); SCMutexLock(&f->m);
/* see if this is the flow we are looking for */ /* see if this is the flow we are looking for */
if (CMP_FLOW(f, p) == 0) { if (CMP_FLOW(f, p) == 0) {
Flow *pf = NULL; /* previous flow */ Flow *pf = NULL; /* previous flow */
sc_mutex_unlock(&f->m); SCMutexUnlock(&f->m);
while (f) { while (f) {
pf = f; /* pf is not locked at this point */ pf = f; /* pf is not locked at this point */
@ -131,7 +131,7 @@ Flow *FlowGetFlowFromHash (Packet *p)
f = fb->f = FlowAlloc(); f = fb->f = FlowAlloc();
if (f == NULL) { if (f == NULL) {
sc_mutex_unlock(&fb->m); SCMutexUnlock(&fb->m);
return NULL; return NULL;
} }
} }
@ -140,18 +140,18 @@ Flow *FlowGetFlowFromHash (Packet *p)
f->hprev = pf; f->hprev = pf;
/* lock, initialize and return */ /* lock, initialize and return */
sc_mutex_lock(&f->m); SCMutexLock(&f->m);
FlowInit(f,p); FlowInit(f,p);
FlowRequeue(f, NULL, &flow_new_q[f->protomap]); FlowRequeue(f, NULL, &flow_new_q[f->protomap]);
f->flags |= FLOW_NEW_LIST; f->flags |= FLOW_NEW_LIST;
f->fb = fb; f->fb = fb;
sc_mutex_unlock(&fb->m); SCMutexUnlock(&fb->m);
return f; return f;
} }
sc_mutex_lock(&f->m); SCMutexLock(&f->m);
if (CMP_FLOW(f, p) != 0) { if (CMP_FLOW(f, p) != 0) {
/* we found our flow, lets put it on top of the /* we found our flow, lets put it on top of the
@ -165,18 +165,18 @@ Flow *FlowGetFlowFromHash (Packet *p)
fb->f = f; fb->f = f;
/* found our flow */ /* found our flow */
sc_mutex_unlock(&fb->m); SCMutexUnlock(&fb->m);
return f; return f;
} }
/* not found, try the next... */ /* not found, try the next... */
sc_mutex_unlock(&f->m); SCMutexUnlock(&f->m);
} }
} }
/* The 'root' flow was our flow, return it. /* The 'root' flow was our flow, return it.
* It's already locked. */ * It's already locked. */
sc_mutex_unlock(&fb->m); SCMutexUnlock(&fb->m);
return f; return f;
} }

@ -9,7 +9,7 @@
* to the list, the entire bucket is locked. */ * to the list, the entire bucket is locked. */
typedef struct FlowBucket_ { typedef struct FlowBucket_ {
Flow *f; Flow *f;
sc_mutex_t m; SCMutex m;
} FlowBucket; } FlowBucket;
/* prototypes */ /* prototypes */

@ -85,7 +85,7 @@ FlowConfig flow_config;
uint8_t flow_flags; uint8_t flow_flags;
uint32_t flow_memuse; uint32_t flow_memuse;
sc_mutex_t flow_memuse_mutex; SCMutex flow_memuse_mutex;
#define FLOWBITS_STATS #define FLOWBITS_STATS
#ifdef FLOWBITS_STATS #ifdef FLOWBITS_STATS
@ -93,7 +93,7 @@ uint32_t flowbits_memuse;
uint32_t flowbits_memuse_max; uint32_t flowbits_memuse_max;
uint32_t flowbits_added; uint32_t flowbits_added;
uint32_t flowbits_removed; uint32_t flowbits_removed;
sc_mutex_t flowbits_mutex; SCMutex flowbits_mutex;
#endif /* FLOWBITS_STATS */ #endif /* FLOWBITS_STATS */
#endif /* __FLOW_PRIVATE_H__ */ #endif /* __FLOW_PRIVATE_H__ */

@ -23,8 +23,8 @@ FlowQueue *FlowQueueNew() {
FlowQueue *FlowQueueInit (FlowQueue *q) { FlowQueue *FlowQueueInit (FlowQueue *q) {
if (q != NULL) { if (q != NULL) {
memset(q, 0, sizeof(FlowQueue)); memset(q, 0, sizeof(FlowQueue));
sc_mutex_init(&q->mutex_q, NULL); SCMutexInit(&q->mutex_q, NULL);
sc_cond_init(&q->cond_q, NULL); SCCondInit(&q->cond_q, NULL);
} }
return q; return q;
} }
@ -48,11 +48,11 @@ void FlowEnqueue (FlowQueue *q, Flow *f) {
} }
Flow *FlowDequeue (FlowQueue *q) { Flow *FlowDequeue (FlowQueue *q) {
sc_mutex_lock(&q->mutex_q); SCMutexLock(&q->mutex_q);
Flow *f = q->bot; Flow *f = q->bot;
if (f == NULL) { if (f == NULL) {
sc_mutex_unlock(&q->mutex_q); SCMutexUnlock(&q->mutex_q);
return NULL; return NULL;
} }
@ -71,7 +71,7 @@ Flow *FlowDequeue (FlowQueue *q) {
f->lnext = NULL; f->lnext = NULL;
f->lprev = NULL; f->lprev = NULL;
sc_mutex_unlock(&q->mutex_q); SCMutexUnlock(&q->mutex_q);
return f; return f;
} }
@ -79,7 +79,7 @@ void FlowRequeue(Flow *f, FlowQueue *srcq, FlowQueue *dstq)
{ {
if (srcq != NULL) if (srcq != NULL)
{ {
sc_mutex_lock(&srcq->mutex_q); SCMutexLock(&srcq->mutex_q);
/* remove from old queue */ /* remove from old queue */
if (srcq->top == f) if (srcq->top == f)
@ -97,11 +97,11 @@ void FlowRequeue(Flow *f, FlowQueue *srcq, FlowQueue *dstq)
f->lprev = NULL; f->lprev = NULL;
/* don't unlock if src and dst are the same */ /* don't unlock if src and dst are the same */
if (srcq != dstq) sc_mutex_unlock(&srcq->mutex_q); if (srcq != dstq) SCMutexUnlock(&srcq->mutex_q);
} }
/* now put it in dst */ /* now put it in dst */
if (srcq != dstq) sc_mutex_lock(&dstq->mutex_q); if (srcq != dstq) SCMutexLock(&dstq->mutex_q);
/* add to new queue (append) */ /* add to new queue (append) */
f->lprev = dstq->bot; f->lprev = dstq->bot;
@ -118,6 +118,6 @@ void FlowRequeue(Flow *f, FlowQueue *srcq, FlowQueue *dstq)
dstq->dbg_maxlen = dstq->len; dstq->dbg_maxlen = dstq->len;
#endif /* DBG_PERF */ #endif /* DBG_PERF */
sc_mutex_unlock(&dstq->mutex_q); SCMutexUnlock(&dstq->mutex_q);
} }

@ -12,8 +12,8 @@ typedef struct FlowQueue_
Flow *top; Flow *top;
Flow *bot; Flow *bot;
uint32_t len; uint32_t len;
sc_mutex_t mutex_q; SCMutex mutex_q;
sc_cond_t cond_q; SCCondT cond_q;
#ifdef DBG_PERF #ifdef DBG_PERF
uint32_t dbg_maxlen; uint32_t dbg_maxlen;
#endif /* DBG_PERF */ #endif /* DBG_PERF */

@ -15,20 +15,20 @@ Flow *FlowAlloc(void)
{ {
Flow *f; Flow *f;
sc_mutex_lock(&flow_memuse_mutex); SCMutexLock(&flow_memuse_mutex);
if (flow_memuse + sizeof(Flow) > flow_config.memcap) { if (flow_memuse + sizeof(Flow) > flow_config.memcap) {
sc_mutex_unlock(&flow_memuse_mutex); SCMutexUnlock(&flow_memuse_mutex);
return NULL; return NULL;
} }
f = malloc(sizeof(Flow)); f = malloc(sizeof(Flow));
if (f == NULL) { if (f == NULL) {
sc_mutex_unlock(&flow_memuse_mutex); SCMutexUnlock(&flow_memuse_mutex);
return NULL; return NULL;
} }
flow_memuse += sizeof(Flow); flow_memuse += sizeof(Flow);
sc_mutex_unlock(&flow_memuse_mutex); SCMutexUnlock(&flow_memuse_mutex);
sc_mutex_init(&f->m, NULL); SCMutexInit(&f->m, NULL);
f->lnext = NULL; f->lnext = NULL;
f->lprev = NULL; f->lprev = NULL;
f->hnext = NULL; f->hnext = NULL;
@ -42,9 +42,9 @@ Flow *FlowAlloc(void)
/** free the memory of a flow */ /** free the memory of a flow */
void FlowFree(Flow *f) void FlowFree(Flow *f)
{ {
sc_mutex_lock(&flow_memuse_mutex); SCMutexLock(&flow_memuse_mutex);
flow_memuse -= sizeof(Flow); flow_memuse -= sizeof(Flow);
sc_mutex_unlock(&flow_memuse_mutex); SCMutexUnlock(&flow_memuse_mutex);
free(f); free(f);
} }

@ -39,7 +39,7 @@ FlowVar *FlowVarGet(Flow *f, uint8_t idx) {
void FlowVarAdd(Flow *f, uint8_t idx, uint8_t *value, uint16_t size) { void FlowVarAdd(Flow *f, uint8_t idx, uint8_t *value, uint16_t size) {
//printf("Adding flow var \"%s\" with value(%" PRId32 ") \"%s\"\n", name, size, value); //printf("Adding flow var \"%s\" with value(%" PRId32 ") \"%s\"\n", name, size, value);
sc_mutex_lock(&f->m); SCMutexLock(&f->m);
FlowVar *fv = FlowVarGet(f, idx); FlowVar *fv = FlowVarGet(f, idx);
if (fv == NULL) { if (fv == NULL) {
@ -59,7 +59,7 @@ void FlowVarAdd(Flow *f, uint8_t idx, uint8_t *value, uint16_t size) {
} }
out: out:
sc_mutex_unlock(&f->m); SCMutexUnlock(&f->m);
} }
void FlowVarFree(FlowVar *fv) { void FlowVarFree(FlowVar *fv) {

@ -104,7 +104,7 @@ void FlowUpdateQueue(Flow *f)
*/ */
static int FlowPrune (FlowQueue *q, struct timeval *ts) static int FlowPrune (FlowQueue *q, struct timeval *ts)
{ {
int mr = sc_mutex_trylock(&q->mutex_q); int mr = SCMutexTrylock(&q->mutex_q);
if (mr != 0) { if (mr != 0) {
SCLogDebug("Trylock failed!\n"); SCLogDebug("Trylock failed!\n");
if (mr == EBUSY) if (mr == EBUSY)
@ -116,21 +116,21 @@ static int FlowPrune (FlowQueue *q, struct timeval *ts)
Flow *f = q->top; Flow *f = q->top;
if (f == NULL) { if (f == NULL) {
sc_mutex_unlock(&q->mutex_q); SCMutexUnlock(&q->mutex_q);
SCLogDebug("top was null!\n"); SCLogDebug("top was null!\n");
return 0; return 0;
} }
if (sc_mutex_trylock(&f->m) != 0) { if (SCMutexTrylock(&f->m) != 0) {
SCLogDebug("cant lock 1!\n"); SCLogDebug("cant lock 1!\n");
sc_mutex_unlock(&q->mutex_q); SCMutexUnlock(&q->mutex_q);
return 0; return 0;
} }
/* unlock list */ /* unlock list */
sc_mutex_unlock(&q->mutex_q); SCMutexUnlock(&q->mutex_q);
if (sc_mutex_trylock(&f->fb->m) != 0) { if (SCMutexTrylock(&f->fb->m) != 0) {
sc_mutex_unlock(&f->m); SCMutexUnlock(&f->m);
SCLogDebug("cant lock 2!\n"); SCLogDebug("cant lock 2!\n");
return 0; return 0;
} }
@ -184,8 +184,8 @@ static int FlowPrune (FlowQueue *q, struct timeval *ts)
/* do the timeout check */ /* do the timeout check */
if ((f->lastts.tv_sec + timeout) >= ts->tv_sec) { if ((f->lastts.tv_sec + timeout) >= ts->tv_sec) {
sc_mutex_unlock(&f->fb->m); SCMutexUnlock(&f->fb->m);
sc_mutex_unlock(&f->m); SCMutexUnlock(&f->m);
SCLogDebug("timeout check failed!\n"); SCLogDebug("timeout check failed!\n");
return 0; return 0;
} }
@ -194,8 +194,8 @@ static int FlowPrune (FlowQueue *q, struct timeval *ts)
* we are currently processing in one of the threads */ * we are currently processing in one of the threads */
if (f->use_cnt > 0) { if (f->use_cnt > 0) {
SCLogDebug("timed out but use_cnt > 0: %"PRIu16", %p, proto %"PRIu8"", f->use_cnt, f, f->proto); SCLogDebug("timed out but use_cnt > 0: %"PRIu16", %p, proto %"PRIu8"", f->use_cnt, f, f->proto);
sc_mutex_unlock(&f->fb->m); SCMutexUnlock(&f->fb->m);
sc_mutex_unlock(&f->m); SCMutexUnlock(&f->m);
SCLogDebug("it is in one of the threads!\n"); SCLogDebug("it is in one of the threads!\n");
return 0; return 0;
} }
@ -211,7 +211,7 @@ static int FlowPrune (FlowQueue *q, struct timeval *ts)
f->hnext = NULL; f->hnext = NULL;
f->hprev = NULL; f->hprev = NULL;
sc_mutex_unlock(&f->fb->m); SCMutexUnlock(&f->fb->m);
f->fb = NULL; f->fb = NULL;
FlowClearMemory (f, f->protomap); FlowClearMemory (f, f->protomap);
@ -219,7 +219,7 @@ static int FlowPrune (FlowQueue *q, struct timeval *ts)
/* move to spare list */ /* move to spare list */
FlowRequeue(f, q, &flow_spare_q); FlowRequeue(f, q, &flow_spare_q);
sc_mutex_unlock(&f->m); SCMutexUnlock(&f->m);
return 1; return 1;
} }
@ -247,11 +247,11 @@ static uint32_t FlowPruneFlows(FlowQueue *q, struct timeval *ts)
static int FlowUpdateSpareFlows(void) { static int FlowUpdateSpareFlows(void) {
uint32_t toalloc = 0, tofree = 0, len; uint32_t toalloc = 0, tofree = 0, len;
sc_mutex_lock(&flow_spare_q.mutex_q); SCMutexLock(&flow_spare_q.mutex_q);
len = flow_spare_q.len; len = flow_spare_q.len;
sc_mutex_unlock(&flow_spare_q.mutex_q); SCMutexUnlock(&flow_spare_q.mutex_q);
if (len < flow_config.prealloc) { if (len < flow_config.prealloc) {
toalloc = flow_config.prealloc - len; toalloc = flow_config.prealloc - len;
@ -262,9 +262,9 @@ static int FlowUpdateSpareFlows(void) {
if (f == NULL) if (f == NULL)
return 0; return 0;
sc_mutex_lock(&flow_spare_q.mutex_q); SCMutexLock(&flow_spare_q.mutex_q);
FlowEnqueue(&flow_spare_q,f); FlowEnqueue(&flow_spare_q,f);
sc_mutex_unlock(&flow_spare_q.mutex_q); SCMutexUnlock(&flow_spare_q.mutex_q);
} }
} else if (len > flow_config.prealloc) { } else if (len > flow_config.prealloc) {
tofree = len - flow_config.prealloc; tofree = len - flow_config.prealloc;
@ -288,9 +288,9 @@ static int FlowUpdateSpareFlows(void) {
* \param direction direction to set the flag in * \param direction direction to set the flag in
*/ */
void FlowSetIPOnlyFlag(Flow *f, char direction) { void FlowSetIPOnlyFlag(Flow *f, char direction) {
sc_mutex_lock(&f->m); SCMutexLock(&f->m);
direction ? (f->flags |= FLOW_TOSERVER_IPONLY_SET) : (f->flags |= FLOW_TOCLIENT_IPONLY_SET); direction ? (f->flags |= FLOW_TOSERVER_IPONLY_SET) : (f->flags |= FLOW_TOCLIENT_IPONLY_SET);
sc_mutex_unlock(&f->m); SCMutexUnlock(&f->m);
} }
/** \brief decrease the use cnt of a flow /** \brief decrease the use cnt of a flow
@ -301,10 +301,10 @@ void FlowDecrUsecnt(ThreadVars *tv, Packet *p) {
if (p == NULL || p->flow == NULL) if (p == NULL || p->flow == NULL)
return; return;
sc_mutex_lock(&p->flow->m); SCMutexLock(&p->flow->m);
if (p->flow->use_cnt > 0) if (p->flow->use_cnt > 0)
p->flow->use_cnt--; p->flow->use_cnt--;
sc_mutex_unlock(&p->flow->m); SCMutexUnlock(&p->flow->m);
} }
/** \brief Entry point for packet flow handling /** \brief Entry point for packet flow handling
@ -362,7 +362,7 @@ void FlowHandlePacket (ThreadVars *tv, Packet *p)
/* set the flow in the packet */ /* set the flow in the packet */
p->flow = f; p->flow = f;
sc_mutex_unlock(&f->m); SCMutexUnlock(&f->m);
} }
/** \brief initialize the configuration /** \brief initialize the configuration
@ -382,7 +382,7 @@ void FlowInitConfig (char quiet)
FlowQueueInit(&flow_est_q[ifq]); FlowQueueInit(&flow_est_q[ifq]);
FlowQueueInit(&flow_close_q[ifq]); FlowQueueInit(&flow_close_q[ifq]);
} }
sc_mutex_init(&flow_memuse_mutex, NULL); SCMutexInit(&flow_memuse_mutex, NULL);
/* set defaults */ /* set defaults */
flow_config.hash_rand = rand(); /* XXX seed rand */ flow_config.hash_rand = rand(); /* XXX seed rand */
@ -405,7 +405,7 @@ void FlowInitConfig (char quiet)
memset(flow_hash, 0, flow_config.hash_size * sizeof(FlowBucket)); memset(flow_hash, 0, flow_config.hash_size * sizeof(FlowBucket));
for (i = 0; i < flow_config.hash_size; i++) for (i = 0; i < flow_config.hash_size; i++)
sc_mutex_init(&flow_hash[i].m, NULL); SCMutexInit(&flow_hash[i].m, NULL);
flow_config.memuse += (flow_config.hash_size * sizeof(FlowBucket)); flow_config.memuse += (flow_config.hash_size * sizeof(FlowBucket));
if (quiet == FALSE) if (quiet == FALSE)
@ -511,7 +511,7 @@ void FlowShutdown(void) {
free(flow_hash); free(flow_hash);
flow_memuse -= flow_config.hash_size * sizeof(FlowBucket); flow_memuse -= flow_config.hash_size * sizeof(FlowBucket);
sc_mutex_destroy(&flow_memuse_mutex); SCMutexDestroy(&flow_memuse_mutex);
} }
/** \brief Thread that manages the various queue's and removes timed out flows. /** \brief Thread that manages the various queue's and removes timed out flows.
@ -771,9 +771,9 @@ int FlowSetProtoEmergencyTimeout(uint8_t proto, uint32_t emerg_new_timeout, uint
* \param f Flow to set the flag in * \param f Flow to set the flag in
*/ */
void FlowLockSetNoPacketInspectionFlag(Flow *f) { void FlowLockSetNoPacketInspectionFlag(Flow *f) {
sc_mutex_lock(&f->m); SCMutexLock(&f->m);
f->flags |= FLOW_NOPACKET_INSPECTION; f->flags |= FLOW_NOPACKET_INSPECTION;
sc_mutex_unlock(&f->m); SCMutexUnlock(&f->m);
} }
/** \brief Set the No Packet Inspection Flag without locking the flow. /** \brief Set the No Packet Inspection Flag without locking the flow.
@ -789,9 +789,9 @@ void FlowSetNoPacketInspectionFlag(Flow *f) {
* \param f Flow to set the flag in * \param f Flow to set the flag in
*/ */
void FlowLockSetNoPayloadInspectionFlag(Flow *f) { void FlowLockSetNoPayloadInspectionFlag(Flow *f) {
sc_mutex_lock(&f->m); SCMutexLock(&f->m);
f->flags |= FLOW_NOPAYLOAD_INSPECTION; f->flags |= FLOW_NOPAYLOAD_INSPECTION;
sc_mutex_unlock(&f->m); SCMutexUnlock(&f->m);
} }
/** \brief Set the No payload inspection Flag without locking the flow. /** \brief Set the No payload inspection Flag without locking the flow.
@ -899,7 +899,7 @@ static int FlowTestPrune(Flow *f, struct timeval *ts) {
FlowQueue *q = FlowQueueNew(); FlowQueue *q = FlowQueueNew();
int r = sc_mutex_init(&q->mutex_q, NULL); int r = SCMutexInit(&q->mutex_q, NULL);
if (r != 0) { if (r != 0) {
SCLogDebug("Error initializing mutex!"); SCLogDebug("Error initializing mutex!");
@ -945,12 +945,12 @@ static int FlowTest03 (void) {
memset(&f, 0, sizeof(Flow)); memset(&f, 0, sizeof(Flow));
memset(&ts, 0, sizeof(ts)); memset(&ts, 0, sizeof(ts));
memset(&fb, 0, sizeof(FlowBucket)); memset(&fb, 0, sizeof(FlowBucket));
sc_mutex_init(&f.m, NULL); SCMutexInit(&f.m, NULL);
TimeGet(&ts); TimeGet(&ts);
f.lastts.tv_sec = ts.tv_sec - 5000; f.lastts.tv_sec = ts.tv_sec - 5000;
f.protoctx = &ssn; f.protoctx = &ssn;
sc_mutex_init(&fb.m, NULL); SCMutexInit(&fb.m, NULL);
f.fb = &fb; f.fb = &fb;
f.proto = IPPROTO_TCP; f.proto = IPPROTO_TCP;
@ -985,8 +985,8 @@ static int FlowTest04 (void) {
memset(&seg, 0, sizeof(TcpSegment)); memset(&seg, 0, sizeof(TcpSegment));
memset(&client, 0, sizeof(TcpSegment)); memset(&client, 0, sizeof(TcpSegment));
sc_mutex_init(&f.m, NULL); SCMutexInit(&f.m, NULL);
sc_mutex_init(&fb.m, NULL); SCMutexInit(&fb.m, NULL);
TimeGet(&ts); TimeGet(&ts);
seg.payload = payload; seg.payload = payload;
@ -1028,8 +1028,8 @@ static int FlowTest05 (void) {
memset(&ts, 0, sizeof(ts)); memset(&ts, 0, sizeof(ts));
memset(&fb, 0, sizeof(FlowBucket)); memset(&fb, 0, sizeof(FlowBucket));
sc_mutex_init(&f.m, NULL); SCMutexInit(&f.m, NULL);
sc_mutex_init(&fb.m, NULL); SCMutexInit(&fb.m, NULL);
TimeGet(&ts); TimeGet(&ts);
ssn.state = TCP_SYN_SENT; ssn.state = TCP_SYN_SENT;
@ -1069,8 +1069,8 @@ static int FlowTest06 (void) {
memset(&seg, 0, sizeof(TcpSegment)); memset(&seg, 0, sizeof(TcpSegment));
memset(&client, 0, sizeof(TcpSegment)); memset(&client, 0, sizeof(TcpSegment));
sc_mutex_init(&fb.m, NULL); SCMutexInit(&fb.m, NULL);
sc_mutex_init(&f.m, NULL); SCMutexInit(&f.m, NULL);
TimeGet(&ts); TimeGet(&ts);
seg.payload = payload; seg.payload = payload;

@ -77,7 +77,7 @@ typedef struct Flow_
/** how many pkts and stream msgs are using the flow *right now* */ /** how many pkts and stream msgs are using the flow *right now* */
uint16_t use_cnt; uint16_t use_cnt;
sc_mutex_t m; SCMutex m;
/* list flow ptrs /* list flow ptrs
* NOTE!!! These are NOT protected by the * NOTE!!! These are NOT protected by the

@ -6,7 +6,7 @@
#include "util-bloomfilter-counting.h" #include "util-bloomfilter-counting.h"
typedef struct HostTable_ { typedef struct HostTable_ {
sc_mutex_t m; SCMutex m;
/* storage & lookup */ /* storage & lookup */
HashTable *hash; HashTable *hash;
@ -16,7 +16,7 @@ typedef struct HostTable_ {
} HostTable; } HostTable;
typedef struct Host_ { typedef struct Host_ {
sc_mutex_t m; SCMutex m;
Address addr; Address addr;
uint8_t os; uint8_t os;

@ -93,7 +93,7 @@ TmEcode LogHttplogIPv4(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq)
inet_ntop(AF_INET, (const void *)GET_IPV4_SRC_ADDR_PTR(p), srcip, sizeof(srcip)); inet_ntop(AF_INET, (const void *)GET_IPV4_SRC_ADDR_PTR(p), srcip, sizeof(srcip));
inet_ntop(AF_INET, (const void *)GET_IPV4_DST_ADDR_PTR(p), dstip, sizeof(dstip)); inet_ntop(AF_INET, (const void *)GET_IPV4_DST_ADDR_PTR(p), dstip, sizeof(dstip));
sc_mutex_lock(&aft->file_ctx->fp_mutex); SCMutexLock(&aft->file_ctx->fp_mutex);
for (i = 0; i < p->http_uri.cnt; i++) { for (i = 0; i < p->http_uri.cnt; i++) {
/* time */ /* time */
fprintf(aft->file_ctx->fp, "%s ", timebuf); fprintf(aft->file_ctx->fp, "%s ", timebuf);
@ -111,7 +111,7 @@ TmEcode LogHttplogIPv4(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq)
fprintf(aft->file_ctx->fp, " [**] %s:%" PRIu32 " -> %s:%" PRIu32 "\n", srcip, p->sp, dstip, p->dp); fprintf(aft->file_ctx->fp, " [**] %s:%" PRIu32 " -> %s:%" PRIu32 "\n", srcip, p->sp, dstip, p->dp);
} }
fflush(aft->file_ctx->fp); fflush(aft->file_ctx->fp);
sc_mutex_unlock(&aft->file_ctx->fp_mutex); SCMutexUnlock(&aft->file_ctx->fp_mutex);
aft->uri_cnt += p->http_uri.cnt; aft->uri_cnt += p->http_uri.cnt;
return TM_ECODE_OK; return TM_ECODE_OK;
@ -136,7 +136,7 @@ TmEcode LogHttplogIPv6(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq)
inet_ntop(AF_INET6, (const void *)GET_IPV6_SRC_ADDR(p), srcip, sizeof(srcip)); inet_ntop(AF_INET6, (const void *)GET_IPV6_SRC_ADDR(p), srcip, sizeof(srcip));
inet_ntop(AF_INET6, (const void *)GET_IPV6_DST_ADDR(p), dstip, sizeof(dstip)); inet_ntop(AF_INET6, (const void *)GET_IPV6_DST_ADDR(p), dstip, sizeof(dstip));
sc_mutex_lock(&aft->file_ctx->fp_mutex); SCMutexLock(&aft->file_ctx->fp_mutex);
for (i = 0; i < p->http_uri.cnt; i++) { for (i = 0; i < p->http_uri.cnt; i++) {
/* time */ /* time */
fprintf(aft->file_ctx->fp, "%s ", timebuf); fprintf(aft->file_ctx->fp, "%s ", timebuf);
@ -154,7 +154,7 @@ TmEcode LogHttplogIPv6(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq)
fprintf(aft->file_ctx->fp, " [**] %s:%" PRIu32 " -> %s:%" PRIu32 "\n", srcip, p->sp, dstip, p->dp); fprintf(aft->file_ctx->fp, " [**] %s:%" PRIu32 " -> %s:%" PRIu32 "\n", srcip, p->sp, dstip, p->dp);
} }
fflush(aft->file_ctx->fp); fflush(aft->file_ctx->fp);
sc_mutex_unlock(&aft->file_ctx->fp_mutex); SCMutexUnlock(&aft->file_ctx->fp_mutex);
aft->uri_cnt += p->http_uri.cnt; aft->uri_cnt += p->http_uri.cnt;
return TM_ECODE_OK; return TM_ECODE_OK;

@ -36,7 +36,7 @@ Packet *PacketDequeue (PacketQueue *q) {
/* If we are going to get the last packet, set len to 0 /* If we are going to get the last packet, set len to 0
* before doing anything else (to make the threads to follow * before doing anything else (to make the threads to follow
* the sc_cond_wait as soon as possible) */ * the SCondWait as soon as possible) */
q->len--; q->len--;
/* pull the bottom packet from the queue */ /* pull the bottom packet from the queue */

@ -12,8 +12,8 @@ typedef struct PacketQueue_ {
Packet *top; Packet *top;
Packet *bot; Packet *bot;
uint16_t len; uint16_t len;
sc_mutex_t mutex_q; SCMutex mutex_q;
sc_cond_t cond_q; SCCondT cond_q;
#ifdef DBG_PERF #ifdef DBG_PERF
uint16_t dbg_maxlen; uint16_t dbg_maxlen;
#endif /* DBG_PERF */ #endif /* DBG_PERF */

@ -68,7 +68,7 @@ static NFQGlobalVars nfq_g;
static NFQThreadVars nfq_t[NFQ_MAX_QUEUE]; static NFQThreadVars nfq_t[NFQ_MAX_QUEUE];
static uint16_t receive_queue_num = 0; static uint16_t receive_queue_num = 0;
static uint16_t verdict_queue_num = 0; static uint16_t verdict_queue_num = 0;
static sc_mutex_t nfq_init_lock; static SCMutex nfq_init_lock;
TmEcode ReceiveNFQ(ThreadVars *, Packet *, void *, PacketQueue *); TmEcode ReceiveNFQ(ThreadVars *, Packet *, void *, PacketQueue *);
TmEcode ReceiveNFQThreadInit(ThreadVars *, void *, void **); TmEcode ReceiveNFQThreadInit(ThreadVars *, void *, void **);
@ -86,7 +86,7 @@ void TmModuleReceiveNFQRegister (void) {
/* XXX create a general NFQ setup function */ /* XXX create a general NFQ setup function */
memset(&nfq_g, 0, sizeof(nfq_g)); memset(&nfq_g, 0, sizeof(nfq_g));
memset(&nfq_t, 0, sizeof(nfq_t)); memset(&nfq_t, 0, sizeof(nfq_t));
sc_mutex_init(&nfq_init_lock, NULL); SCMutexInit(&nfq_init_lock, NULL);
tmm_modules[TMM_RECEIVENFQ].name = "ReceiveNFQ"; tmm_modules[TMM_RECEIVENFQ].name = "ReceiveNFQ";
tmm_modules[TMM_RECEIVENFQ].ThreadInit = ReceiveNFQThreadInit; tmm_modules[TMM_RECEIVENFQ].ThreadInit = ReceiveNFQThreadInit;
@ -264,7 +264,7 @@ TmEcode NFQInitThread(NFQThreadVars *nfq_t, uint16_t queue_num, uint32_t queue_m
} }
TmEcode ReceiveNFQThreadInit(ThreadVars *tv, void *initdata, void **data) { TmEcode ReceiveNFQThreadInit(ThreadVars *tv, void *initdata, void **data) {
sc_mutex_lock(&nfq_init_lock); SCMutexLock(&nfq_init_lock);
printf("ReceiveNFQThreadInit: starting... will bind to queuenum %" PRIu32 "\n", receive_queue_num); printf("ReceiveNFQThreadInit: starting... will bind to queuenum %" PRIu32 "\n", receive_queue_num);
sigset_t sigs; sigset_t sigs;
@ -281,18 +281,18 @@ TmEcode ReceiveNFQThreadInit(ThreadVars *tv, void *initdata, void **data) {
if (r < 0) { if (r < 0) {
printf("NFQInitThread failed\n"); printf("NFQInitThread failed\n");
//return -1; //return -1;
sc_mutex_unlock(&nfq_init_lock); SCMutexUnlock(&nfq_init_lock);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
*data = (void *)ntv; *data = (void *)ntv;
receive_queue_num++; receive_queue_num++;
sc_mutex_unlock(&nfq_init_lock); SCMutexUnlock(&nfq_init_lock);
return TM_ECODE_OK; return TM_ECODE_OK;
} }
TmEcode VerdictNFQThreadInit(ThreadVars *tv, void *initdata, void **data) { TmEcode VerdictNFQThreadInit(ThreadVars *tv, void *initdata, void **data) {
sc_mutex_lock(&nfq_init_lock); SCMutexLock(&nfq_init_lock);
printf("VerdictNFQThreadInit: starting... will bind to queuenum %" PRIu32 "\n", verdict_queue_num); printf("VerdictNFQThreadInit: starting... will bind to queuenum %" PRIu32 "\n", verdict_queue_num);
/* no initialization, ReceiveNFQ takes care of that */ /* no initialization, ReceiveNFQ takes care of that */
@ -301,7 +301,7 @@ TmEcode VerdictNFQThreadInit(ThreadVars *tv, void *initdata, void **data) {
*data = (void *)ntv; *data = (void *)ntv;
verdict_queue_num++; verdict_queue_num++;
sc_mutex_unlock(&nfq_init_lock); SCMutexUnlock(&nfq_init_lock);
return TM_ECODE_OK; return TM_ECODE_OK;
} }
@ -338,9 +338,9 @@ void NFQRecvPkt(NFQThreadVars *t) {
//printf("NFQRecvPkt: t %p, rv = %" PRId32 "\n", t, rv); //printf("NFQRecvPkt: t %p, rv = %" PRId32 "\n", t, rv);
sc_mutex_lock(&t->mutex_qh); SCMutexLock(&t->mutex_qh);
ret = nfq_handle_packet(t->h, buf, rv); ret = nfq_handle_packet(t->h, buf, rv);
sc_mutex_unlock(&t->mutex_qh); SCMutexUnlock(&t->mutex_qh);
if (ret != 0) if (ret != 0)
printf("NFQRecvPkt: nfq_handle_packet error %" PRId32 "\n", ret); printf("NFQRecvPkt: nfq_handle_packet error %" PRId32 "\n", ret);
@ -357,11 +357,11 @@ TmEcode ReceiveNFQ(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq) {
/* check if we have too many packets in the system /* check if we have too many packets in the system
* so we will wait for some to free up */ * so we will wait for some to free up */
sc_mutex_lock(&mutex_pending); SCMutexLock(&mutex_pending);
if (pending > MAX_PENDING) { if (pending > MAX_PENDING) {
sc_cond_wait(&cond_pending, &mutex_pending); SCondWait(&cond_pending, &mutex_pending);
} }
sc_mutex_unlock(&mutex_pending); SCMutexUnlock(&mutex_pending);
return TM_ECODE_OK; return TM_ECODE_OK;
} }
@ -405,9 +405,9 @@ void NFQSetVerdict(NFQThreadVars *t, Packet *p) {
if (verdict == NF_DROP) t->dropped++; if (verdict == NF_DROP) t->dropped++;
#endif /* COUNTERS */ #endif /* COUNTERS */
sc_mutex_lock(&t->mutex_qh); SCMutexLock(&t->mutex_qh);
ret = nfq_set_verdict(t->qh, p->nfq_v.id, verdict, 0, NULL); ret = nfq_set_verdict(t->qh, p->nfq_v.id, verdict, 0, NULL);
sc_mutex_unlock(&t->mutex_qh); SCMutexUnlock(&t->mutex_qh);
if (ret < 0) if (ret < 0)
printf("NFQSetVerdict: nfq_set_verdict of %p failed %" PRId32 "\n", p, ret); printf("NFQSetVerdict: nfq_set_verdict of %p failed %" PRId32 "\n", p, ret);
@ -422,15 +422,15 @@ TmEcode VerdictNFQ(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq) {
char verdict = 1; char verdict = 1;
//printf("VerdictNFQ: tunnel pkt: %p %s\n", p, p->root ? "upper layer" : "root"); //printf("VerdictNFQ: tunnel pkt: %p %s\n", p, p->root ? "upper layer" : "root");
sc_mutex_t *m = p->root ? &p->root->mutex_rtv_cnt : &p->mutex_rtv_cnt; SCMutex *m = p->root ? &p->root->mutex_rtv_cnt : &p->mutex_rtv_cnt;
sc_mutex_lock(m); SCMutexLock(m);
/* if there are more tunnel packets than ready to verdict packets, /* if there are more tunnel packets than ready to verdict packets,
* we won't verdict this one */ * we won't verdict this one */
if (TUNNEL_PKT_TPR(p) > TUNNEL_PKT_RTV(p)) { if (TUNNEL_PKT_TPR(p) > TUNNEL_PKT_RTV(p)) {
//printf("VerdictNFQ: not ready to verdict yet: TUNNEL_PKT_TPR(p) > TUNNEL_PKT_RTV(p) = %" PRId32 " > %" PRId32 "\n", TUNNEL_PKT_TPR(p), TUNNEL_PKT_RTV(p)); //printf("VerdictNFQ: not ready to verdict yet: TUNNEL_PKT_TPR(p) > TUNNEL_PKT_RTV(p) = %" PRId32 " > %" PRId32 "\n", TUNNEL_PKT_TPR(p), TUNNEL_PKT_RTV(p));
verdict = 0; verdict = 0;
} }
sc_mutex_unlock(m); SCMutexUnlock(m);
/* don't verdict if we are not ready */ /* don't verdict if we are not ready */
if (verdict == 1) { if (verdict == 1) {

@ -30,7 +30,7 @@ typedef struct NFQThreadVars_
struct nfnl_handle *nh; struct nfnl_handle *nh;
/* 2 threads deal with the queue handle, so add a mutex */ /* 2 threads deal with the queue handle, so add a mutex */
struct nfq_q_handle *qh; struct nfq_q_handle *qh;
sc_mutex_t mutex_qh; SCMutex mutex_qh;
/* this one should be not changing after init */ /* this one should be not changing after init */
uint16_t queue_num; uint16_t queue_num;
int fd; int fd;

@ -74,11 +74,11 @@ void PcapFileCallback(char *user, struct pcap_pkthdr *h, u_char *pkt) {
PcapFileThreadVars *ptv = (PcapFileThreadVars *)user; PcapFileThreadVars *ptv = (PcapFileThreadVars *)user;
//ThreadVars *tv = ptv->tv; //ThreadVars *tv = ptv->tv;
sc_mutex_lock(&mutex_pending); SCMutexLock(&mutex_pending);
if (pending > MAX_PENDING) { if (pending > MAX_PENDING) {
sc_cond_wait(&cond_pending, &mutex_pending); SCondWait(&cond_pending, &mutex_pending);
} }
sc_mutex_unlock(&mutex_pending); SCMutexUnlock(&mutex_pending);
Packet *p = ptv->in_p; Packet *p = ptv->in_p;

@ -86,11 +86,11 @@ void PcapCallback(char *user, struct pcap_pkthdr *h, u_char *pkt) {
PcapThreadVars *ptv = (PcapThreadVars *)user; PcapThreadVars *ptv = (PcapThreadVars *)user;
ThreadVars *tv = ptv->tv; ThreadVars *tv = ptv->tv;
sc_mutex_lock(&mutex_pending); SCMutexLock(&mutex_pending);
if (pending > MAX_PENDING) { if (pending > MAX_PENDING) {
sc_cond_wait(&cond_pending, &mutex_pending); SCondWait(&cond_pending, &mutex_pending);
} }
sc_mutex_unlock(&mutex_pending); SCMutexUnlock(&mutex_pending);
Packet *p = tv->tmqh_in(tv); Packet *p = tv->tmqh_in(tv);
p->ts.tv_sec = h->ts.tv_sec; p->ts.tv_sec = h->ts.tv_sec;

@ -37,7 +37,7 @@
//#define DEBUG //#define DEBUG
#ifdef DEBUG #ifdef DEBUG
static sc_mutex_t segment_pool_memuse_mutex; static SCMutex segment_pool_memuse_mutex;
static uint64_t segment_pool_memuse = 0; static uint64_t segment_pool_memuse = 0;
static uint64_t segment_pool_memcnt = 0; static uint64_t segment_pool_memcnt = 0;
#endif #endif
@ -70,10 +70,10 @@ void *TcpSegmentPoolAlloc(void *payload_len) {
} }
#ifdef DEBUG #ifdef DEBUG
sc_mutex_lock(&segment_pool_memuse_mutex); SCMutexLock(&segment_pool_memuse_mutex);
segment_pool_memuse += seg->payload_len; segment_pool_memuse += seg->payload_len;
segment_pool_memcnt ++; segment_pool_memcnt ++;
sc_mutex_unlock(&segment_pool_memuse_mutex); SCMutexUnlock(&segment_pool_memuse_mutex);
#endif #endif
return seg; return seg;
} }
@ -97,9 +97,9 @@ void TcpSegmentPoolFree(void *ptr) {
static uint16_t segment_pool_pktsizes[segment_pool_num] = {4, 16, 112, 248, 512, 768, 1448, 0xffff}; static uint16_t segment_pool_pktsizes[segment_pool_num] = {4, 16, 112, 248, 512, 768, 1448, 0xffff};
static uint16_t segment_pool_poolsizes[segment_pool_num] = {2048, 3072, 3072, 3072, 3072, 4096, 8192, 512}; static uint16_t segment_pool_poolsizes[segment_pool_num] = {2048, 3072, 3072, 3072, 3072, 4096, 8192, 512};
static Pool *segment_pool[segment_pool_num]; static Pool *segment_pool[segment_pool_num];
static sc_mutex_t segment_pool_mutex[segment_pool_num]; static SCMutex segment_pool_mutex[segment_pool_num];
#ifdef DEBUG #ifdef DEBUG
static sc_mutex_t segment_pool_cnt_mutex; static SCMutex segment_pool_cnt_mutex;
static uint64_t segment_pool_cnt = 0; static uint64_t segment_pool_cnt = 0;
#endif #endif
/* index to the right pool for all packet sizes. */ /* index to the right pool for all packet sizes. */
@ -108,12 +108,12 @@ static uint16_t segment_pool_idx[65536]; /* O(1) lookups of the pool */
int StreamTcpReassembleInit(char quiet) { int StreamTcpReassembleInit(char quiet) {
StreamMsgQueuesInit(); StreamMsgQueuesInit();
#ifdef DEBUG #ifdef DEBUG
sc_mutex_init(&segment_pool_memuse_mutex, NULL); SCMutexInit(&segment_pool_memuse_mutex, NULL);
#endif #endif
uint16_t u16 = 0; uint16_t u16 = 0;
for (u16 = 0; u16 < segment_pool_num; u16++) { for (u16 = 0; u16 < segment_pool_num; u16++) {
segment_pool[u16] = PoolInit(segment_pool_poolsizes[u16], segment_pool_poolsizes[u16] / 8, TcpSegmentPoolAlloc, (void *) & segment_pool_pktsizes[u16], TcpSegmentPoolFree); segment_pool[u16] = PoolInit(segment_pool_poolsizes[u16], segment_pool_poolsizes[u16] / 8, TcpSegmentPoolAlloc, (void *) & segment_pool_pktsizes[u16], TcpSegmentPoolFree);
sc_mutex_init(&segment_pool_mutex[u16], NULL); SCMutexInit(&segment_pool_mutex[u16], NULL);
} }
uint16_t idx = 0; uint16_t idx = 0;
@ -131,7 +131,7 @@ int StreamTcpReassembleInit(char quiet) {
idx++; idx++;
} }
#ifdef DEBUG #ifdef DEBUG
sc_mutex_init(&segment_pool_cnt_mutex, NULL); SCMutexInit(&segment_pool_cnt_mutex, NULL);
#endif #endif
return 0; return 0;
} }
@ -145,7 +145,7 @@ void StreamTcpReassembleFree(char quiet) {
} }
PoolFree(segment_pool[u16]); PoolFree(segment_pool[u16]);
sc_mutex_destroy(&segment_pool_mutex[u16]); SCMutexDestroy(&segment_pool_mutex[u16]);
} }
#ifdef DEBUG #ifdef DEBUG
@ -1352,21 +1352,21 @@ void StreamTcpSegmentDataCopy(TcpSegment *dst_seg, TcpSegment *src_seg) {
TcpSegment* StreamTcpGetSegment(uint16_t len) { TcpSegment* StreamTcpGetSegment(uint16_t len) {
uint16_t idx = segment_pool_idx[len]; uint16_t idx = segment_pool_idx[len];
SCLogDebug("%" PRIu32 " for payload_len %" PRIu32 "", idx, len); SCLogDebug("%" PRIu32 " for payload_len %" PRIu32 "", idx, len);
sc_mutex_lock(&segment_pool_mutex[idx]); SCMutexLock(&segment_pool_mutex[idx]);
TcpSegment *seg = (TcpSegment *) PoolGet(segment_pool[idx]); TcpSegment *seg = (TcpSegment *) PoolGet(segment_pool[idx]);
SCLogDebug("segment_pool[%u]->empty_list_size %u, segment_pool[%u]->alloc_list_size %u, alloc %u", SCLogDebug("segment_pool[%u]->empty_list_size %u, segment_pool[%u]->alloc_list_size %u, alloc %u",
idx, segment_pool[idx]->empty_list_size, idx, segment_pool[idx]->alloc_list_size, segment_pool[idx]->allocated); idx, segment_pool[idx]->empty_list_size, idx, segment_pool[idx]->alloc_list_size, segment_pool[idx]->allocated);
//PoolPrintSaturation(segment_pool[idx]); //PoolPrintSaturation(segment_pool[idx]);
sc_mutex_unlock(&segment_pool_mutex[idx]); SCMutexUnlock(&segment_pool_mutex[idx]);
SCLogDebug("StreamTcpGetSegment: seg we return is %p", seg); SCLogDebug("StreamTcpGetSegment: seg we return is %p", seg);
if (seg == NULL) { if (seg == NULL) {
SCLogDebug("segment_pool[%u]->empty_list_size %u, alloc %u", idx, segment_pool[idx]->empty_list_size, segment_pool[idx]->allocated); SCLogDebug("segment_pool[%u]->empty_list_size %u, alloc %u", idx, segment_pool[idx]->empty_list_size, segment_pool[idx]->allocated);
} else { } else {
#ifdef DEBUG #ifdef DEBUG
sc_mutex_lock(&segment_pool_cnt_mutex); SCMutexLock(&segment_pool_cnt_mutex);
segment_pool_cnt++; segment_pool_cnt++;
sc_mutex_unlock(&segment_pool_cnt_mutex); SCMutexUnlock(&segment_pool_cnt_mutex);
#endif #endif
} }
return seg; return seg;
@ -1383,15 +1383,15 @@ void StreamTcpSegmentReturntoPool(TcpSegment *seg) {
seg->prev = NULL; seg->prev = NULL;
uint16_t idx = segment_pool_idx[seg->pool_size]; uint16_t idx = segment_pool_idx[seg->pool_size];
sc_mutex_lock(&segment_pool_mutex[idx]); SCMutexLock(&segment_pool_mutex[idx]);
PoolReturn(segment_pool[idx], (void *) seg); PoolReturn(segment_pool[idx], (void *) seg);
SCLogDebug("segment_pool[%"PRIu16"]->empty_list_size %"PRIu32"", idx,segment_pool[idx]->empty_list_size); SCLogDebug("segment_pool[%"PRIu16"]->empty_list_size %"PRIu32"", idx,segment_pool[idx]->empty_list_size);
sc_mutex_unlock(&segment_pool_mutex[idx]); SCMutexUnlock(&segment_pool_mutex[idx]);
#ifdef DEBUG #ifdef DEBUG
sc_mutex_lock(&segment_pool_cnt_mutex); SCMutexLock(&segment_pool_cnt_mutex);
segment_pool_cnt--; segment_pool_cnt--;
sc_mutex_unlock(&segment_pool_cnt_mutex); SCMutexUnlock(&segment_pool_cnt_mutex);
#endif #endif
} }

@ -68,11 +68,11 @@ static int ValidTimestamp(TcpSession * , Packet *);
#define STREAMTCP_EMERG_CLOSED_TIMEOUT 20 #define STREAMTCP_EMERG_CLOSED_TIMEOUT 20
static Pool *ssn_pool = NULL; static Pool *ssn_pool = NULL;
static sc_mutex_t ssn_pool_mutex; static SCMutex ssn_pool_mutex;
#ifdef DEBUG #ifdef DEBUG
static uint64_t ssn_pool_cnt; static uint64_t ssn_pool_cnt;
static sc_mutex_t ssn_pool_cnt_mutex; static SCMutex ssn_pool_cnt_mutex;
#endif #endif
void TmModuleStreamTcpRegister (void) { void TmModuleStreamTcpRegister (void) {
@ -116,14 +116,14 @@ void StreamTcpSessionClear(void *ssnptr) {
AppLayerParserCleanupState(ssn); AppLayerParserCleanupState(ssn);
memset(ssn, 0, sizeof(TcpSession)); memset(ssn, 0, sizeof(TcpSession));
sc_mutex_lock(&ssn_pool_mutex); SCMutexLock(&ssn_pool_mutex);
PoolReturn(ssn_pool, ssn); PoolReturn(ssn_pool, ssn);
sc_mutex_unlock(&ssn_pool_mutex); SCMutexUnlock(&ssn_pool_mutex);
#ifdef DEBUG #ifdef DEBUG
sc_mutex_lock(&ssn_pool_cnt_mutex); SCMutexLock(&ssn_pool_cnt_mutex);
ssn_pool_cnt--; ssn_pool_cnt--;
sc_mutex_unlock(&ssn_pool_cnt_mutex); SCMutexUnlock(&ssn_pool_cnt_mutex);
#endif #endif
} }
@ -143,16 +143,16 @@ static void StreamTcpSessionPktFree (Packet *p) {
AppLayerParserCleanupState(ssn); AppLayerParserCleanupState(ssn);
memset(ssn, 0, sizeof(TcpSession)); memset(ssn, 0, sizeof(TcpSession));
sc_mutex_lock(&ssn_pool_mutex); SCMutexLock(&ssn_pool_mutex);
PoolReturn(ssn_pool, p->flow->protoctx); PoolReturn(ssn_pool, p->flow->protoctx);
sc_mutex_unlock(&ssn_pool_mutex); SCMutexUnlock(&ssn_pool_mutex);
p->flow->protoctx = NULL; p->flow->protoctx = NULL;
#ifdef DEBUG #ifdef DEBUG
sc_mutex_lock(&ssn_pool_cnt_mutex); SCMutexLock(&ssn_pool_cnt_mutex);
ssn_pool_cnt--; ssn_pool_cnt--;
sc_mutex_unlock(&ssn_pool_cnt_mutex); SCMutexUnlock(&ssn_pool_cnt_mutex);
#endif #endif
} }
@ -210,7 +210,7 @@ void StreamTcpInitConfig(char quiet) {
exit(1); exit(1);
} }
sc_mutex_init(&ssn_pool_mutex, NULL); SCMutexInit(&ssn_pool_mutex, NULL);
StreamTcpReassembleInit(quiet); StreamTcpReassembleInit(quiet);
@ -235,7 +235,7 @@ void StreamTcpFreeConfig(char quiet) {
#ifdef DEBUG #ifdef DEBUG
SCLogDebug("ssn_pool_cnt %"PRIu64"", ssn_pool_cnt); SCLogDebug("ssn_pool_cnt %"PRIu64"", ssn_pool_cnt);
#endif #endif
sc_mutex_destroy(&ssn_pool_mutex); SCMutexDestroy(&ssn_pool_mutex);
} }
/** \brief The function is used to to fetch a TCP session from the /** \brief The function is used to to fetch a TCP session from the
@ -249,9 +249,9 @@ TcpSession *StreamTcpNewSession (Packet *p) {
TcpSession *ssn = (TcpSession *)p->flow->protoctx; TcpSession *ssn = (TcpSession *)p->flow->protoctx;
if (ssn == NULL) { if (ssn == NULL) {
sc_mutex_lock(&ssn_pool_mutex); SCMutexLock(&ssn_pool_mutex);
p->flow->protoctx = PoolGet(ssn_pool); p->flow->protoctx = PoolGet(ssn_pool);
sc_mutex_unlock(&ssn_pool_mutex); SCMutexUnlock(&ssn_pool_mutex);
ssn = (TcpSession *)p->flow->protoctx; ssn = (TcpSession *)p->flow->protoctx;
if (ssn == NULL) if (ssn == NULL)
@ -261,9 +261,9 @@ TcpSession *StreamTcpNewSession (Packet *p) {
ssn->aldata = NULL; ssn->aldata = NULL;
#ifdef DEBUG #ifdef DEBUG
sc_mutex_lock(&ssn_pool_cnt_mutex); SCMutexLock(&ssn_pool_cnt_mutex);
ssn_pool_cnt++; ssn_pool_cnt++;
sc_mutex_unlock(&ssn_pool_cnt_mutex); SCMutexUnlock(&ssn_pool_cnt_mutex);
#endif #endif
} }
@ -1955,9 +1955,9 @@ TmEcode StreamTcp (ThreadVars *tv, Packet *p, void *data, PacketQueue *pq)
if (p->flow == NULL) if (p->flow == NULL)
return TM_ECODE_OK; return TM_ECODE_OK;
sc_mutex_lock(&p->flow->m); SCMutexLock(&p->flow->m);
ret = StreamTcpPacket(tv, p, stt); ret = StreamTcpPacket(tv, p, stt);
sc_mutex_unlock(&p->flow->m); SCMutexUnlock(&p->flow->m);
//if (ret) //if (ret)
// return TM_ECODE_FAILED; // return TM_ECODE_FAILED;

@ -7,7 +7,7 @@
#include "util-pool.h" #include "util-pool.h"
#include "util-debug.h" #include "util-debug.h"
static sc_mutex_t stream_pool_memuse_mutex; static SCMutex stream_pool_memuse_mutex;
static uint64_t stream_pool_memuse = 0; static uint64_t stream_pool_memuse = 0;
static uint64_t stream_pool_memcnt = 0; static uint64_t stream_pool_memcnt = 0;
@ -20,7 +20,7 @@ static uint16_t toclient_min_init_chunk_len = 0;
static uint16_t toclient_min_chunk_len = 0; static uint16_t toclient_min_chunk_len = 0;
static Pool *stream_msg_pool = NULL; static Pool *stream_msg_pool = NULL;
static sc_mutex_t stream_msg_pool_mutex = PTHREAD_MUTEX_INITIALIZER; static SCMutex stream_msg_pool_mutex = PTHREAD_MUTEX_INITIALIZER;
void *StreamMsgAlloc(void *null) { void *StreamMsgAlloc(void *null) {
StreamMsg *s = malloc(sizeof(StreamMsg)); StreamMsg *s = malloc(sizeof(StreamMsg));
@ -29,10 +29,10 @@ void *StreamMsgAlloc(void *null) {
memset(s, 0, sizeof(StreamMsg)); memset(s, 0, sizeof(StreamMsg));
sc_mutex_lock(&stream_pool_memuse_mutex); SCMutexLock(&stream_pool_memuse_mutex);
stream_pool_memuse += sizeof(StreamMsg); stream_pool_memuse += sizeof(StreamMsg);
stream_pool_memcnt ++; stream_pool_memcnt ++;
sc_mutex_unlock(&stream_pool_memuse_mutex); SCMutexUnlock(&stream_pool_memuse_mutex);
return s; return s;
} }
@ -92,38 +92,38 @@ static StreamMsg *StreamMsgDequeue (StreamMsgQueue *q) {
/* Used by stream reassembler to get msgs */ /* Used by stream reassembler to get msgs */
StreamMsg *StreamMsgGetFromPool(void) StreamMsg *StreamMsgGetFromPool(void)
{ {
sc_mutex_lock(&stream_msg_pool_mutex); SCMutexLock(&stream_msg_pool_mutex);
StreamMsg *s = (StreamMsg *)PoolGet(stream_msg_pool); StreamMsg *s = (StreamMsg *)PoolGet(stream_msg_pool);
sc_mutex_unlock(&stream_msg_pool_mutex); SCMutexUnlock(&stream_msg_pool_mutex);
return s; return s;
} }
/* Used by l7inspection to return msgs to pool */ /* Used by l7inspection to return msgs to pool */
void StreamMsgReturnToPool(StreamMsg *s) { void StreamMsgReturnToPool(StreamMsg *s) {
sc_mutex_lock(&stream_msg_pool_mutex); SCMutexLock(&stream_msg_pool_mutex);
PoolReturn(stream_msg_pool, (void *)s); PoolReturn(stream_msg_pool, (void *)s);
sc_mutex_unlock(&stream_msg_pool_mutex); SCMutexUnlock(&stream_msg_pool_mutex);
} }
/* Used by l7inspection to get msgs with data */ /* Used by l7inspection to get msgs with data */
StreamMsg *StreamMsgGetFromQueue(StreamMsgQueue *q) StreamMsg *StreamMsgGetFromQueue(StreamMsgQueue *q)
{ {
sc_mutex_lock(&q->mutex_q); SCMutexLock(&q->mutex_q);
if (q->len == 0) { if (q->len == 0) {
struct timespec cond_time; struct timespec cond_time;
cond_time.tv_sec = time(NULL) + 5; cond_time.tv_sec = time(NULL) + 5;
cond_time.tv_nsec = 0; cond_time.tv_nsec = 0;
/* if we have no stream msgs in queue, wait... for 5 seconds */ /* if we have no stream msgs in queue, wait... for 5 seconds */
sc_cond_timedwait(&q->cond_q, &q->mutex_q, &cond_time); SCCondTimedwait(&q->cond_q, &q->mutex_q, &cond_time);
} }
if (q->len > 0) { if (q->len > 0) {
StreamMsg *s = StreamMsgDequeue(q); StreamMsg *s = StreamMsgDequeue(q);
sc_mutex_unlock(&q->mutex_q); SCMutexUnlock(&q->mutex_q);
return s; return s;
} else { } else {
/* return NULL if we have no stream msg. Should only happen on signals. */ /* return NULL if we have no stream msg. Should only happen on signals. */
sc_mutex_unlock(&q->mutex_q); SCMutexUnlock(&q->mutex_q);
return NULL; return NULL;
} }
} }
@ -131,15 +131,15 @@ StreamMsg *StreamMsgGetFromQueue(StreamMsgQueue *q)
/* Used by stream reassembler to fill the queue for l7inspect reading */ /* Used by stream reassembler to fill the queue for l7inspect reading */
void StreamMsgPutInQueue(StreamMsgQueue *q, StreamMsg *s) void StreamMsgPutInQueue(StreamMsgQueue *q, StreamMsg *s)
{ {
sc_mutex_lock(&q->mutex_q); SCMutexLock(&q->mutex_q);
StreamMsgEnqueue(q, s); StreamMsgEnqueue(q, s);
SCLogDebug("q->len %" PRIu32 "", q->len); SCLogDebug("q->len %" PRIu32 "", q->len);
sc_cond_signal(&q->cond_q); SCCondSignal(&q->cond_q);
sc_mutex_unlock(&q->mutex_q); SCMutexUnlock(&q->mutex_q);
} }
void StreamMsgQueuesInit(void) { void StreamMsgQueuesInit(void) {
sc_mutex_init(&stream_pool_memuse_mutex, NULL); SCMutexInit(&stream_pool_memuse_mutex, NULL);
//memset(&stream_q, 0, sizeof(stream_q)); //memset(&stream_q, 0, sizeof(stream_q));
stream_msg_pool = PoolInit(5000,250,StreamMsgAlloc,NULL,StreamMsgFree); stream_msg_pool = PoolInit(5000,250,StreamMsgAlloc,NULL,StreamMsgFree);
@ -149,7 +149,7 @@ void StreamMsgQueuesInit(void) {
void StreamMsgQueuesDeinit(char quiet) { void StreamMsgQueuesDeinit(char quiet) {
PoolFree(stream_msg_pool); PoolFree(stream_msg_pool);
sc_mutex_destroy(&stream_pool_memuse_mutex); SCMutexDestroy(&stream_pool_memuse_mutex);
if (quiet == FALSE) if (quiet == FALSE)
SCLogDebug("stream_pool_memuse %"PRIu64", stream_pool_memcnt %"PRIu64"", stream_pool_memuse, stream_pool_memcnt); SCLogDebug("stream_pool_memuse %"PRIu64", stream_pool_memcnt %"PRIu64"", stream_pool_memuse, stream_pool_memcnt);
@ -164,8 +164,8 @@ StreamMsgQueue *StreamMsgQueueGetNew(void) {
} }
memset(smq, 0x00, sizeof(StreamMsgQueue)); memset(smq, 0x00, sizeof(StreamMsgQueue));
sc_mutex_init(&smq->mutex_q, NULL); SCMutexInit(&smq->mutex_q, NULL);
sc_cond_init(&smq->cond_q, NULL); SCCondInit(&smq->cond_q, NULL);
return smq; return smq;
} }
@ -184,7 +184,7 @@ StreamMsgQueue *StreamMsgQueueGetByPort(uint16_t port) {
/* XXX hack */ /* XXX hack */
void StreamMsgSignalQueueHack(void) { void StreamMsgSignalQueueHack(void) {
//sc_cond_signal(&stream_q.cond_q); //SCCondSignal(&stream_q.cond_q);
} }
void StreamMsgQueueSetMinInitChunkLen(uint8_t dir, uint16_t len) { void StreamMsgQueueSetMinInitChunkLen(uint8_t dir, uint16_t len) {

@ -40,8 +40,8 @@ typedef struct StreamMsgQueue_ {
StreamMsg *top; StreamMsg *top;
StreamMsg *bot; StreamMsg *bot;
uint16_t len; uint16_t len;
sc_mutex_t mutex_q; SCMutex mutex_q;
sc_cond_t cond_q; SCCondT cond_q;
#ifdef DBG_PERF #ifdef DBG_PERF
uint16_t dbg_maxlen; uint16_t dbg_maxlen;
#endif /* DBG_PERF */ #endif /* DBG_PERF */

@ -18,13 +18,13 @@
* \brief Test Mutex macros * \brief Test Mutex macros
*/ */
int ThreadMacrosTest01Mutex(void) { int ThreadMacrosTest01Mutex(void) {
sc_mutex_t mut; SCMutex mut;
int r = 0; int r = 0;
r |= sc_mutex_init(&mut, NULL); r |= SCMutexInit(&mut, NULL);
r |= sc_mutex_lock(&mut); r |= SCMutexLock(&mut);
r |= (sc_mutex_trylock(&mut) == EBUSY)? 0 : 1; r |= (SCMutexTrylock(&mut) == EBUSY)? 0 : 1;
r |= sc_mutex_unlock(&mut); r |= SCMutexUnlock(&mut);
r |= sc_mutex_destroy(&mut); r |= SCMutexDestroy(&mut);
return (r == 0)? 1 : 0; return (r == 0)? 1 : 0;
} }
@ -33,13 +33,13 @@ int ThreadMacrosTest01Mutex(void) {
* \brief Test Spin Macros * \brief Test Spin Macros
*/ */
int ThreadMacrosTest02Spinlocks(void) { int ThreadMacrosTest02Spinlocks(void) {
sc_spin_t mut; SCSpinlock mut;
int r = 0; int r = 0;
r |= sc_spin_init(&mut, 0); r |= SCSpinInit(&mut, 0);
r |= sc_spin_lock(&mut); r |= SCSpinLock(&mut);
r |= (sc_spin_trylock(&mut) == EBUSY)? 0 : 1; r |= (SCSpinTrylock(&mut) == EBUSY)? 0 : 1;
r |= sc_spin_unlock(&mut); r |= SCSpinUnlock(&mut);
r |= sc_spin_destroy(&mut); r |= SCSpinDestroy(&mut);
return (r == 0)? 1 : 0; return (r == 0)? 1 : 0;
} }

@ -20,9 +20,9 @@
//#define DBG_THREADS //#define DBG_THREADS
/** Suricata Mutex */ /** Suricata Mutex */
#define sc_mutex_t pthread_mutex_t #define SCMutex pthread_mutex_t
#define sc_mutexattr_t pthread_mutexattr_t #define SCMutexAttr pthread_mutexattr_t
#define sc_mutex_destroy pthread_mutex_destroy #define SCMutexDestroy pthread_mutex_destroy
/** Mutex Functions */ /** Mutex Functions */
#ifdef DBG_THREADS #ifdef DBG_THREADS
@ -31,7 +31,7 @@
* It is for Mac OS X users; * It is for Mac OS X users;
* If you see a mutex, spinlock or condiion not initialized, report it please! * If you see a mutex, spinlock or condiion not initialized, report it please!
*/ */
#define sc_mutex_lock_dbg(mut) ({ \ #define SCMutexLock_dbg(mut) ({ \
printf("%16s(%s:%d): (thread:%"PRIuMAX") locking mutex %p\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), mut); \ printf("%16s(%s:%d): (thread:%"PRIuMAX") locking mutex %p\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), mut); \
int retl = pthread_mutex_lock(mut); \ int retl = pthread_mutex_lock(mut); \
printf("%16s(%s:%d): (thread:%"PRIuMAX") locked mutex %p ret %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), mut, retl); \ printf("%16s(%s:%d): (thread:%"PRIuMAX") locked mutex %p ret %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), mut, retl); \
@ -52,7 +52,7 @@
retl; \ retl; \
}) })
#define sc_mutex_trylock_dbg(mut) ({ \ #define SCMutexTrylock_dbg(mut) ({ \
printf("%16s(%s:%d): (thread:%"PRIuMAX") trylocking mutex %p\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), mut); \ printf("%16s(%s:%d): (thread:%"PRIuMAX") trylocking mutex %p\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), mut); \
int rett = pthread_mutex_trylock(mut); \ int rett = pthread_mutex_trylock(mut); \
printf("%16s(%s:%d): (thread:%"PRIuMAX") trylocked mutex %p ret %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), mut, rett); \ printf("%16s(%s:%d): (thread:%"PRIuMAX") trylocked mutex %p ret %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), mut, rett); \
@ -69,7 +69,7 @@
rett; \ rett; \
}) })
#define sc_mutex_init_dbg(mut, mutattr) ({ \ #define SCMutexInit_dbg(mut, mutattr) ({ \
int ret; \ int ret; \
ret = pthread_mutex_init(mut, mutattr); \ ret = pthread_mutex_init(mut, mutattr); \
if (ret != 0) { \ if (ret != 0) { \
@ -91,7 +91,7 @@
ret; \ ret; \
}) })
#define sc_mutex_unlock_dbg(mut) ({ \ #define SCMutexUnlock_dbg(mut) ({ \
printf("%16s(%s:%d): (thread:%"PRIuMAX") unlocking mutex %p\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), mut); \ printf("%16s(%s:%d): (thread:%"PRIuMAX") unlocking mutex %p\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), mut); \
int retu = pthread_mutex_unlock(mut); \ int retu = pthread_mutex_unlock(mut); \
printf("%16s(%s:%d): (thread:%"PRIuMAX") unlocked mutex %p ret %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), mut, retu); \ printf("%16s(%s:%d): (thread:%"PRIuMAX") unlocked mutex %p ret %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), mut, retu); \
@ -108,55 +108,55 @@
retu; \ retu; \
}) })
#define sc_mutex_init(mut, mutattrs) sc_mutex_init_dbg(mut, mutattrs) #define SCMutexInit(mut, mutattrs) SCMutexInit_dbg(mut, mutattrs)
#define sc_mutex_lock(mut) sc_mutex_lock_dbg(mut) #define SCMutexLock(mut) SCMutexLock_dbg(mut)
#define sc_mutex_trylock(mut) sc_mutex_trylock_dbg(mut) #define SCMutexTrylock(mut) SCMutexTrylock_dbg(mut)
#define sc_mutex_unlock(mut) sc_mutex_unlock_dbg(mut) #define SCMutexUnlock(mut) SCMutexUnlock_dbg(mut)
#else #else
#define sc_mutex_init(mut, mutattr ) pthread_mutex_init(mut, mutattr) #define SCMutexInit(mut, mutattr ) pthread_mutex_init(mut, mutattr)
#define sc_mutex_lock(mut) pthread_mutex_lock(mut) #define SCMutexLock(mut) pthread_mutex_lock(mut)
#define sc_mutex_trylock(mut) pthread_mutex_trylock(mut) #define SCMutexTrylock(mut) pthread_mutex_trylock(mut)
#define sc_mutex_unlock(mut) pthread_mutex_unlock(mut) #define SCMutexUnlock(mut) pthread_mutex_unlock(mut)
#endif #endif
/** Conditions/Signals */ /** Conditions/Signals */
/* Here we don't need to do nothing atm */ /* Here we don't need to do nothing atm */
#define sc_cond_t pthread_cond_t #define SCCondT pthread_cond_t
#define sc_cond_init pthread_cond_init #define SCCondInit pthread_cond_init
#define sc_cond_signal pthread_cond_signal #define SCCondSignal pthread_cond_signal
#define sc_cond_timedwait pthread_cond_timedwait #define SCCondTimedwait pthread_cond_timedwait
#ifdef DBG_THREAD #ifdef DBG_THREAD
#define sc_cond_wait_dbg(cond, mut) ({ \ #define SCondWait_dbg(cond, mut) ({ \
int ret = pthread_cond_wait(cond, mut); \ int ret = pthread_cond_wait(cond, mut); \
switch (ret) { \ switch (ret) { \
case EINVAL: \ case EINVAL: \
printf("The value specified by attr is invalid (or a sc_cond_t not initialized!)\n"); \ printf("The value specified by attr is invalid (or a SCCondT not initialized!)\n"); \
printf("%16s(%s:%d): (thread:%"PRIuMAX") failed sc_cond_wait %p ret %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), mut, retu); \ printf("%16s(%s:%d): (thread:%"PRIuMAX") failed SCondWait %p ret %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), mut, retu); \
break; \ break; \
} \ } \
ret; \ ret; \
}) })
#define sc_cond_wait sc_cond_wait_dbg #define SCondWait SCondWait_dbg
#else #else
#define sc_cond_wait(cond, mut) pthread_cond_wait(cond, mut) #define SCondWait(cond, mut) pthread_cond_wait(cond, mut)
#endif #endif
/** Spinlocks */ /** Spinlocks */
#define sc_spin_t pthread_spinlock_t #define SCSpinlock pthread_spinlock_t
/** If posix spin not supported, use mutex */ /** If posix spin not supported, use mutex */
#if ((_POSIX_SPIN_LOCKS - 200112L) < 0L) #if ((_POSIX_SPIN_LOCKS - 200112L) < 0L)
#define pthread_spinlock_t pthread_mutex_t #define pthread_spinlock_t pthread_mutex_t
#define pthread_spin_init(target,arg) sc_mutex_init(target, NULL) #define pthread_spin_init(target,arg) SCMutexInit(target, NULL)
#define pthread_spin_lock(spin) sc_mutex_lock(spin) #define pthread_spin_lock(spin) SCMutexLock(spin)
#define pthread_spin_trylock(spin) sc_mutex_trylock(spin) #define pthread_spin_trylock(spin) SCMutexTrylock(spin)
#define pthread_spin_unlock(spin) sc_mutex_unlock(spin) #define pthread_spin_unlock(spin) SCMutexUnlock(spin)
#define pthread_spin_destroy(spin) sc_mutex_destroy(spin) #define pthread_spin_destroy(spin) SCMutexDestroy(spin)
#endif /* End Spin not supported */ #endif /* End Spin not supported */
#ifdef DBG_THREADS #ifdef DBG_THREADS
#define sc_spin_lock_dbg(spin) ({ \ #define SCSpinLock_dbg(spin) ({ \
printf("%16s(%s:%d): (thread:%"PRIuMAX") locking spin %p\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), spin); \ printf("%16s(%s:%d): (thread:%"PRIuMAX") locking spin %p\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), spin); \
int ret = pthread_spin_lock(spin); \ int ret = pthread_spin_lock(spin); \
printf("%16s(%s:%d): (thread:%"PRIuMAX") unlocked spin %p ret %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), spin, ret); \ printf("%16s(%s:%d): (thread:%"PRIuMAX") unlocked spin %p ret %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), spin, ret); \
@ -171,7 +171,7 @@
ret; \ ret; \
}) })
#define sc_spin_trylock_dbg(spin) ({ \ #define SCSpinTrylock_dbg(spin) ({ \
printf("%16s(%s:%d): (thread:%"PRIuMAX") trylocking spin %p\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), spin); \ printf("%16s(%s:%d): (thread:%"PRIuMAX") trylocking spin %p\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), spin); \
int ret = pthread_spin_trylock(spin); \ int ret = pthread_spin_trylock(spin); \
printf("%16s(%s:%d): (thread:%"PRIuMAX") trylocked spin %p ret %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), spin, ret); \ printf("%16s(%s:%d): (thread:%"PRIuMAX") trylocked spin %p ret %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), spin, ret); \
@ -189,7 +189,7 @@
ret; \ ret; \
}) })
#define sc_spin_unlock_dbg(spin) ({ \ #define SCSpinUnlock_dbg(spin) ({ \
printf("%16s(%s:%d): (thread:%"PRIuMAX") unlocking spin %p\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), spin); \ printf("%16s(%s:%d): (thread:%"PRIuMAX") unlocking spin %p\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), spin); \
int ret = pthread_spin_unlock(spin); \ int ret = pthread_spin_unlock(spin); \
printf("%16s(%s:%d): (thread:%"PRIuMAX") unlockedspin %p ret %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), spin, ret); \ printf("%16s(%s:%d): (thread:%"PRIuMAX") unlockedspin %p ret %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), spin, ret); \
@ -204,7 +204,7 @@
ret; \ ret; \
}) })
#define sc_spin_init_dbg(spin, spin_attr) ({ \ #define SCSpinInit_dbg(spin, spin_attr) ({ \
int ret = pthread_spin_init(spin, spin_attr); \ int ret = pthread_spin_init(spin, spin_attr); \
printf("%16s(%s:%d): (thread:%"PRIuMAX") spinlock %p initialization returned %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), spin, ret); \ printf("%16s(%s:%d): (thread:%"PRIuMAX") spinlock %p initialization returned %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), spin, ret); \
switch (ret) { \ switch (ret) { \
@ -224,7 +224,7 @@
ret; \ ret; \
}) })
#define sc_spin_destroy_dbg(spin) ({ \ #define SCSpinDestroy_dbg(spin) ({ \
printf("%16s(%s:%d): (thread:%"PRIuMAX") condition %p waiting\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), spin); \ printf("%16s(%s:%d): (thread:%"PRIuMAX") condition %p waiting\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), spin); \
int ret = pthread_spin_destroy(spin); \ int ret = pthread_spin_destroy(spin); \
printf("%16s(%s:%d): (thread:%"PRIuMAX") condition %p passed %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), spin, ret); \ printf("%16s(%s:%d): (thread:%"PRIuMAX") condition %p passed %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), spin, ret); \
@ -245,17 +245,17 @@
ret; \ ret; \
}) })
#define sc_spin_lock sc_spin_lock_dbg #define SCSpinLock SCSpinLock_dbg
#define sc_spin_trylock sc_spin_trylock_dbg #define SCSpinTrylock SCSpinTrylock_dbg
#define sc_spin_unlock sc_spin_unlock_dbg #define SCSpinUnlock SCSpinUnlock_dbg
#define sc_spin_init sc_spin_init_dbg #define SCSpinInit SCSpinInit_dbg
#define sc_spin_destroy sc_spin_destroy_dbg #define SCSpinDestroy SCSpinDestroy_dbg
#else /* if no dbg threads defined... */ #else /* if no dbg threads defined... */
#define sc_spin_lock(spin) pthread_spin_lock(spin) #define SCSpinLock(spin) pthread_spin_lock(spin)
#define sc_spin_trylock(spin) pthread_spin_trylock(spin) #define SCSpinTrylock(spin) pthread_spin_trylock(spin)
#define sc_spin_unlock(spin) pthread_spin_unlock(spin) #define SCSpinUnlock(spin) pthread_spin_unlock(spin)
#define sc_spin_init(spin, spin_attr) pthread_spin_init(spin, spin_attr) #define SCSpinInit(spin, spin_attr) pthread_spin_init(spin, spin_attr)
#define sc_spin_destroy(spin) pthread_spin_destroy(spin) #define SCSpinDestroy(spin) pthread_spin_destroy(spin)
#endif /* DBG_THREADS */ #endif /* DBG_THREADS */

@ -30,7 +30,7 @@ typedef struct ThreadVars_ {
char *name; char *name;
uint8_t flags; uint8_t flags;
sc_spin_t flags_spinlock; SCSpinlock flags_spinlock;
/** aof(action on failure) determines what should be done with the thread /** aof(action on failure) determines what should be done with the thread
when it encounters certain conditions like failures */ when it encounters certain conditions like failures */
@ -62,8 +62,8 @@ typedef struct ThreadVars_ {
SCPerfContext sc_perf_pctx; SCPerfContext sc_perf_pctx;
SCPerfCounterArray *sc_perf_pca; SCPerfCounterArray *sc_perf_pca;
sc_mutex_t *m; SCMutex *m;
sc_cond_t *cond; SCCondT *cond;
struct ThreadVars_ *next; struct ThreadVars_ *next;
struct ThreadVars_ *prev; struct ThreadVars_ *prev;

@ -55,8 +55,8 @@ LogFileCtx *LogFileNewCtx()
} }
memset(lf_ctx, 0, sizeof(LogFileCtx)); memset(lf_ctx, 0, sizeof(LogFileCtx));
/** Ensure that it is unlocked */ /** Ensure that it is unlocked */
sc_mutex_init(&lf_ctx->fp_mutex,NULL); SCMutexInit(&lf_ctx->fp_mutex,NULL);
sc_mutex_unlock(&lf_ctx->fp_mutex); SCMutexUnlock(&lf_ctx->fp_mutex);
return lf_ctx; return lf_ctx;
} }
@ -73,9 +73,9 @@ int LogFileFreeCtx(LogFileCtx *lf_ctx)
{ {
if (lf_ctx->fp != NULL) if (lf_ctx->fp != NULL)
{ {
sc_mutex_lock(&lf_ctx->fp_mutex); SCMutexLock(&lf_ctx->fp_mutex);
fclose(lf_ctx->fp); fclose(lf_ctx->fp);
sc_mutex_unlock(&lf_ctx->fp_mutex); SCMutexUnlock(&lf_ctx->fp_mutex);
} }
if (lf_ctx->config_file != NULL); if (lf_ctx->config_file != NULL);
free(lf_ctx->config_file); free(lf_ctx->config_file);

@ -56,7 +56,7 @@ typedef struct LogFileCtx_ {
FILE *fp; FILE *fp;
/** It will be locked if the log/alert /** It will be locked if the log/alert
* record cannot be written to the file in one call */ * record cannot be written to the file in one call */
sc_mutex_t fp_mutex; SCMutex fp_mutex;
/** To know where did we read this config */ /** To know where did we read this config */
char *config_file; char *config_file;

@ -50,9 +50,9 @@ void TmqDebugList(void) {
uint16_t i = 0; uint16_t i = 0;
for (i = 0; i < tmq_id; i++) { for (i = 0; i < tmq_id; i++) {
/* get a lock accessing the len */ /* get a lock accessing the len */
sc_mutex_lock(&trans_q[tmqs[i].id].mutex_q); SCMutexLock(&trans_q[tmqs[i].id].mutex_q);
printf("TmqDebugList: id %" PRIu32 ", name \'%s\', len %" PRIu32 "\n", tmqs[i].id, tmqs[i].name, trans_q[tmqs[i].id].len); printf("TmqDebugList: id %" PRIu32 ", name \'%s\', len %" PRIu32 "\n", tmqs[i].id, tmqs[i].name, trans_q[tmqs[i].id].len);
sc_mutex_unlock(&trans_q[tmqs[i].id].mutex_q); SCMutexUnlock(&trans_q[tmqs[i].id].mutex_q);
} }
} }
@ -71,7 +71,7 @@ void TmValidateQueueState(void)
char err = FALSE; char err = FALSE;
for (i = 0; i < tmq_id; i++) { for (i = 0; i < tmq_id; i++) {
sc_mutex_lock(&trans_q[tmqs[i].id].mutex_q); SCMutexLock(&trans_q[tmqs[i].id].mutex_q);
if (tmqs[i].reader_cnt == 0) { if (tmqs[i].reader_cnt == 0) {
printf("Error: Queue \"%s\" doesn't have a reader\n", tmqs[i].name); printf("Error: Queue \"%s\" doesn't have a reader\n", tmqs[i].name);
err = TRUE; err = TRUE;
@ -79,7 +79,7 @@ void TmValidateQueueState(void)
printf("Error: Queue \"%s\" doesn't have a writer\n", tmqs[i].name); printf("Error: Queue \"%s\" doesn't have a writer\n", tmqs[i].name);
err = TRUE; err = TRUE;
} }
sc_mutex_unlock(&trans_q[tmqs[i].id].mutex_q); SCMutexUnlock(&trans_q[tmqs[i].id].mutex_q);
if (err == TRUE) if (err == TRUE)
goto error; goto error;

@ -37,7 +37,7 @@ static int SetCPUAffinity(int cpu);
ThreadVars *tv_root[TVT_MAX] = { NULL }; ThreadVars *tv_root[TVT_MAX] = { NULL };
/* lock to protect tv_root */ /* lock to protect tv_root */
sc_mutex_t tv_root_lock = PTHREAD_MUTEX_INITIALIZER; SCMutex tv_root_lock = PTHREAD_MUTEX_INITIALIZER;
/* Action On Failure(AOF). Determines how the engine should behave when a /* Action On Failure(AOF). Determines how the engine should behave when a
thread encounters a failure. Defaults to restart the failed thread */ thread encounters a failure. Defaults to restart the failed thread */
@ -75,34 +75,34 @@ typedef struct TmVarSlot_ {
*/ */
inline int TmThreadsCheckFlag(ThreadVars *tv, uint8_t flag) { inline int TmThreadsCheckFlag(ThreadVars *tv, uint8_t flag) {
int r; int r;
if (sc_spin_lock(&tv->flags_spinlock) != 0) { if (SCSpinLock(&tv->flags_spinlock) != 0) {
SCLogError(SC_SPINLOCK_ERROR,"spin lock errno=%d",errno); SCLogError(SC_SPINLOCK_ERROR,"spin lock errno=%d",errno);
return 0; return 0;
} }
r = (tv->flags & flag); r = (tv->flags & flag);
sc_spin_unlock(&tv->flags_spinlock); SCSpinUnlock(&tv->flags_spinlock);
return r; return r;
} }
inline void TmThreadsSetFlag(ThreadVars *tv, uint8_t flag) { inline void TmThreadsSetFlag(ThreadVars *tv, uint8_t flag) {
if (sc_spin_lock(&tv->flags_spinlock) != 0) { if (SCSpinLock(&tv->flags_spinlock) != 0) {
SCLogError(SC_SPINLOCK_ERROR,"spin lock errno=%d",errno); SCLogError(SC_SPINLOCK_ERROR,"spin lock errno=%d",errno);
return; return;
} }
tv->flags |= flag; tv->flags |= flag;
sc_spin_unlock(&tv->flags_spinlock); SCSpinUnlock(&tv->flags_spinlock);
} }
inline void TmThreadsUnsetFlag(ThreadVars *tv, uint8_t flag) { inline void TmThreadsUnsetFlag(ThreadVars *tv, uint8_t flag) {
if (sc_spin_lock(&tv->flags_spinlock) != 0) { if (SCSpinLock(&tv->flags_spinlock) != 0) {
SCLogError(SC_SPINLOCK_ERROR,"spin lock errno=%d",errno); SCLogError(SC_SPINLOCK_ERROR,"spin lock errno=%d",errno);
return; return;
} }
tv->flags &= ~flag; tv->flags &= ~flag;
sc_spin_unlock(&tv->flags_spinlock); SCSpinUnlock(&tv->flags_spinlock);
} }
/* 1 slot functions */ /* 1 slot functions */
@ -636,8 +636,8 @@ ThreadVars *TmThreadCreate(char *name, char *inq_name, char *inqh_name,
if (tv == NULL) goto error; if (tv == NULL) goto error;
memset(tv, 0, sizeof(ThreadVars)); memset(tv, 0, sizeof(ThreadVars));
sc_spin_init(&tv->flags_spinlock, PTHREAD_PROCESS_PRIVATE); SCSpinInit(&tv->flags_spinlock, PTHREAD_PROCESS_PRIVATE);
sc_mutex_init(&tv->sc_perf_pctx.m, NULL); SCMutexInit(&tv->sc_perf_pctx.m, NULL);
tv->name = name; tv->name = name;
/* default state for every newly created thread */ /* default state for every newly created thread */
@ -769,7 +769,7 @@ ThreadVars *TmThreadCreateMgmtThread(char *name, void *(fn_p)(void *),
*/ */
void TmThreadAppend(ThreadVars *tv, int type) void TmThreadAppend(ThreadVars *tv, int type)
{ {
sc_mutex_lock(&tv_root_lock); SCMutexLock(&tv_root_lock);
if (tv_root[type] == NULL) { if (tv_root[type] == NULL) {
tv_root[type] = tv; tv_root[type] = tv;
@ -777,7 +777,7 @@ void TmThreadAppend(ThreadVars *tv, int type)
tv->prev = NULL; tv->prev = NULL;
//printf("TmThreadAppend: thread \'%s\' is the first thread in the list.\n", tv->name); //printf("TmThreadAppend: thread \'%s\' is the first thread in the list.\n", tv->name);
sc_mutex_unlock(&tv_root_lock); SCMutexUnlock(&tv_root_lock);
return; return;
} }
@ -794,7 +794,7 @@ void TmThreadAppend(ThreadVars *tv, int type)
t = t->next; t = t->next;
} }
sc_mutex_unlock(&tv_root_lock); SCMutexUnlock(&tv_root_lock);
//printf("TmThreadAppend: thread \'%s\' is added to the list.\n", tv->name); //printf("TmThreadAppend: thread \'%s\' is added to the list.\n", tv->name);
} }
@ -819,12 +819,12 @@ void TmThreadKillThreads(void) {
//printf("TmThreadKillThreads: (t->inq->reader_cnt + t->inq->writer_cnt) %" PRIu32 "\n", (t->inq->reader_cnt + t->inq->writer_cnt)); //printf("TmThreadKillThreads: (t->inq->reader_cnt + t->inq->writer_cnt) %" PRIu32 "\n", (t->inq->reader_cnt + t->inq->writer_cnt));
/* make sure our packet pending counter doesn't block */ /* make sure our packet pending counter doesn't block */
sc_cond_signal(&cond_pending); SCCondSignal(&cond_pending);
/* signal the queue for the number of users */ /* signal the queue for the number of users */
for (i = 0; i < (tv->inq->reader_cnt + tv->inq->writer_cnt); i++) for (i = 0; i < (tv->inq->reader_cnt + tv->inq->writer_cnt); i++)
sc_cond_signal(&trans_q[tv->inq->id].cond_q); SCCondSignal(&trans_q[tv->inq->id].cond_q);
/* to be sure, signal more */ /* to be sure, signal more */
int cnt = 0; int cnt = 0;
@ -837,7 +837,7 @@ void TmThreadKillThreads(void) {
cnt++; cnt++;
for (i = 0; i < (tv->inq->reader_cnt + tv->inq->writer_cnt); i++) for (i = 0; i < (tv->inq->reader_cnt + tv->inq->writer_cnt); i++)
sc_cond_signal(&trans_q[tv->inq->id].cond_q); SCCondSignal(&trans_q[tv->inq->id].cond_q);
usleep(100); usleep(100);
} }
@ -935,22 +935,22 @@ void TmThreadSetAOF(ThreadVars *tv, uint8_t aof)
*/ */
void TmThreadInitMC(ThreadVars *tv) void TmThreadInitMC(ThreadVars *tv)
{ {
if ( (tv->m = malloc(sizeof(sc_mutex_t))) == NULL) { if ( (tv->m = malloc(sizeof(SCMutex))) == NULL) {
printf("Error allocating memory\n"); printf("Error allocating memory\n");
exit(0); exit(0);
} }
if (sc_mutex_init(tv->m, NULL) != 0) { if (SCMutexInit(tv->m, NULL) != 0) {
printf("Error initializing the tv->m mutex\n"); printf("Error initializing the tv->m mutex\n");
exit(0); exit(0);
} }
if ( (tv->cond = malloc(sizeof(sc_cond_t))) == NULL) { if ( (tv->cond = malloc(sizeof(SCCondT))) == NULL) {
printf("Error allocating memory\n"); printf("Error allocating memory\n");
exit(0); exit(0);
} }
if (sc_cond_init(tv->cond, NULL) != 0) { if (SCCondInit(tv->cond, NULL) != 0) {
printf("Error initializing the tv->cond condition variable\n"); printf("Error initializing the tv->cond condition variable\n");
exit(0); exit(0);
} }
@ -1154,20 +1154,20 @@ ThreadVars *TmThreadsGetCallingThread(void)
ThreadVars *tv = NULL; ThreadVars *tv = NULL;
int i = 0; int i = 0;
sc_mutex_lock(&tv_root_lock); SCMutexLock(&tv_root_lock);
for (i = 0; i < TVT_MAX; i++) { for (i = 0; i < TVT_MAX; i++) {
tv = tv_root[i]; tv = tv_root[i];
while (tv) { while (tv) {
if (pthread_equal(self, tv->t)) { if (pthread_equal(self, tv->t)) {
sc_mutex_unlock(&tv_root_lock); SCMutexUnlock(&tv_root_lock);
return tv; return tv;
} }
tv = tv->next; tv = tv->next;
} }
} }
sc_mutex_unlock(&tv_root_lock); SCMutexUnlock(&tv_root_lock);
return NULL; return NULL;
} }

@ -12,7 +12,7 @@ enum {
extern ThreadVars *tv_root[TVT_MAX]; extern ThreadVars *tv_root[TVT_MAX];
extern sc_mutex_t tv_root_lock; extern SCMutex tv_root_lock;
void Tm1SlotSetFunc(ThreadVars *, TmModule *, void *); void Tm1SlotSetFunc(ThreadVars *, TmModule *, void *);

@ -49,10 +49,10 @@ Packet *TmqhInputFlow(ThreadVars *tv)
{ {
PacketQueue *q = &trans_q[tv->inq->id]; PacketQueue *q = &trans_q[tv->inq->id];
sc_mutex_lock(&q->mutex_q); SCMutexLock(&q->mutex_q);
if (q->len == 0) { if (q->len == 0) {
/* if we have no packets in queue, wait... */ /* if we have no packets in queue, wait... */
sc_cond_wait(&q->cond_q, &q->mutex_q); SCondWait(&q->cond_q, &q->mutex_q);
} }
if (tv->sc_perf_pctx.perf_flag == 1) if (tv->sc_perf_pctx.perf_flag == 1)
@ -60,11 +60,11 @@ Packet *TmqhInputFlow(ThreadVars *tv)
if (q->len > 0) { if (q->len > 0) {
Packet *p = PacketDequeue(q); Packet *p = PacketDequeue(q);
sc_mutex_unlock(&q->mutex_q); SCMutexUnlock(&q->mutex_q);
return p; return p;
} else { } else {
/* return NULL if we have no pkt. Should only happen on signals. */ /* return NULL if we have no pkt. Should only happen on signals. */
sc_mutex_unlock(&q->mutex_q); SCMutexUnlock(&q->mutex_q);
return NULL; return NULL;
} }
} }
@ -177,10 +177,10 @@ void TmqhOutputFlow(ThreadVars *tv, Packet *p)
} }
PacketQueue *q = &trans_q[qid]; PacketQueue *q = &trans_q[qid];
sc_mutex_lock(&q->mutex_q); SCMutexLock(&q->mutex_q);
PacketEnqueue(q, p); PacketEnqueue(q, p);
sc_cond_signal(&q->cond_q); SCCondSignal(&q->cond_q);
sc_mutex_unlock(&q->mutex_q); SCMutexUnlock(&q->mutex_q);
} }
#ifdef UNITTESTS #ifdef UNITTESTS

@ -22,10 +22,10 @@ void TmqhOutputVerdictNfq(ThreadVars *t, Packet *p)
#if 0 #if 0
PacketQueue *q = &trans_q[p->verdict_q_id]; PacketQueue *q = &trans_q[p->verdict_q_id];
sc_mutex_lock(&q->mutex_q); SCMutexLock(&q->mutex_q);
PacketEnqueue(q, p); PacketEnqueue(q, p);
sc_cond_signal(&q->cond_q); SCCondSignal(&q->cond_q);
sc_mutex_unlock(&q->mutex_q); SCMutexUnlock(&q->mutex_q);
#endif #endif
} }

@ -26,14 +26,14 @@ Packet *TmqhInputPacketpool(ThreadVars *t)
/* XXX */ /* XXX */
Packet *p = SetupPkt(); Packet *p = SetupPkt();
sc_mutex_lock(&mutex_pending); SCMutexLock(&mutex_pending);
pending++; pending++;
//printf("PcapFileCallback: pending %" PRIu32 "\n", pending); //printf("PcapFileCallback: pending %" PRIu32 "\n", pending);
#ifdef DBG_PERF #ifdef DBG_PERF
if (pending > dbg_maxpending) if (pending > dbg_maxpending)
dbg_maxpending = pending; dbg_maxpending = pending;
#endif /* DBG_PERF */ #endif /* DBG_PERF */
sc_mutex_unlock(&mutex_pending); SCMutexUnlock(&mutex_pending);
/* /*
* Disabled because it can enter a 'wait' state, while * Disabled because it can enter a 'wait' state, while
@ -41,11 +41,11 @@ Packet *TmqhInputPacketpool(ThreadVars *t)
* to free packets, the exact condition we are waiting * to free packets, the exact condition we are waiting
* for. VJ 09-01-16 * for. VJ 09-01-16
* *
sc_mutex_lock(&mutex_pending); SCMutexLock(&mutex_pending);
if (pending > MAX_PENDING) { if (pending > MAX_PENDING) {
sc_cond_wait(&cond_pending, &mutex_pending); SCondWait(&cond_pending, &mutex_pending);
} }
sc_mutex_unlock(&mutex_pending); SCMutexUnlock(&mutex_pending);
*/ */
return p; return p;
} }
@ -62,8 +62,8 @@ void TmqhOutputPacketpool(ThreadVars *t, Packet *p)
//printf("TmqhOutputPacketpool: tunnel packet: %p %s\n", p,p->root ? "upper layer":"root"); //printf("TmqhOutputPacketpool: tunnel packet: %p %s\n", p,p->root ? "upper layer":"root");
/* get a lock */ /* get a lock */
sc_mutex_t *m = p->root ? &p->root->mutex_rtv_cnt : &p->mutex_rtv_cnt; SCMutex *m = p->root ? &p->root->mutex_rtv_cnt : &p->mutex_rtv_cnt;
sc_mutex_lock(m); SCMutexLock(m);
if (IS_TUNNEL_ROOT_PKT(p)) { if (IS_TUNNEL_ROOT_PKT(p)) {
//printf("TmqhOutputPacketpool: IS_TUNNEL_ROOT_PKT\n"); //printf("TmqhOutputPacketpool: IS_TUNNEL_ROOT_PKT\n");
@ -80,7 +80,7 @@ void TmqhOutputPacketpool(ThreadVars *t, Packet *p)
* by the tunnel packets, and we will enqueue it * by the tunnel packets, and we will enqueue it
* when we handle them */ * when we handle them */
p->tunnel_verdicted = 1; p->tunnel_verdicted = 1;
sc_mutex_unlock(m); SCMutexUnlock(m);
return; return;
} }
} else { } else {
@ -103,7 +103,7 @@ void TmqhOutputPacketpool(ThreadVars *t, Packet *p)
/* fall through */ /* fall through */
} }
} }
sc_mutex_unlock(m); SCMutexUnlock(m);
//printf("TmqhOutputPacketpool: tunnel stuff done, move on\n"); //printf("TmqhOutputPacketpool: tunnel stuff done, move on\n");
} }
@ -112,18 +112,18 @@ void TmqhOutputPacketpool(ThreadVars *t, Packet *p)
if (proot && p->root != NULL) { if (proot && p->root != NULL) {
CLEAR_PACKET(p->root); CLEAR_PACKET(p->root);
sc_mutex_lock(&q->mutex_q); SCMutexLock(&q->mutex_q);
PacketEnqueue(q, p->root); PacketEnqueue(q, p->root);
sc_mutex_unlock(&q->mutex_q); SCMutexUnlock(&q->mutex_q);
} }
CLEAR_PACKET(p); CLEAR_PACKET(p);
sc_mutex_lock(&q->mutex_q); SCMutexLock(&q->mutex_q);
PacketEnqueue(q, p); PacketEnqueue(q, p);
sc_mutex_unlock(&q->mutex_q); SCMutexUnlock(&q->mutex_q);
sc_mutex_lock(&mutex_pending); SCMutexLock(&mutex_pending);
//printf("TmqhOutputPacketpool: pending %" PRIu32 "\n", pending); //printf("TmqhOutputPacketpool: pending %" PRIu32 "\n", pending);
if (pending > 0) { if (pending > 0) {
pending--; pending--;
@ -138,8 +138,8 @@ void TmqhOutputPacketpool(ThreadVars *t, Packet *p)
printf("TmqhOutputPacketpool: warning, trying to subtract from 0 pending counter.\n"); printf("TmqhOutputPacketpool: warning, trying to subtract from 0 pending counter.\n");
} }
if (pending <= MAX_PENDING) if (pending <= MAX_PENDING)
sc_cond_signal(&cond_pending); SCCondSignal(&cond_pending);
sc_mutex_unlock(&mutex_pending); SCMutexUnlock(&mutex_pending);
} }
/** /**
@ -157,12 +157,12 @@ void TmqhReleasePacketsToPacketPool(PacketQueue *pq)
if (pq == NULL) if (pq == NULL)
return; return;
sc_mutex_lock(&pq->mutex_q); SCMutexLock(&pq->mutex_q);
while ( (p = PacketDequeue(pq)) != NULL) while ( (p = PacketDequeue(pq)) != NULL)
TmqhOutputPacketpool(NULL, p); TmqhOutputPacketpool(NULL, p);
sc_mutex_unlock(&pq->mutex_q); SCMutexUnlock(&pq->mutex_q);
return; return;
} }

@ -20,10 +20,10 @@ Packet *TmqhInputSimple(ThreadVars *t)
{ {
PacketQueue *q = &trans_q[t->inq->id]; PacketQueue *q = &trans_q[t->inq->id];
sc_mutex_lock(&q->mutex_q); SCMutexLock(&q->mutex_q);
if (q->len == 0) { if (q->len == 0) {
/* if we have no packets in queue, wait... */ /* if we have no packets in queue, wait... */
sc_cond_wait(&q->cond_q, &q->mutex_q); SCondWait(&q->cond_q, &q->mutex_q);
} }
if (t->sc_perf_pctx.perf_flag == 1) if (t->sc_perf_pctx.perf_flag == 1)
@ -31,11 +31,11 @@ Packet *TmqhInputSimple(ThreadVars *t)
if (q->len > 0) { if (q->len > 0) {
Packet *p = PacketDequeue(q); Packet *p = PacketDequeue(q);
sc_mutex_unlock(&q->mutex_q); SCMutexUnlock(&q->mutex_q);
return p; return p;
} else { } else {
/* return NULL if we have no pkt. Should only happen on signals. */ /* return NULL if we have no pkt. Should only happen on signals. */
sc_mutex_unlock(&q->mutex_q); SCMutexUnlock(&q->mutex_q);
return NULL; return NULL;
} }
} }
@ -44,9 +44,9 @@ void TmqhOutputSimple(ThreadVars *t, Packet *p)
{ {
PacketQueue *q = &trans_q[t->outq->id]; PacketQueue *q = &trans_q[t->outq->id];
sc_mutex_lock(&q->mutex_q); SCMutexLock(&q->mutex_q);
PacketEnqueue(q, p); PacketEnqueue(q, p);
sc_cond_signal(&q->cond_q); SCCondSignal(&q->cond_q);
sc_mutex_unlock(&q->mutex_q); SCMutexUnlock(&q->mutex_q);
} }

@ -33,7 +33,7 @@ static SCLogFGFilterFile *sc_log_fg_filters[SC_LOG_FILTER_MAX] = { NULL, NULL };
/** /**
* \brief Mutex for accessing the fine-grained fiters sc_log_fg_filters * \brief Mutex for accessing the fine-grained fiters sc_log_fg_filters
*/ */
static sc_mutex_t sc_log_fg_filters_m[SC_LOG_FILTER_MAX] = { PTHREAD_MUTEX_INITIALIZER, static SCMutex sc_log_fg_filters_m[SC_LOG_FILTER_MAX] = { PTHREAD_MUTEX_INITIALIZER,
PTHREAD_MUTEX_INITIALIZER }; PTHREAD_MUTEX_INITIALIZER };
/** /**
@ -44,7 +44,7 @@ static SCLogFDFilter *sc_log_fd_filters = NULL;
/** /**
* \brief Mutex for accessing the function-dependent filters sc_log_fd_filters * \brief Mutex for accessing the function-dependent filters sc_log_fd_filters
*/ */
static sc_mutex_t sc_log_fd_filters_m = PTHREAD_MUTEX_INITIALIZER; static SCMutex sc_log_fd_filters_m = PTHREAD_MUTEX_INITIALIZER;
/** /**
* \brief Holds the thread_list required by function-dependent filters * \brief Holds the thread_list required by function-dependent filters
@ -54,7 +54,7 @@ static SCLogFDFilterThreadList *sc_log_fd_filters_tl = NULL;
/** /**
* \brief Mutex for accessing the FD thread_list sc_log_fd_filters_tl * \brief Mutex for accessing the FD thread_list sc_log_fd_filters_tl
*/ */
static sc_mutex_t sc_log_fd_filters_tl_m = PTHREAD_MUTEX_INITIALIZER; static SCMutex sc_log_fd_filters_tl_m = PTHREAD_MUTEX_INITIALIZER;
/** /**
@ -246,9 +246,9 @@ static inline int SCLogAddFGFilter(const char *file, const char *function,
return -1; return -1;
} }
sc_mutex_t *m = &sc_log_fg_filters_m[listtype]; SCMutex *m = &sc_log_fg_filters_m[listtype];
sc_mutex_lock(m); SCMutexLock(m);
fgf_file = sc_log_fg_filters[listtype]; fgf_file = sc_log_fg_filters[listtype];
@ -315,7 +315,7 @@ static inline int SCLogAddFGFilter(const char *file, const char *function,
} }
done: done:
sc_mutex_unlock(&sc_log_fg_filters_m[listtype]); SCMutexUnlock(&sc_log_fg_filters_m[listtype]);
sc_log_fg_filters_present = 1; sc_log_fg_filters_present = 1;
return 0; return 0;
@ -351,12 +351,12 @@ static int SCLogMatchFGFilter(const char *file, const char *function, int line,
return -1; return -1;
} }
sc_mutex_lock(&sc_log_fg_filters_m[listtype]); SCMutexLock(&sc_log_fg_filters_m[listtype]);
fgf_file = sc_log_fg_filters[listtype]; fgf_file = sc_log_fg_filters[listtype];
if (fgf_file == NULL) { if (fgf_file == NULL) {
sc_mutex_unlock(&sc_log_fg_filters_m[listtype]); SCMutexUnlock(&sc_log_fg_filters_m[listtype]);
return 1; return 1;
} }
@ -400,7 +400,7 @@ static int SCLogMatchFGFilter(const char *file, const char *function, int line,
} }
if (match == 1) { if (match == 1) {
sc_mutex_unlock(&sc_log_fg_filters_m[listtype]); SCMutexUnlock(&sc_log_fg_filters_m[listtype]);
if (listtype == SC_LOG_FILTER_WL) if (listtype == SC_LOG_FILTER_WL)
return 1; return 1;
else else
@ -410,7 +410,7 @@ static int SCLogMatchFGFilter(const char *file, const char *function, int line,
fgf_file = fgf_file->next; fgf_file = fgf_file->next;
} }
sc_mutex_unlock(&sc_log_fg_filters_m[listtype]); SCMutexUnlock(&sc_log_fg_filters_m[listtype]);
if (listtype == SC_LOG_FILTER_WL) if (listtype == SC_LOG_FILTER_WL)
return 0; return 0;
@ -507,7 +507,7 @@ void SCLogReleaseFGFilters(void)
int i = 0; int i = 0;
for (i = 0; i < SC_LOG_FILTER_MAX; i++) { for (i = 0; i < SC_LOG_FILTER_MAX; i++) {
sc_mutex_lock(&sc_log_fg_filters_m[i]); SCMutexLock(&sc_log_fg_filters_m[i]);
fgf_file = sc_log_fg_filters[i]; fgf_file = sc_log_fg_filters[i];
while (fgf_file != NULL) { while (fgf_file != NULL) {
@ -536,7 +536,7 @@ void SCLogReleaseFGFilters(void)
free(temp); free(temp);
} }
sc_mutex_unlock(&sc_log_fg_filters_m[i]); SCMutexUnlock(&sc_log_fg_filters_m[i]);
sc_log_fg_filters[i] = NULL; sc_log_fg_filters[i] = NULL;
} }
@ -568,7 +568,7 @@ int SCLogPrintFGFilters()
#endif #endif
for (i = 0; i < SC_LOG_FILTER_MAX; i++) { for (i = 0; i < SC_LOG_FILTER_MAX; i++) {
sc_mutex_lock(&sc_log_fg_filters_m[i]); SCMutexLock(&sc_log_fg_filters_m[i]);
fgf_file = sc_log_fg_filters[i]; fgf_file = sc_log_fg_filters[i];
while (fgf_file != NULL) { while (fgf_file != NULL) {
@ -594,7 +594,7 @@ int SCLogPrintFGFilters()
fgf_file = fgf_file->next; fgf_file = fgf_file->next;
} }
sc_mutex_unlock(&sc_log_fg_filters_m[i]); SCMutexUnlock(&sc_log_fg_filters_m[i]);
} }
return count; return count;
@ -648,10 +648,10 @@ int SCLogMatchFDFilter(const char *function)
return 0; return 0;
} }
sc_mutex_lock(&sc_log_fd_filters_tl_m); SCMutexLock(&sc_log_fd_filters_tl_m);
if (sc_log_fd_filters_tl == NULL) { if (sc_log_fd_filters_tl == NULL) {
sc_mutex_unlock(&sc_log_fd_filters_tl_m); SCMutexUnlock(&sc_log_fd_filters_tl_m);
if (sc_log_fd_filters != NULL) if (sc_log_fd_filters != NULL)
return 0; return 0;
return 1; return 1;
@ -661,17 +661,17 @@ int SCLogMatchFDFilter(const char *function)
while (thread_list != NULL) { while (thread_list != NULL) {
if (self == thread_list->t) { if (self == thread_list->t) {
if (thread_list->entered > 0) { if (thread_list->entered > 0) {
sc_mutex_unlock(&sc_log_fd_filters_tl_m); SCMutexUnlock(&sc_log_fd_filters_tl_m);
return 1; return 1;
} }
sc_mutex_unlock(&sc_log_fd_filters_tl_m); SCMutexUnlock(&sc_log_fd_filters_tl_m);
return 0; return 0;
} }
thread_list = thread_list->next; thread_list = thread_list->next;
} }
sc_mutex_unlock(&sc_log_fd_filters_tl_m); SCMutexUnlock(&sc_log_fd_filters_tl_m);
return 0; return 0;
} }
@ -701,7 +701,7 @@ int SCLogCheckFDFilterEntry(const char *function)
return 0; return 0;
} }
sc_mutex_lock(&sc_log_fd_filters_m); SCMutexLock(&sc_log_fd_filters_m);
curr = sc_log_fd_filters; curr = sc_log_fd_filters;
@ -713,13 +713,13 @@ int SCLogCheckFDFilterEntry(const char *function)
} }
if (curr == NULL) { if (curr == NULL) {
sc_mutex_unlock(&sc_log_fd_filters_m); SCMutexUnlock(&sc_log_fd_filters_m);
return 1; return 1;
} }
sc_mutex_unlock(&sc_log_fd_filters_m); SCMutexUnlock(&sc_log_fd_filters_m);
sc_mutex_lock(&sc_log_fd_filters_tl_m); SCMutexLock(&sc_log_fd_filters_tl_m);
thread_list = sc_log_fd_filters_tl; thread_list = sc_log_fd_filters_tl;
thread_list_temp = thread_list; thread_list_temp = thread_list;
@ -734,7 +734,7 @@ int SCLogCheckFDFilterEntry(const char *function)
if (thread_list != NULL) { if (thread_list != NULL) {
thread_list->entered++; thread_list->entered++;
sc_mutex_unlock(&sc_log_fd_filters_tl_m); SCMutexUnlock(&sc_log_fd_filters_tl_m);
return 1; return 1;
} }
@ -752,7 +752,7 @@ int SCLogCheckFDFilterEntry(const char *function)
else else
thread_list_prev->next = thread_list_temp; thread_list_prev->next = thread_list_temp;
sc_mutex_unlock(&sc_log_fd_filters_tl_m); SCMutexUnlock(&sc_log_fd_filters_tl_m);
return 1; return 1;
} }
@ -779,7 +779,7 @@ void SCLogCheckFDFilterExit(const char *function)
return; return;
} }
sc_mutex_lock(&sc_log_fd_filters_m); SCMutexLock(&sc_log_fd_filters_m);
curr = sc_log_fd_filters; curr = sc_log_fd_filters;
@ -791,13 +791,13 @@ void SCLogCheckFDFilterExit(const char *function)
} }
if (curr == NULL) { if (curr == NULL) {
sc_mutex_unlock(&sc_log_fd_filters_m); SCMutexUnlock(&sc_log_fd_filters_m);
return; return;
} }
sc_mutex_unlock(&sc_log_fd_filters_m); SCMutexUnlock(&sc_log_fd_filters_m);
sc_mutex_lock(&sc_log_fd_filters_tl_m); SCMutexLock(&sc_log_fd_filters_tl_m);
thread_list = sc_log_fd_filters_tl; thread_list = sc_log_fd_filters_tl;
while (thread_list != NULL) { while (thread_list != NULL) {
@ -807,7 +807,7 @@ void SCLogCheckFDFilterExit(const char *function)
thread_list = thread_list->next; thread_list = thread_list->next;
} }
sc_mutex_unlock(&sc_log_fd_filters_tl_m); SCMutexUnlock(&sc_log_fd_filters_tl_m);
thread_list->entered--; thread_list->entered--;
@ -839,7 +839,7 @@ int SCLogAddFDFilter(const char *function)
return -1; return -1;
} }
sc_mutex_lock(&sc_log_fd_filters_m); SCMutexLock(&sc_log_fd_filters_m);
curr = sc_log_fd_filters; curr = sc_log_fd_filters;
while (curr != NULL) { while (curr != NULL) {
@ -847,7 +847,7 @@ int SCLogAddFDFilter(const char *function)
if (strcmp(function, curr->func) == 0) { if (strcmp(function, curr->func) == 0) {
sc_mutex_unlock(&sc_log_fd_filters_m); SCMutexUnlock(&sc_log_fd_filters_m);
return 0; return 0;
} }
@ -873,7 +873,7 @@ int SCLogAddFDFilter(const char *function)
prev->next = temp; prev->next = temp;
} }
sc_mutex_unlock(&sc_log_fd_filters_m); SCMutexUnlock(&sc_log_fd_filters_m);
sc_log_fd_filters_present = 1; sc_log_fd_filters_present = 1;
return 0; return 0;
@ -887,7 +887,7 @@ void SCLogReleaseFDFilters(void)
SCLogFDFilter *fdf = NULL; SCLogFDFilter *fdf = NULL;
SCLogFDFilter *temp = NULL; SCLogFDFilter *temp = NULL;
sc_mutex_lock(&sc_log_fd_filters_m); SCMutexLock(&sc_log_fd_filters_m);
fdf = sc_log_fd_filters; fdf = sc_log_fd_filters;
while (fdf != NULL) { while (fdf != NULL) {
@ -898,7 +898,7 @@ void SCLogReleaseFDFilters(void)
sc_log_fd_filters = NULL; sc_log_fd_filters = NULL;
sc_mutex_unlock( &sc_log_fd_filters_m ); SCMutexUnlock( &sc_log_fd_filters_m );
return; return;
} }
@ -927,10 +927,10 @@ int SCLogRemoveFDFilter(const char *function)
return -1; return -1;
} }
sc_mutex_lock(&sc_log_fd_filters_m); SCMutexLock(&sc_log_fd_filters_m);
if (sc_log_fd_filters == NULL) { if (sc_log_fd_filters == NULL) {
sc_mutex_unlock(&sc_log_fd_filters_m); SCMutexUnlock(&sc_log_fd_filters_m);
return 0; return 0;
} }
@ -946,7 +946,7 @@ int SCLogRemoveFDFilter(const char *function)
if (curr == NULL) { if (curr == NULL) {
sc_mutex_unlock(&sc_log_fd_filters_m); SCMutexUnlock(&sc_log_fd_filters_m);
return 0; return 0;
} }
@ -958,7 +958,7 @@ int SCLogRemoveFDFilter(const char *function)
SCLogReleaseFDFilter(curr); SCLogReleaseFDFilter(curr);
sc_mutex_unlock(&sc_log_fd_filters_m); SCMutexUnlock(&sc_log_fd_filters_m);
if (sc_log_fd_filters == NULL) if (sc_log_fd_filters == NULL)
sc_log_fd_filters_present = 0; sc_log_fd_filters_present = 0;
@ -987,7 +987,7 @@ int SCLogPrintFDFilters(void)
printf("FD filters:\n"); printf("FD filters:\n");
#endif #endif
r = sc_mutex_lock(&sc_log_fd_filters_m); r = SCMutexLock(&sc_log_fd_filters_m);
fdf = sc_log_fd_filters; fdf = sc_log_fd_filters;
while (fdf != NULL) { while (fdf != NULL) {
@ -998,7 +998,7 @@ int SCLogPrintFDFilters(void)
count++; count++;
} }
r = sc_mutex_unlock(&sc_log_fd_filters_m); r = SCMutexUnlock(&sc_log_fd_filters_m);
return count; return count;
} }

@ -6,7 +6,7 @@
#include "util-debug.h" #include "util-debug.h"
static struct timeval current_time = { 0, 0 }; static struct timeval current_time = { 0, 0 };
static sc_mutex_t current_time_mutex = PTHREAD_MUTEX_INITIALIZER; static SCMutex current_time_mutex = PTHREAD_MUTEX_INITIALIZER;
static char live = TRUE; static char live = TRUE;
void TimeModeSetLive(void) void TimeModeSetLive(void)
@ -29,14 +29,14 @@ void TimeSet(struct timeval *tv)
if (tv == NULL) if (tv == NULL)
return; return;
sc_mutex_lock(&current_time_mutex); SCMutexLock(&current_time_mutex);
current_time.tv_sec = tv->tv_sec; current_time.tv_sec = tv->tv_sec;
current_time.tv_usec = tv->tv_usec; current_time.tv_usec = tv->tv_usec;
SCLogDebug("time set to %" PRIuMAX " sec, %" PRIuMAX " usec", SCLogDebug("time set to %" PRIuMAX " sec, %" PRIuMAX " usec",
(uintmax_t)current_time.tv_sec, (uintmax_t)current_time.tv_usec); (uintmax_t)current_time.tv_sec, (uintmax_t)current_time.tv_usec);
sc_mutex_unlock(&current_time_mutex); SCMutexUnlock(&current_time_mutex);
} }
/** \brief set the time to "gettimeofday" meant for testing */ /** \brief set the time to "gettimeofday" meant for testing */
@ -57,10 +57,10 @@ void TimeGet(struct timeval *tv)
if (live == TRUE) { if (live == TRUE) {
gettimeofday(tv, NULL); gettimeofday(tv, NULL);
} else { } else {
sc_mutex_lock(&current_time_mutex); SCMutexLock(&current_time_mutex);
tv->tv_sec = current_time.tv_sec; tv->tv_sec = current_time.tv_sec;
tv->tv_usec = current_time.tv_usec; tv->tv_usec = current_time.tv_usec;
sc_mutex_unlock(&current_time_mutex); SCMutexUnlock(&current_time_mutex);
} }
SCLogDebug("time we got is %" PRIuMAX " sec, %" PRIuMAX " usec", SCLogDebug("time we got is %" PRIuMAX " sec, %" PRIuMAX " usec",

Loading…
Cancel
Save