Skip to content

Commit

Permalink
Pre-allocate one atomic pointer for each loaded module per stream
Browse files Browse the repository at this point in the history
and export that array into the public rtpp_stream interface.
  • Loading branch information
sobomax committed May 12, 2020
1 parent 3b0c2af commit 6e74acc
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/rtpp_pipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ rtpp_pipe_ctor(const struct r_pipe_ctor_args *ap)

rtpp_gen_uid(&pvt->pub.ppuid);
rsca = (struct r_stream_ctor_args){.log = ap->log, .servers_wrt = ap->servers_wrt,
.rtpp_stats = ap->rtpp_stats, .pipe_type = ap->pipe_type, .seuid = ap->seuid};
.rtpp_stats = ap->rtpp_stats, .pipe_type = ap->pipe_type, .seuid = ap->seuid,
.nmodules = ap->nmodules};
for (i = 0; i < 2; i++) {
rsca.side = i;
pvt->pub.stream[i] = rtpp_stream_ctor(&rsca);
Expand Down
2 changes: 1 addition & 1 deletion src/rtpp_pipe.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/*
* Copyright (c) 2004-2006 Maxim Sobolev <sobomax@FreeBSD.org>
* Copyright (c) 2006-2015 Sippy Software, Inc., http://www.sippysoft.com
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -71,6 +70,7 @@ struct r_pipe_ctor_args {
struct rtpp_log *log;
struct rtpp_stats *rtpp_stats;
int pipe_type;
unsigned int nmodules;
};

struct rtpp_pipe *rtpp_pipe_ctor(const struct r_pipe_ctor_args *);
Expand Down
3 changes: 2 additions & 1 deletion src/rtpp_session.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ rtpp_session_ctor(const struct rtpp_cfg *cfs, struct common_cmd_args *ccap,
CALL_METHOD(log, setlevel, cfs->log_level);
pipe_cfg = (struct r_pipe_ctor_args){.seuid = pub->seuid,
.streams_wrt = cfs->rtp_streams_wrt, .servers_wrt = cfs->servers_wrt,
.log = log, .rtpp_stats = cfs->rtpp_stats, .pipe_type = PIPE_RTP};
.log = log, .rtpp_stats = cfs->rtpp_stats, .pipe_type = PIPE_RTP,
.nmodules = cfs->modules_cf->count.total};
pub->rtp = rtpp_pipe_ctor(&pipe_cfg);
if (pub->rtp == NULL) {
goto e2;
Expand Down
12 changes: 11 additions & 1 deletion src/rtpp_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <sys/socket.h>
#include <netinet/in.h>
#include <pthread.h>
#include <stdatomic.h>
#include <stddef.h>
#include <stdlib.h>
#include <stdint.h>
Expand Down Expand Up @@ -109,6 +110,8 @@ struct rtpp_stream_priv
struct rtpp_socket *fd;
/* Remote source address */
struct rtpp_netaddr *rem_addr;
/* Placeholder for per-module structures */
_Atomic(void *) pmod_data[];
};

static void rtpp_stream_dtor(struct rtpp_stream_priv *);
Expand Down Expand Up @@ -171,8 +174,11 @@ struct rtpp_stream *
rtpp_stream_ctor(const struct r_stream_ctor_args *ap)
{
struct rtpp_stream_priv *pvt;
size_t alen;

pvt = rtpp_rzmalloc(sizeof(struct rtpp_stream_priv), PVT_RCOFFS(pvt));
alen = offsetof(struct rtpp_stream_priv, pmod_data) +
(ap->nmodules * sizeof(pvt->pmod_data[0]));
pvt = rtpp_rzmalloc(alen, PVT_RCOFFS(pvt));
if (pvt == NULL) {
goto e0;
}
Expand Down Expand Up @@ -207,6 +213,10 @@ rtpp_stream_ctor(const struct r_stream_ctor_args *ap)

rtpp_gen_uid(&pvt->pub.stuid);
pvt->pub.seuid = ap->seuid;
for (unsigned int i = 0; i < ap->nmodules; i++) {
atomic_init(&(pvt->pmod_data[i]), NULL);
}
pvt->pub.pmod_data = &(pvt->pmod_data[0]);
CALL_SMETHOD(pvt->pub.rcnt, attach, (rtpp_refcnt_dtor_t)&rtpp_stream_dtor,
pvt);
return (&pvt->pub);
Expand Down
4 changes: 2 additions & 2 deletions src/rtpp_stream.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/*
* Copyright (c) 2004-2006 Maxim Sobolev <sobomax@FreeBSD.org>
* Copyright (c) 2006-2015 Sippy Software, Inc., http://www.sippysoft.com
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -139,7 +138,7 @@ struct rtpp_stream {
/* Public methods */
const struct rtpp_stream_smethods *smethods;
/* Placeholder for per-module structures */
_Atomic(void *) pmod_data[0];
_Atomic(void *) *pmod_data;
};

struct r_stream_ctor_args {
Expand All @@ -149,6 +148,7 @@ struct r_stream_ctor_args {
enum rtpp_stream_side side;
int pipe_type;
uint64_t seuid;
unsigned int nmodules;
};

struct rtpp_stream *rtpp_stream_ctor(const struct r_stream_ctor_args *);
Expand Down

0 comments on commit 6e74acc

Please sign in to comment.