tbf: add llc_queue_size() to check llc_queue is valid before calling size()

gcc6 is optimizing if (!this) {CODE} as this is assumed to never be a
std::nullptr here. Move the null check to the caller. In preparation of
removing the check within llc_queue->size(), all callers must check the object
before calling it. Make sure of that: make the llc_queue() access function
protected and offer only a public llc_queue_size() function that incorporates
the NULL check. All current callers are only interested in the
llc_queue_size().

Tweaked-by: nhofmeyr
Change-Id: I88cc3180f8f86785e3f07981895dabddf50b60a2
This commit is contained in:
Alexander Couzens 2016-08-21 19:38:30 +02:00 committed by lynxis lazus
parent 0a4a6c1200
commit d38b92e972
3 changed files with 15 additions and 6 deletions

View File

@ -189,6 +189,13 @@ const gprs_llc_queue *gprs_rlcmac_tbf::llc_queue() const
return m_ms ? m_ms->llc_queue() : NULL;
}
int gprs_rlcmac_tbf::llc_queue_size() const
{
/* m_ms->llc_queue() never returns NULL: GprsMs::m_llc_queue is a
* member instance. */
return m_ms ? m_ms->llc_queue()->size() : 0;
}
void gprs_rlcmac_tbf::set_ms(GprsMs *ms)
{
if (m_ms == ms)

View File

@ -142,8 +142,7 @@ struct gprs_rlcmac_tbf {
uint8_t ms_class() const;
void set_ms_class(uint8_t);
GprsCodingScheme current_cs() const;
gprs_llc_queue *llc_queue();
const gprs_llc_queue *llc_queue() const;
int llc_queue_size() const;
time_t created_ts() const;
uint8_t dl_slots() const;
@ -231,6 +230,9 @@ protected:
int set_tlli_from_ul(uint32_t new_tlli);
void merge_and_clear_ms(GprsMs *old_ms);
gprs_llc_queue *llc_queue();
const gprs_llc_queue *llc_queue() const;
static const char *tbf_state_name[7];
class GprsMs *m_ms;

View File

@ -310,7 +310,7 @@ drop_frame:
LOGP(DRLCMACDL, LOGL_NOTICE, "%s Discarding LLC PDU "
"because lifetime limit reached, "
"count=%u new_queue_size=%zu\n",
tbf_name(this), frames, llc_queue()->size());
tbf_name(this), frames, llc_queue_size());
if (frames > 0xff)
frames = 0xff;
if (octets > 0xffffff)
@ -572,7 +572,7 @@ int gprs_rlcmac_dl_tbf::create_new_bsn(const uint32_t fn, GprsCodingScheme cs)
m_llc.frame_length(), frames_since_last_drain(fn));
}
is_final = llc_queue()->size() == 0 && !keep_open(fn);
is_final = llc_queue_size() == 0 && !keep_open(fn);
ar = Encoding::rlc_data_to_dl_append(rdbi, cs,
&m_llc, &write_offset, &num_chunks, data, is_final, &payload_written);
@ -1050,7 +1050,7 @@ int gprs_rlcmac_dl_tbf::maybe_start_new_window()
release();
/* check for LLC PDU in the LLC Queue */
if (llc_queue()->size() > 0)
if (llc_queue_size() > 0)
/* we have more data so we will re-use this tbf */
establish_dl_tbf_on_pacch();
@ -1168,7 +1168,7 @@ bool gprs_rlcmac_dl_tbf::need_control_ts() const
bool gprs_rlcmac_dl_tbf::have_data() const
{
return m_llc.chunk_size() > 0 ||
(llc_queue() && llc_queue()->size() > 0);
(llc_queue_size() > 0);
}
int gprs_rlcmac_dl_tbf::frames_since_last_poll(unsigned fn) const