mirror of https://github.com/joan2937/pigpio
V66: #133 fixed by simplifying timer loop
This commit is contained in:
parent
5981d495cc
commit
cf29b45ded
36
pigpio.c
36
pigpio.c
|
@ -25,7 +25,7 @@ OTHER DEALINGS IN THE SOFTWARE.
|
||||||
For more information, please refer to <http://unlicense.org/>
|
For more information, please refer to <http://unlicense.org/>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* pigpio version 65 */
|
/* pigpio version 66 */
|
||||||
|
|
||||||
/* include ------------------------------------------------------- */
|
/* include ------------------------------------------------------- */
|
||||||
|
|
||||||
|
@ -981,7 +981,6 @@ typedef struct
|
||||||
unsigned id;
|
unsigned id;
|
||||||
unsigned running;
|
unsigned running;
|
||||||
unsigned millis;
|
unsigned millis;
|
||||||
struct timespec nextTick;
|
|
||||||
pthread_t pthId;
|
pthread_t pthId;
|
||||||
} gpioTimer_t;
|
} gpioTimer_t;
|
||||||
|
|
||||||
|
@ -6750,28 +6749,15 @@ static void *pthScript(void *x)
|
||||||
|
|
||||||
static void * pthTimerTick(void *x)
|
static void * pthTimerTick(void *x)
|
||||||
{
|
{
|
||||||
gpioTimer_t * tp;
|
gpioTimer_t *tp;
|
||||||
struct timespec req, rem, period;
|
struct timespec req, rem;
|
||||||
char buf[256];
|
|
||||||
|
|
||||||
tp = x;
|
tp = x;
|
||||||
|
|
||||||
clock_gettime(CLOCK_REALTIME, &tp->nextTick);
|
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
clock_gettime(CLOCK_REALTIME, &rem);
|
req.tv_sec = tp->millis / THOUSAND;
|
||||||
|
req.tv_nsec = (tp->millis % THOUSAND) * THOUSAND * THOUSAND;
|
||||||
period.tv_sec = tp->millis / THOUSAND;
|
|
||||||
period.tv_nsec = (tp->millis % THOUSAND) * THOUSAND * THOUSAND;
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
|
||||||
TIMER_ADD(&tp->nextTick, &period, &tp->nextTick);
|
|
||||||
|
|
||||||
TIMER_SUB(&tp->nextTick, &rem, &req);
|
|
||||||
}
|
|
||||||
while (req.tv_sec < 0);
|
|
||||||
|
|
||||||
while (nanosleep(&req, &rem))
|
while (nanosleep(&req, &rem))
|
||||||
{
|
{
|
||||||
|
@ -6779,18 +6765,6 @@ static void * pthTimerTick(void *x)
|
||||||
req.tv_nsec = rem.tv_nsec;
|
req.tv_nsec = rem.tv_nsec;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gpioCfg.dbgLevel >= DBG_SLOW_TICK)
|
|
||||||
{
|
|
||||||
if ((tp->millis > 50) || (gpioCfg.dbgLevel >= DBG_FAST_TICK))
|
|
||||||
{
|
|
||||||
sprintf(buf, "pigpio: TIMER=%d @ %u %u\n",
|
|
||||||
tp->id,
|
|
||||||
(unsigned)tp->nextTick.tv_sec,
|
|
||||||
(unsigned)tp->nextTick.tv_nsec);
|
|
||||||
fprintf(stderr, "%s", buf);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tp->ex) (tp->func)(tp->userdata);
|
if (tp->ex) (tp->func)(tp->userdata);
|
||||||
else (tp->func)();
|
else (tp->func)();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue