Add a WRK_BgThread-light for use with fellow_cache_test

parent 44d788bf
......@@ -299,9 +299,11 @@ endif
############################################################
## test programs
standalone_aux = aux_cache_wrk.c
fellow_log_test_ndebug_LDADD = libfellow.la
fellow_log_test_ndebug_CFLAGS = $(AM_CFLAGS) $(DEV_CFLAGS) $(XXHASH_CFLAGS) -DTEST_DRIVER
fellow_log_test_ndebug_SOURCES = fellow_log_test.c
fellow_log_test_ndebug_SOURCES = $(standalone_aux) fellow_log_test.c
fellow_log_test_LDFLAGS = $(fellow_log_test_ndebug_LDFLAGS)
fellow_log_test_LDADD = libfellowwitness.la
......@@ -314,7 +316,7 @@ fellow_cache_test_LDFLAGS = $(fellow_log_test_ndebug_LDFLAGS)
fellow_cache_test_LDADD = libfellowwitness.la
fellow_cache_test_CFLAGS = $(fellow_log_test_ndebug_CFLAGS) \
-DDEBUG -DBUDDY_WITNESS
fellow_cache_test_SOURCES = fellow_cache.c
fellow_cache_test_SOURCES = $(standalone_aux) fellow_cache.c
noinst_PROGRAMS += \
fellow_log_dbg \
......@@ -451,4 +453,4 @@ dist_man_MANS = \
# XXX TODO flexelint fellow_io_*
flint:
flexelint $(VARNISHSRC_CFLAGS) -I .. flint.lnt \
`ls *.c | grep -vE 'fellow_io_aio|fellow_io_threads|fellow_log_test.c|slashmap.c'`
`ls *.c | grep -vE 'fellow_io_aio|fellow_io_threads|fellow_log_test.c|slashmap.c|aux_'`
/*-
* Copyright (c) 2006 Verdens Gang AS
* Copyright (c) 2006-2011 Varnish Software AS
* All rights reserved.
*
* Author: Poul-Henning Kamp <phk@phk.freebsd.dk>
*
* SPDX-License-Identifier: BSD-2-Clause
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*/
#include "config.h"
#include <stdlib.h>
#include <sched.h>
#include "cache/cache_varnishd.h"
/*
* stripped down version of Varnish-Cache WRK_BgThread for
* fellow_cache_test
*/
struct bgthread {
unsigned magic;
#define BGTHREAD_MAGIC 0x23b5152b
const char *name;
bgthread_t *func;
void *priv;
};
static void *
wrk_bgthread(void *arg)
{
struct bgthread *bt;
struct worker wrk;
struct worker_priv wpriv[1];
void *r;
CAST_OBJ_NOTNULL(bt, arg, BGTHREAD_MAGIC);
INIT_OBJ(&wrk, WORKER_MAGIC);
INIT_OBJ(wpriv, WORKER_PRIV_MAGIC);
wrk.wpriv = wpriv;
r = bt->func(&wrk, bt->priv);
return (r);
}
void
WRK_BgThread(pthread_t *thr, const char *name, bgthread_t *func, void *priv)
{
struct bgthread *bt;
ALLOC_OBJ(bt, BGTHREAD_MAGIC);
AN(bt);
bt->name = name;
bt->func = func;
bt->priv = priv;
PTOK(pthread_create(thr, NULL, wrk_bgthread, bt));
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment