Skip to content

Commit

Permalink
shared memory: Drop shm_resize()
Browse files Browse the repository at this point in the history
It has the same purpose and uses the same parameters as shm_realloc()...
  • Loading branch information
liviuchircu committed Mar 18, 2019
1 parent bc74237 commit 4a22a7b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 87 deletions.
56 changes: 1 addition & 55 deletions mem/shm_mem.c
Expand Up @@ -2,6 +2,7 @@
* Shared memory functions
*
* Copyright (C) 2001-2003 FhG Fokus
* Copyright (C) 2019 OpenSIPS Solutions
*
* This file is part of opensips, a free SIP server.
*
Expand All @@ -18,13 +19,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* History:
* --------
* 2003-03-12 split shm_mem_init in shm_getmem & shm_mem_init_mallocs
* (andrei)
* 2004-07-27 ANON mmap support, needed on darwin (andrei)
* 2004-09-19 shm_mem_destroy: destroy first the lock & then unmap (andrei)
*/


Expand Down Expand Up @@ -217,54 +211,6 @@ void shm_event_raise(long used, long size, long perc)
}
#endif



inline static void* sh_realloc(void* p, unsigned int size)
{
void *r;

shm_lock();

#ifndef HP_MALLOC
shm_free_unsafe(p);
r = shm_malloc_unsafe(size);
#else
shm_free(p);
r = shm_malloc(size);
#endif

shm_threshold_check();

shm_unlock();

return r;
}

/* look at a buffer if there is perhaps enough space for the new size
if so, we return current buffer again; otherwise, we free it,
allocate a new one and return it; no guarantee for buffer content;
if allocation fails, we return NULL
*/

#ifdef DBG_MALLOC
void* _shm_resize( void* p, unsigned int s, const char* file, const char* func,
int line)
#else
void* _shm_resize( void* p , unsigned int s)
#endif
{
if (p==0) {
LM_DBG("resize(0) called\n");
return shm_malloc( s );
}

return sh_realloc( p, s );
}





int shm_getmem(void)
{

Expand Down
24 changes: 2 additions & 22 deletions mem/shm_mem.h
@@ -1,7 +1,8 @@
/*
* shared mem stuff
* Shared memory functions
*
* Copyright (C) 2001-2003 FhG Fokus
* Copyright (C) 2019 OpenSIPS Solutions
*
* This file is part of opensips, a free SIP server.
*
Expand All @@ -18,12 +19,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* History:
* --------
* 2003-06-29 added shm_realloc & replaced shm_resize (andrei)
* 2003-11-19 reverted shm_resize to the old version, using
* realloc causes terrible fragmentation (andrei)
*/


Expand Down Expand Up @@ -479,14 +474,6 @@ inline static void _shm_free(void *ptr,
extern unsigned long long *shm_hash_usage;
#endif

void* _shm_resize(void* ptr, unsigned int size, const char* f, const char* fn,
int line);
#define shm_resize(_p, _s ) _shm_resize((_p), (_s), \
__FILE__, __FUNCTION__, __LINE__ )
/*#define shm_resize(_p, _s ) shm_realloc( (_p), (_s))*/



#else /*DBG_MALLOC*/

inline static void* shm_malloc_unsafe(unsigned int size)
Expand Down Expand Up @@ -638,15 +625,8 @@ inline static void shm_free(void *_p)
shm_unlock();
}


void* _shm_resize(void* ptr, unsigned int size);
#define shm_resize(_p, _s) _shm_resize( (_p), (_s))
/*#define shm_resize(_p, _s) shm_realloc( (_p), (_s))*/


#endif


inline static void shm_status(void)
{
shm_lock();
Expand Down
16 changes: 8 additions & 8 deletions modules/tm/t_fwd.c
Expand Up @@ -112,9 +112,9 @@ static inline int pre_print_uac_request( struct cell *t, int branch,
/* copy path vector into branch */
if (request->path_vec.len) {
t->uac[branch].path_vec.s =
shm_resize(t->uac[branch].path_vec.s, request->path_vec.len+1);
shm_realloc(t->uac[branch].path_vec.s, request->path_vec.len+1);
if (t->uac[branch].path_vec.s==NULL) {
LM_ERR("shm_resize failed\n");
LM_ERR("shm_realloc failed\n");
goto error;
}
t->uac[branch].path_vec.len = request->path_vec.len;
Expand All @@ -124,10 +124,10 @@ static inline int pre_print_uac_request( struct cell *t, int branch,

/* do the same for the advertised port & address */
if (request->set_global_address.len) {
t->uac[branch].adv_address.s = shm_resize(t->uac[branch].adv_address.s,
t->uac[branch].adv_address.s = shm_realloc(t->uac[branch].adv_address.s,
request->set_global_address.len+1);
if (t->uac[branch].adv_address.s==NULL) {
LM_ERR("shm_resize failed for storing the advertised address "
LM_ERR("shm_realloc failed for storing the advertised address "
"(len=%d)\n",request->set_global_address.len);
goto error;
}
Expand All @@ -136,10 +136,10 @@ static inline int pre_print_uac_request( struct cell *t, int branch,
request->set_global_address.len+1);
}
if (request->set_global_port.len) {
t->uac[branch].adv_port.s = shm_resize(t->uac[branch].adv_port.s,
t->uac[branch].adv_port.s = shm_realloc(t->uac[branch].adv_port.s,
request->set_global_port.len+1);
if (t->uac[branch].adv_port.s==NULL) {
LM_ERR("shm_resize failed for storing the advertised port "
LM_ERR("shm_realloc failed for storing the advertised port "
"(len=%d)\n",request->set_global_port.len);
goto error;
}
Expand Down Expand Up @@ -209,9 +209,9 @@ static inline int pre_print_uac_request( struct cell *t, int branch,
/* copy dst_uri into branch (after branch route possible updated it) */
if (request->dst_uri.len) {
t->uac[branch].duri.s =
shm_resize(t->uac[branch].duri.s, request->dst_uri.len);
shm_realloc(t->uac[branch].duri.s, request->dst_uri.len);
if (t->uac[branch].duri.s==NULL) {
LM_ERR("shm_resize failed\n");
LM_ERR("shm_realloc failed\n");
goto error;
}
t->uac[branch].duri.len = request->dst_uri.len;
Expand Down
4 changes: 2 additions & 2 deletions modules/tm/t_reply.c
Expand Up @@ -369,7 +369,7 @@ static int _reply_light( struct cell *trans, char* buf, unsigned int len,

trans->uas.status = code;
buf_len = rb->buffer.s ? len : len + REPLY_OVERBUFFER_LEN;
rb->buffer.s = (char*)shm_resize( rb->buffer.s, buf_len );
rb->buffer.s = shm_realloc( rb->buffer.s, buf_len );
/* puts the reply's buffer to uas.response */
if (! rb->buffer.s ) {
LM_ERR("failed to allocate shmem buffer\n");
Expand Down Expand Up @@ -1292,7 +1292,7 @@ enum rps relay_reply( struct cell *t, struct sip_msg *p_msg, int branch,
larger messages are likely to follow and we will be
able to reuse the memory frag
*/
uas_rb->buffer.s = (char*)shm_resize( uas_rb->buffer.s, res_len +
uas_rb->buffer.s = shm_realloc( uas_rb->buffer.s, res_len +
(msg_status<200 ? REPLY_OVERBUFFER_LEN : 0));
if (!uas_rb->buffer.s) {
LM_ERR("no more share memory\n");
Expand Down

0 comments on commit 4a22a7b

Please sign in to comment.