-/* $OpenBSD: uipc_usrreq.c,v 1.158 2021/11/17 22:56:19 mvs Exp $ */
+/* $OpenBSD: uipc_usrreq.c,v 1.159 2021/12/07 01:19:47 mvs Exp $ */
/* $NetBSD: uipc_usrreq.c,v 1.18 1996/02/09 19:00:50 christos Exp $ */
/*
fp = rp->fp;
rp++;
- if ((unp = fptounp(fp)) != NULL)
- atomic_dec_long(&unp->unp_msgcount);
+ if ((unp = fptounp(fp)) != NULL) {
+ rw_enter_write(&unp_gc_lock);
+ unp->unp_msgcount--;
+ rw_exit_write(&unp_gc_lock);
+ }
}
mtx_enter(&unp_rights_mtx);
rp->flags = fdp->fd_ofileflags[fd] & UF_PLEDGED;
rp--;
if ((unp = fptounp(fp)) != NULL) {
- atomic_inc_long(&unp->unp_msgcount);
+ rw_enter_write(&unp_gc_lock);
+ unp->unp_msgcount++;
unp->unp_file = fp;
+ rw_exit_write(&unp_gc_lock);
}
}
fdpunlock(fdp);
for ( ; i > 0; i--) {
rp++;
fp = rp->fp;
- if ((unp = fptounp(fp)) != NULL)
- atomic_dec_long(&unp->unp_msgcount);
+ if ((unp = fptounp(fp)) != NULL) {
+ rw_enter_write(&unp_gc_lock);
+ unp->unp_msgcount--;
+ rw_exit_write(&unp_gc_lock);
+ }
FRELE(fp, p);
}
fp = defer->ud_fp[i].fp;
if (fp == NULL)
continue;
- if ((unp = fptounp(fp)) != NULL)
- atomic_dec_long(&unp->unp_msgcount);
+ if ((unp = fptounp(fp)) != NULL) {
+ rw_enter_write(&unp_gc_lock);
+ unp->unp_msgcount--;
+ rw_exit_write(&unp_gc_lock);
+ }
mtx_enter(&unp_rights_mtx);
unp_rights--;
mtx_leave(&unp_rights_mtx);
-/* $OpenBSD: unpcb.h,v 1.20 2021/11/16 08:56:20 mvs Exp $ */
+/* $OpenBSD: unpcb.h,v 1.21 2021/12/07 01:19:47 mvs Exp $ */
/* $NetBSD: unpcb.h,v 1.6 1994/06/29 06:46:08 cgd Exp $ */
/*
* I immutable after creation
* G unp_gc_lock
* U unp_lock
- * a atomic
*/
struct unpcb {
struct socket *unp_socket; /* [I] pointer back to socket */
struct vnode *unp_vnode; /* [U] if associated with file */
- struct file *unp_file; /* [a] backpointer for unp_gc() */
+ struct file *unp_file; /* [G] backpointer for unp_gc() */
struct unpcb *unp_conn; /* [U] control block of connected socket */
ino_t unp_ino; /* [U] fake inode number */
SLIST_HEAD(,unpcb) unp_refs; /* [U] referencing socket linked list */
SLIST_ENTRY(unpcb) unp_nextref; /* [U] link in unp_refs list */
struct mbuf *unp_addr; /* [U] bound address of socket */
- long unp_msgcount; /* [a] references from socket rcv buf */
+ long unp_msgcount; /* [G] references from socket rcv buf */
int unp_flags; /* [U] this unpcb contains peer eids */
int unp_gcflags; /* [G] garbge collector flags */
struct sockpeercred unp_connid;/* [U] id of peer process */