-/* $OpenBSD: kern_time.c,v 1.155 2022/05/04 21:24:33 bluhm Exp $ */
+/* $OpenBSD: kern_time.c,v 1.156 2022/05/05 09:45:15 bluhm Exp $ */
/* $NetBSD: kern_time.c,v 1.20 1996/02/18 11:57:06 fvdl Exp $ */
/*
#include <sys/resourcevar.h>
#include <sys/kernel.h>
#include <sys/systm.h>
+#include <sys/mutex.h>
#include <sys/rwlock.h>
#include <sys/proc.h>
#include <sys/ktrace.h>
return (0);
}
+struct mutex ratecheck_mtx = MUTEX_INITIALIZER(IPL_HIGH);
+
/*
* ratecheck(): simple time-based rate-limit checking. see ratecheck(9)
* for usage and rationale.
int
ratecheck(struct timeval *lasttime, const struct timeval *mininterval)
{
- static struct mutex mtx = MUTEX_INITIALIZER(IPL_HIGH);
struct timeval tv, delta;
int rv = 0;
getmicrouptime(&tv);
- mtx_enter(&mtx);
+ mtx_enter(&ratecheck_mtx);
timersub(&tv, lasttime, &delta);
/*
*lasttime = tv;
rv = 1;
}
- mtx_leave(&mtx);
+ mtx_leave(&ratecheck_mtx);
return (rv);
}
+struct mutex ppsratecheck_mtx = MUTEX_INITIALIZER(IPL_HIGH);
+
/*
* ppsratecheck(): packets (or events) per second limitation.
*/
int
ppsratecheck(struct timeval *lasttime, int *curpps, int maxpps)
{
- static struct mutex mtx = MUTEX_INITIALIZER(IPL_HIGH);
struct timeval tv, delta;
int rv;
microuptime(&tv);
- mtx_enter(&mtx);
+ mtx_enter(&ppsratecheck_mtx);
timersub(&tv, lasttime, &delta);
/*
if (*curpps + 1 > *curpps)
*curpps = *curpps + 1;
- mtx_leave(&mtx);
+ mtx_leave(&ppsratecheck_mtx);
return (rv);
}