Coverage Report

Created: 2025-07-18 06:32

/src/opensips/lock_alloc.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (C) 2001-2003 FhG Fokus
3
 *
4
 * This file is part of opensips, a free SIP server.
5
 *
6
 * opensips is free software; you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation; either version 2 of the License, or
9
 * (at your option) any later version
10
 *
11
 * opensips is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
19
 *
20
 * History:
21
 * --------
22
 *  2003-03-06  created by andrei (contains parts of the original locking.h)
23
 *  2003-03-17  fixed cast warning in shm_free (forced to void*) (andrei)
24
 *  2004-07-28  s/lock_set_t/gen_lock_set_t/ because of a type conflict
25
 *              on darwin (andrei)
26
 */
27
28
/*!
29
 * \file
30
 * \brief OpenSIPS locking library
31
 * \note WARNING: don't include this directly, use instead locking.h.
32
 */
33
34
35
/*!
36
 * \page OpenSIPS locking library
37
 * Implements simple locks and lock sets.
38
 *
39
 * simple locks:
40
 * - gen_lock_t* lock_alloc();               - allocates a lock in shared mem.
41
 * - void    lock_dealloc(gen_lock_t* lock); - deallocates the lock's shared m.
42
 *
43
 * lock sets: [implemented only for FL & SYSV so far]
44
 * - gen_lock_set_t* lock_set_alloc(no)           - allocs a lock set in shm.
45
 * - void lock_set_dealloc(gen_lock_set_t* s);    - deallocs the lock set shm.
46
 *
47
 * \see locking.h
48
*/
49
50
#ifndef _lock_alloc_h
51
#define _lock_alloc_h
52
53
/*shm_{malloc, free}*/
54
#include "mem/mem.h"
55
#include "mem/shm_mem.h"
56
57
#if defined(FAST_LOCK) || defined(USE_PTHREAD_MUTEX) || defined(USE_POSIX_SEM) || defined(USE_UMUTEX)
58
/* simple locks*/
59
0
#define lock_alloc() shm_malloc(sizeof(gen_lock_t))
60
0
#define lock_dealloc(lock) shm_free((void*)lock)
61
/* lock sets */
62
63
inline static gen_lock_set_t* lock_set_alloc(int n)
64
0
{
65
0
  struct {
66
0
      gen_lock_set_t set;
67
0
      gen_lock_t _locks[0];
68
0
  } *ls;
69
0
70
0
  ls=shm_malloc(sizeof(*ls)+n*sizeof(ls->_locks[0]));
71
0
  if (ls==NULL){
72
0
    LM_CRIT("no more shm memory\n");
73
0
  }else{
74
0
    ls->set.locks=ls->_locks;
75
0
    ls->set.size=n;
76
0
  }
77
0
  return &(ls->set);
78
0
}
Unexecuted instantiation: fuzz_csv_parser.c:lock_set_alloc
Unexecuted instantiation: csv.c:lock_set_alloc
Unexecuted instantiation: dprint.c:lock_set_alloc
Unexecuted instantiation: pt.c:lock_set_alloc
Unexecuted instantiation: ut.c:lock_set_alloc
Unexecuted instantiation: statistics.c:lock_set_alloc
Unexecuted instantiation: route.c:lock_set_alloc
Unexecuted instantiation: ipc.c:lock_set_alloc
Unexecuted instantiation: core_stats.c:lock_set_alloc
Unexecuted instantiation: route_struct.c:lock_set_alloc
Unexecuted instantiation: dset.c:lock_set_alloc
Unexecuted instantiation: pt_load.c:lock_set_alloc
Unexecuted instantiation: sr_module.c:lock_set_alloc
Unexecuted instantiation: action.c:lock_set_alloc
Unexecuted instantiation: db_insertq.c:lock_set_alloc
Unexecuted instantiation: db.c:lock_set_alloc
Unexecuted instantiation: proto_tcp.c:lock_set_alloc
Unexecuted instantiation: proto_udp.c:lock_set_alloc
Unexecuted instantiation: net_tcp_proc.c:lock_set_alloc
Unexecuted instantiation: net_tcp.c:lock_set_alloc
Unexecuted instantiation: tcp_common.c:lock_set_alloc
Unexecuted instantiation: net_udp.c:lock_set_alloc
Unexecuted instantiation: tcp_conn_profile.c:lock_set_alloc
Unexecuted instantiation: trans_trace.c:lock_set_alloc
Unexecuted instantiation: net_tcp_report.c:lock_set_alloc
Unexecuted instantiation: shm_mem.c:lock_set_alloc
Unexecuted instantiation: mi.c:lock_set_alloc
Unexecuted instantiation: item.c:lock_set_alloc
Unexecuted instantiation: msg_parser.c:lock_set_alloc
Unexecuted instantiation: parse_uri.c:lock_set_alloc
Unexecuted instantiation: parse_fline.c:lock_set_alloc
Unexecuted instantiation: parse_hname2.c:lock_set_alloc
Unexecuted instantiation: parse_content.c:lock_set_alloc
Unexecuted instantiation: hf.c:lock_set_alloc
Unexecuted instantiation: parse_to.c:lock_set_alloc
Unexecuted instantiation: parse_via.c:lock_set_alloc
Unexecuted instantiation: event_interface.c:lock_set_alloc
Unexecuted instantiation: receive.c:lock_set_alloc
Unexecuted instantiation: ip_addr.c:lock_set_alloc
Unexecuted instantiation: async.c:lock_set_alloc
Unexecuted instantiation: daemonize.c:lock_set_alloc
Unexecuted instantiation: timer.c:lock_set_alloc
Unexecuted instantiation: trace_api.c:lock_set_alloc
Unexecuted instantiation: mod_fix.c:lock_set_alloc
Unexecuted instantiation: reactor.c:lock_set_alloc
Unexecuted instantiation: strcommon.c:lock_set_alloc
Unexecuted instantiation: forward.c:lock_set_alloc
Unexecuted instantiation: xlog.c:lock_set_alloc
Unexecuted instantiation: blacklists.c:lock_set_alloc
Unexecuted instantiation: usr_avp.c:lock_set_alloc
Unexecuted instantiation: sdp_ops.c:lock_set_alloc
Unexecuted instantiation: resolve.c:lock_set_alloc
Unexecuted instantiation: io_wait.c:lock_set_alloc
Unexecuted instantiation: transformations.c:lock_set_alloc
Unexecuted instantiation: pvar.c:lock_set_alloc
Unexecuted instantiation: sr_module_deps.c:lock_set_alloc
Unexecuted instantiation: cfg_reload.c:lock_set_alloc
Unexecuted instantiation: socket_info.c:lock_set_alloc
Unexecuted instantiation: time_rec.c:lock_set_alloc
Unexecuted instantiation: status_report.c:lock_set_alloc
Unexecuted instantiation: pt_scaling.c:lock_set_alloc
Unexecuted instantiation: signals.c:lock_set_alloc
Unexecuted instantiation: flags.c:lock_set_alloc
Unexecuted instantiation: db_id.c:lock_set_alloc
Unexecuted instantiation: trans.c:lock_set_alloc
Unexecuted instantiation: sdp.c:lock_set_alloc
Unexecuted instantiation: sdp_helpr_funcs.c:lock_set_alloc
Unexecuted instantiation: digest_parser.c:lock_set_alloc
Unexecuted instantiation: param_parser.c:lock_set_alloc
Unexecuted instantiation: parse_contact.c:lock_set_alloc
Unexecuted instantiation: parse_body.c:lock_set_alloc
Unexecuted instantiation: parse_security.c:lock_set_alloc
Unexecuted instantiation: parse_call_info.c:lock_set_alloc
Unexecuted instantiation: parse_event.c:lock_set_alloc
Unexecuted instantiation: parse_disposition.c:lock_set_alloc
Unexecuted instantiation: parse_authenticate.c:lock_set_alloc
Unexecuted instantiation: parser_f.c:lock_set_alloc
Unexecuted instantiation: parse_rpid.c:lock_set_alloc
Unexecuted instantiation: parse_ppi.c:lock_set_alloc
Unexecuted instantiation: parse_fcaps.c:lock_set_alloc
Unexecuted instantiation: parse_rr.c:lock_set_alloc
Unexecuted instantiation: parse_param.c:lock_set_alloc
Unexecuted instantiation: parse_diversion.c:lock_set_alloc
Unexecuted instantiation: parse_nameaddr.c:lock_set_alloc
Unexecuted instantiation: parse_expires.c:lock_set_alloc
Unexecuted instantiation: parse_refer_to.c:lock_set_alloc
Unexecuted instantiation: parse_from.c:lock_set_alloc
Unexecuted instantiation: parse_pai.c:lock_set_alloc
Unexecuted instantiation: evi_transport.c:lock_set_alloc
Unexecuted instantiation: msg_translator.c:lock_set_alloc
Unexecuted instantiation: md5utils.c:lock_set_alloc
Unexecuted instantiation: cfg.tab.c:lock_set_alloc
Unexecuted instantiation: modparam.c:lock_set_alloc
Unexecuted instantiation: crc.c:lock_set_alloc
Unexecuted instantiation: lex.yy.c:lock_set_alloc
Unexecuted instantiation: cfg_pp.c:lock_set_alloc
Unexecuted instantiation: shutdown.c:lock_set_alloc
Unexecuted instantiation: core_cmds.c:lock_set_alloc
Unexecuted instantiation: cachedb.c:lock_set_alloc
Unexecuted instantiation: cachedb_id.c:lock_set_alloc
Unexecuted instantiation: fuzz_uri_parser.c:lock_set_alloc
Unexecuted instantiation: fuzz_core_funcs.c:lock_set_alloc
79
80
#define lock_set_dealloc(lock_set) shm_free((void*)lock_set)
81
82
#elif defined USE_SYSV_SEM
83
84
/*simple locks*/
85
#define lock_alloc() shm_malloc(sizeof(gen_lock_t))
86
#define lock_dealloc(lock) shm_free((void*)lock)
87
/* lock sets */
88
89
inline static gen_lock_set_t* lock_set_alloc(int n)
90
{
91
  gen_lock_set_t* ls;
92
  ls=(gen_lock_set_t*)shm_malloc(sizeof(gen_lock_set_t));
93
  if (ls){
94
    ls->size=n;
95
    ls->semid=-1;
96
  };
97
  return ls;
98
}
99
100
101
#define lock_set_dealloc(lock_set) shm_free((void*)lock_set)
102
103
104
#else
105
#error "no locking method selected"
106
#endif
107
108
109
#endif