Files
mars-nwe/src/core/library/os/delay.c
2026-06-14 11:36:26 +02:00

148 lines
3.3 KiB
C

/****************************************************************************
|
| (C) Copyright 1985, 1991, 1993, 1996 Novell, Inc.
| All Rights Reserved.
|
| This program is free software; you can redistribute it and/or
| modify it under the terms of version 2 of the GNU General Public
| License as published by the Free Software Foundation.
|
| This program is distributed in the hope that it will be useful,
| but WITHOUT ANY WARRANTY; without even the implied warranty of
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
| GNU General Public License for more details.
|
| You should have received a copy of the GNU General Public License
| along with this program; if not, contact Novell, Inc.
|
| To contact Novell about this file by physical or electronic mail,
| you may find current contact information at www.novell.com
|
|***************************************************************************
|
| NetWare Advance File Services (NSS) module
|
|---------------------------------------------------------------------------
|
| $Author: taysom $
| $Date: 2004-12-31 01:10:58 +0530 (Fri, 31 Dec 2004) $
|
| $RCSfile$
| $Revision: 465 $
|
|---------------------------------------------------------------------------
| This module is used to:
| NSS Library source
+-------------------------------------------------------------------------*/
#include <support/lnxmbINC/procdefs.h>
#include <errno.h>
#include <pthread.h>
#include <sched.h>
#include <time.h>
#include <include/pssmpk.h>
#include <include/schedule.h>
#include <include/xError.h>
/**************************************************************************
* Delay the given number of milliseconeds
***************************************************************************/
LONG Delayed = 0;
void LB_delay(
NINT millisec)
{
if (millisec <= 0)
{
sched_yield();
return;
}
Delayed += millisec;
BOOL hadLock = MPKNSS_I_OWN_SPINLOCK();
if (hadLock)
{
MPKNSS_UNLOCK();
}
struct timespec req;
req.tv_sec = millisec / 1000;
req.tv_nsec = (long)(millisec % 1000) * 1000000L;
while (nanosleep(&req, &req) == -1 && errno == EINTR)
{
}
if (hadLock)
{
MPKNSS_LOCK();
}
}
THREAD kCurrentThread(void)
{
return (THREAD)(ADDR)pthread_self();
}
void ZOS_YieldThread(void)
{
sched_yield();
}
void ZOS_Sleep(void)
{
/* The full NSS scheduler wait queues are imported later with FSM.
* Until then, preserve the userspace scheduling surface for non-contended
* internal latch users by yielding cooperatively. */
ZOS_YieldThread();
}
void ZOS_WakeUp(THREAD thread)
{
(void)thread;
}
LONG GetSuperHighResolutionTimer(void)
{
struct timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
return (LONG)(now.tv_sec * 1000000L + now.tv_nsec / 1000L);
}
STATUS ZOS_ScheduleWorkToDo(struct WorkToDoStructure *work)
{
zWork_s *zwork = (zWork_s *)work;
BOOL hadLock = MPKNSS_I_OWN_SPINLOCK();
if (zwork == NULL || zwork->ProcedureToCall == NULL)
{
return zERR_BAD_PARAMETER_VALUE;
}
if (hadLock)
{
MPKNSS_UNLOCK();
}
((void (*)(void *))zwork->ProcedureToCall)(work);
if (hadLock)
{
MPKNSS_LOCK();
}
return zOK;
}
STATUS ZOS_ScheduleFastWorkToDo(struct WorkToDoStructure *work, int priority)
{
(void)priority;
return ZOS_ScheduleWorkToDo(work);
}
STATUS ZOS_CancelWorkToDo(struct WorkToDoStructure *work)
{
(void)work;
return zOK;
}