Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
trackrdrd
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
uplex-varnish
trackrdrd
Commits
4a234bcc
Commit
4a234bcc
authored
Nov 01, 2012
by
Geoff Simmons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
trackrdrd: added SPMC queue, tested for running with worker threads
parent
2b78681e
Changes
9
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
555 additions
and
4 deletions
+555
-4
configure.ac
trackrdrd/configure.ac
+7
-0
Makefile.am
trackrdrd/src/Makefile.am
+2
-1
data.c
trackrdrd/src/data.c
+0
-1
spmcq.c
trackrdrd/src/spmcq.c
+101
-0
Makefile.am
trackrdrd/src/test/Makefile.am
+12
-2
minunit.h
trackrdrd/src/test/minunit.h
+14
-0
test_spmcq.c
trackrdrd/src/test/test_spmcq.c
+366
-0
test_spmcq_loop.sh
trackrdrd/src/test/test_spmcq_loop.sh
+21
-0
trackrdrd.h
trackrdrd/src/trackrdrd.h
+32
-0
No files found.
trackrdrd/configure.ac
View file @
4a234bcc
...
@@ -20,6 +20,13 @@ fi
...
@@ -20,6 +20,13 @@ fi
AC_PROG_CPP
AC_PROG_CPP
AC_PROG_CXXCPP
AC_PROG_CXXCPP
AX_PTHREAD(,[AC_MSG_ERROR([Could not configure pthreads support])])
LIBS="$PTHREAD_LIBS $LIBS"
CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
CXXFLAGS="$CXXFLAGS $PTHREAD_CFLAGS"
CC="$PTHREAD_CC"
AC_PROG_INSTALL
AC_PROG_INSTALL
AC_PROG_LIBTOOL
AC_PROG_LIBTOOL
AC_PROG_MAKE_SET
AC_PROG_MAKE_SET
...
...
trackrdrd/src/Makefile.am
View file @
4a234bcc
...
@@ -14,7 +14,8 @@ trackrdrd_SOURCES = \
...
@@ -14,7 +14,8 @@ trackrdrd_SOURCES = \
monitor.c
\
monitor.c
\
mq.c
\
mq.c
\
activemq/amq.h
\
activemq/amq.h
\
activemq/amq.cpp
activemq/amq.cpp
\
spmcq.c
trackrdrd_LDADD
=
\
trackrdrd_LDADD
=
\
$(VARNISHSRC)
/lib/libvarnishcompat/libvarnishcompat.la
\
$(VARNISHSRC)
/lib/libvarnishcompat/libvarnishcompat.la
\
...
...
trackrdrd/src/data.c
View file @
4a234bcc
...
@@ -40,7 +40,6 @@
...
@@ -40,7 +40,6 @@
#include "trackrdrd.h"
#include "trackrdrd.h"
#define MIN_TABLE_SCALE 10
#define MIN_DATA_SCALE 10
#define MIN_DATA_SCALE 10
#define INDEX(u) ((u) & (tbl.len - 1))
#define INDEX(u) ((u) & (tbl.len - 1))
...
...
trackrdrd/src/spmcq.c
0 → 100644
View file @
4a234bcc
/*-
* Copyright (c) 2012 UPLEX Nils Goroll Systemoptimierung
* Copyright (c) 2012 Otto Gmbh & Co KG
* All rights reserved
* Use only with permission
*
* Author: Geoffrey Simmons <geoffrey.simmons@uplex.de>
*
* 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 <stdlib.h>
#include <pthread.h>
#include <limits.h>
#include <errno.h>
#include <string.h>
#include "trackrdrd.h"
#include "vas.h"
static
pthread_mutex_t
spmcq_deq_lock
;
static
inline
unsigned
spmcq_len
(
void
)
{
if
(
spmcq
.
tail
<
spmcq
.
head
)
return
UINT_MAX
-
spmcq
.
head
-
1
-
spmcq
.
tail
;
else
return
spmcq
.
tail
-
spmcq
.
head
;
}
static
void
spmcq_cleanup
(
void
)
{
free
(
spmcq
.
data
);
pthread_mutex_destroy
(
&
spmcq_deq_lock
);
}
int
SPMCQ_Init
(
void
)
{
void
*
buf
;
size_t
n
=
1
<<
(
MIN_TABLE_SCALE
+
config
.
maxopen_scale
);
buf
=
calloc
(
n
,
sizeof
(
void
*
));
if
(
buf
==
NULL
)
return
(
errno
);
if
(
pthread_mutex_init
(
&
spmcq_deq_lock
,
NULL
)
!=
0
)
return
(
errno
);
spmcq_t
q
=
{
.
magic
=
SPMCQ_MAGIC
,
.
mask
=
n
-
1
,
.
data
=
buf
,
.
head
=
0
,
.
tail
=
0
};
memcpy
(
&
spmcq
,
&
q
,
sizeof
(
spmcq_t
));
atexit
(
spmcq_cleanup
);
return
(
0
);
}
bool
SPMCQ_Enq
(
void
*
ptr
)
{
if
(
spmcq_len
()
>
spmcq
.
mask
)
return
false
;
spmcq
.
data
[
spmcq
.
tail
++
&
spmcq
.
mask
]
=
ptr
;
return
true
;
}
void
*
SPMCQ_Deq
(
void
)
{
void
*
ptr
;
AZ
(
pthread_mutex_lock
(
&
spmcq_deq_lock
));
if
(
spmcq_len
()
==
0
)
ptr
=
NULL
;
else
ptr
=
spmcq
.
data
[
spmcq
.
head
++
&
spmcq
.
mask
];
AZ
(
pthread_mutex_unlock
(
&
spmcq_deq_lock
));
return
ptr
;
}
trackrdrd/src/test/Makefile.am
View file @
4a234bcc
INCLUDES
=
-I
$(VARNISHSRC)
/include
-I
$(VARNISHSRC)
@AMQ_CFLAGS@
INCLUDES
=
-I
$(VARNISHSRC)
/include
-I
$(VARNISHSRC)
@AMQ_CFLAGS@
TESTS
=
test_parse test_data test_mq regress.sh
TESTS
=
test_parse test_data test_mq
test_spmcq test_spmcq_loop.sh
regress.sh
check_PROGRAMS
=
test_parse test_data test_mq
check_PROGRAMS
=
test_parse test_data test_mq
test_spmcq
test_parse_SOURCES
=
\
test_parse_SOURCES
=
\
minunit.h
\
minunit.h
\
...
@@ -31,3 +31,13 @@ test_mq_LDADD = \
...
@@ -31,3 +31,13 @@ test_mq_LDADD = \
../mq.
$(OBJEXT)
\
../mq.
$(OBJEXT)
\
../amq.
$(OBJEXT)
\
../amq.
$(OBJEXT)
\
@AMQ_LIBS@
@AMQ_LIBS@
test_spmcq_SOURCES
=
\
minunit.h
\
test_spmcq.c
\
../trackrdrd.h
test_spmcq_LDADD
=
\
$(VARNISHSRC)
/lib/libvarnish/libvarnish.la
\
../spmcq.
$(OBJEXT)
trackrdrd/src/test/minunit.h
View file @
4a234bcc
...
@@ -44,6 +44,20 @@
...
@@ -44,6 +44,20 @@
#define mu_assert(msg, test) do { if (!(test)) return msg; } while (0)
#define mu_assert(msg, test) do { if (!(test)) return msg; } while (0)
#define mu_run_test(test) do { const char *msg = test(); tests_run++; \
#define mu_run_test(test) do { const char *msg = test(); tests_run++; \
if (msg) return msg; } while (0)
if (msg) return msg; } while (0)
/* phk-ish mu_assert */
#define mu_assert_errno(c) \
do { \
if (!(c)) { \
sprintf(errmsg, "%s failed in %s at %s:%d: errno %d (%s)", \
#c, __func__, __FILE__, __LINE__, errno, strerror(errno)); \
mu_assert(errmsg, 0); \
} \
} while(0)
/* short for MU Assert Zero / Non-Zero */
#define MAZ(c) do { mu_assert_errno((c) == 0); } while(0)
#define MAN(c) do { mu_assert_errno((c) != 0); } while(0)
extern
int
tests_run
;
extern
int
tests_run
;
#define TEST_RUNNER \
#define TEST_RUNNER \
...
...
trackrdrd/src/test/test_spmcq.c
0 → 100644
View file @
4a234bcc
This diff is collapsed.
Click to expand it.
trackrdrd/src/test/test_spmcq_loop.sh
0 → 100755
View file @
4a234bcc
#! /bin/bash
N
=
1000
echo
echo
"TEST:
$0
"
echo
"... running test_spmcq
$N
times"
I
=
1
while
[[
$I
-le
$N
]]
do
# echo -en "Test $N\r"
./test_spmcq
>
/dev/null
if
[
$?
-ne
0
]
;
then
echo
"Test
$I
FAILED"
exit
1
fi
((
I++
))
done
exit
0
\ No newline at end of file
trackrdrd/src/trackrdrd.h
View file @
4a234bcc
...
@@ -30,6 +30,38 @@
...
@@ -30,6 +30,38 @@
*/
*/
#include <stdio.h>
#include <stdio.h>
#include <stdbool.h>
#include <pthread.h>
#define MIN_TABLE_SCALE 10
/* spmcq.c */
/* Single producer multiple consumer bounded FIFO queue */
typedef
struct
{
unsigned
magic
;
#define SPMCQ_MAGIC 0xe9a5d0a8
const
unsigned
mask
;
void
**
data
;
volatile
unsigned
head
;
volatile
unsigned
tail
;
}
spmcq_t
;
spmcq_t
spmcq
;
int
SPMCQ_Init
(
void
);
bool
SPMCQ_Enq
(
void
*
ptr
);
void
*
SPMCQ_Deq
(
void
);
/* Producer waits for this condition when the spmc queue is full.
Consumers signal this condition after dequeue. */
pthread_cond_t
spmcq_nonfull_cond
;
pthread_mutex_t
spmcq_nonfull_lock
;
/* Consumers wait for this condition when the spmc queue is empty.
Producer signals this condition after enqueue. */
pthread_cond_t
spmcq_nonempty_cond
;
pthread_mutex_t
spmcq_nonempty_lock
;
/* mq.c */
/* mq.c */
const
char
*
MQ_GlobalInit
(
void
);
const
char
*
MQ_GlobalInit
(
void
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment