diff options
| author | Eugene Grosbein <eugen@FreeBSD.org> | 2019-10-11 18:05:06 +0000 |
|---|---|---|
| committer | Eugene Grosbein <eugen@FreeBSD.org> | 2019-10-11 18:05:06 +0000 |
| commit | 9772e81551b821669c0593ce093af1cdfceb742a (patch) | |
| tree | 64f093a9d86b882dad130a6338b750670d9c3765 /lib/libnetgraph | |
| parent | 1f69591a1968fe27bb561ddbd63f340c3acb77bb (diff) | |
Notes
Diffstat (limited to 'lib/libnetgraph')
| -rw-r--r-- | lib/libnetgraph/msg.c | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/lib/libnetgraph/msg.c b/lib/libnetgraph/msg.c index c94645997acb..061bdc233ff5 100644 --- a/lib/libnetgraph/msg.c +++ b/lib/libnetgraph/msg.c @@ -44,6 +44,7 @@ __FBSDID("$FreeBSD$"); #include <sys/types.h> #include <sys/socket.h> #include <stdarg.h> +#include <stdatomic.h> #include <netgraph/ng_message.h> #include <netgraph/ng_socket.h> @@ -51,7 +52,7 @@ __FBSDID("$FreeBSD$"); #include "internal.h" /* Next message token value */ -static int gMsgId; +static _Atomic(unsigned int) gMsgId; /* For delivering both messages and replies */ static int NgDeliverMsg(int cs, const char *path, @@ -72,9 +73,7 @@ NgSendMsg(int cs, const char *path, memset(&msg, 0, sizeof(msg)); msg.header.version = NG_VERSION; msg.header.typecookie = cookie; - if (++gMsgId < 0) - gMsgId = 1; - msg.header.token = gMsgId; + msg.header.token = atomic_fetch_add(&gMsgId, 1) & INT_MAX; msg.header.flags = NGF_ORIG; msg.header.cmd = cmd; snprintf((char *)msg.header.cmdstr, NG_CMDSTRSIZ, "cmd%d", cmd); @@ -143,9 +142,7 @@ NgSendAsciiMsg(int cs, const char *path, const char *fmt, ...) /* Now send binary version */ binary = (struct ng_mesg *)reply->data; - if (++gMsgId < 0) - gMsgId = 1; - binary->header.token = gMsgId; + binary->header.token = atomic_fetch_add(&gMsgId, 1) & INT_MAX; binary->header.version = NG_VERSION; if (NgDeliverMsg(cs, path, binary, binary->data, binary->header.arglen) < 0) { |
