Skip to content

Commit

Permalink
Improve consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
tuexen committed Aug 14, 2023
1 parent e3d1e8c commit adf4752
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
5 changes: 3 additions & 2 deletions usrsctplib/netinet/sctp_lock_userspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,11 @@ __FBSDID("$FreeBSD$");
#define SCTP_IP_PKTLOG_UNLOCK()
#define SCTP_IP_PKTLOG_DESTROY()

#define SCTP_INP_READ_INIT(_inp)
#define SCTP_INP_READ_DESTROY(_inp)
#define SCTP_INP_READ_LOCK_INIT(_inp)
#define SCTP_INP_READ_LOCK_DESTROY(_inp)
#define SCTP_INP_READ_LOCK(_inp)
#define SCTP_INP_READ_UNLOCK(_inp)
#define SCTP_INP_READ_LOCK_ASSERT(_inp)

#define SCTP_INP_LOCK_INIT(_inp)
#define SCTP_ASOC_CREATE_LOCK_INIT(_inp)
Expand Down
4 changes: 2 additions & 2 deletions usrsctplib/netinet/sctp_pcb.c
Original file line number Diff line number Diff line change
Expand Up @@ -2921,7 +2921,7 @@ sctp_inpcb_alloc(struct socket *so, uint32_t vrf_id)
rw_init_flags(&inp->ip_inp.inp.inp_lock, "sctpinp",
RW_RECURSE | RW_DUPOK);
#endif
SCTP_INP_READ_INIT(inp);
SCTP_INP_READ_LOCK_INIT(inp);
SCTP_ASOC_CREATE_LOCK_INIT(inp);
/* lock the new ep */
SCTP_INP_WLOCK(inp);
Expand Down Expand Up @@ -4280,7 +4280,7 @@ sctp_inpcb_free(struct sctp_inpcb *inp, int immediate, int from)
INP_LOCK_DESTROY(&inp->ip_inp.inp);
#endif
SCTP_INP_LOCK_DESTROY(inp);
SCTP_INP_READ_DESTROY(inp);
SCTP_INP_READ_LOCK_DESTROY(inp);
SCTP_ASOC_CREATE_LOCK_DESTROY(inp);
#if !(defined(__APPLE__) && !defined(__Userspace__))
SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_ep), inp);
Expand Down
16 changes: 10 additions & 6 deletions usrsctplib/netinet/sctp_process_lock.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,11 @@
#define SCTP_ASOC_CREATE_LOCK(_inp)
#define SCTP_ASOC_CREATE_UNLOCK(_inp)

#define SCTP_INP_READ_INIT(_inp)
#define SCTP_INP_READ_DESTROY(_inp)
#define SCTP_INP_READ_LOCK_INIT(_inp)
#define SCTP_INP_READ_LOCK_DESTROY(_inp)
#define SCTP_INP_READ_LOCK(_inp)
#define SCTP_INP_READ_UNLOCK(_inp)
#define SCTP_INP_READ_LOCK_ASSERT(_inp)

/* Lock for TCB */
#define SCTP_TCB_LOCK_INIT(_tcb)
Expand Down Expand Up @@ -180,14 +181,15 @@
* we want to change something at the endpoint level for example random_store
* or cookie secrets we lock the INP level.
*/
#define SCTP_INP_READ_INIT(_inp) \
#define SCTP_INP_READ_LOCK_INIT(_inp) \
InitializeCriticalSection(&(_inp)->inp_rdata_mtx)
#define SCTP_INP_READ_DESTROY(_inp) \
#define SCTP_INP_READ_LOCK_DESTROY(_inp) \
DeleteCriticalSection(&(_inp)->inp_rdata_mtx)
#define SCTP_INP_READ_LOCK(_inp) \
EnterCriticalSection(&(_inp)->inp_rdata_mtx)
#define SCTP_INP_READ_UNLOCK(_inp) \
LeaveCriticalSection(&(_inp)->inp_rdata_mtx)
#define SCTP_INP_READ_LOCK_ASSERT(_inp)

#define SCTP_INP_LOCK_INIT(_inp) \
InitializeCriticalSection(&(_inp)->inp_mtx)
Expand Down Expand Up @@ -335,9 +337,9 @@
* we want to change something at the endpoint level for example random_store
* or cookie secrets we lock the INP level.
*/
#define SCTP_INP_READ_INIT(_inp) \
#define SCTP_INP_READ_LOCK_INIT(_inp) \
(void)pthread_mutex_init(&(_inp)->inp_rdata_mtx, &SCTP_BASE_VAR(mtx_attr))
#define SCTP_INP_READ_DESTROY(_inp) \
#define SCTP_INP_READ_LOCK_DESTROY(_inp) \
(void)pthread_mutex_destroy(&(_inp)->inp_rdata_mtx)
#ifdef INVARIANTS
#define SCTP_INP_READ_LOCK(_inp) \
Expand All @@ -350,6 +352,8 @@
#define SCTP_INP_READ_UNLOCK(_inp) \
(void)pthread_mutex_unlock(&(_inp)->inp_rdata_mtx)
#endif
#define SCTP_INP_READ_LOCK_ASSERT(_inp) \
KASSERT(pthread_mutex_trylock(&(_inp)->inp_rdata_mtx) == EBUSY, ("%s:%d: inp_rdata_mtx not locked", __FILE__, __LINE__))

#define SCTP_INP_LOCK_INIT(_inp) \
(void)pthread_mutex_init(&(_inp)->inp_mtx, &SCTP_BASE_VAR(mtx_attr))
Expand Down

0 comments on commit adf4752

Please sign in to comment.