Style cleanups, use M_ZERO instead of bzero, unify the !semaphore and

semaphore return paths.
This commit is contained in:
Nate Lawson 2004-04-14 03:43:06 +00:00
parent e6f06f99f6
commit e4a5123464

View File

@ -45,7 +45,7 @@
#define _COMPONENT ACPI_OS_SERVICES #define _COMPONENT ACPI_OS_SERVICES
ACPI_MODULE_NAME("SYNCH") ACPI_MODULE_NAME("SYNCH")
static MALLOC_DEFINE(M_ACPISEM, "acpisem", "ACPI semaphore"); MALLOC_DEFINE(M_ACPISEM, "acpisem", "ACPI semaphore");
#if __FreeBSD_version < 500000 #if __FreeBSD_version < 500000
# define AS_LOCK(as) s = splhigh() # define AS_LOCK(as) s = splhigh()
@ -59,7 +59,7 @@ static MALLOC_DEFINE(M_ACPISEM, "acpisem", "ACPI semaphore");
#endif #endif
/* /*
* Simple counting semaphore implemented using a mutex. (Subsequently used * Simple counting semaphore implemented using a mutex. (Subsequently used
* in the OSI code to implement a mutex. Go figure.) * in the OSI code to implement a mutex. Go figure.)
*/ */
struct acpi_semaphore { struct acpi_semaphore {
@ -82,10 +82,11 @@ TUNABLE_INT("debug.acpi_semaphore_debug", &acpi_semaphore_debug);
SYSCTL_DECL(_debug_acpi); SYSCTL_DECL(_debug_acpi);
SYSCTL_INT(_debug_acpi, OID_AUTO, semaphore_debug, CTLFLAG_RW, SYSCTL_INT(_debug_acpi, OID_AUTO, semaphore_debug, CTLFLAG_RW,
&acpi_semaphore_debug, 0, "Enable ACPI semaphore debug messages"); &acpi_semaphore_debug, 0, "Enable ACPI semaphore debug messages");
#endif #endif /* !ACPI_NO_SEMAPHORES */
ACPI_STATUS ACPI_STATUS
AcpiOsCreateSemaphore(UINT32 MaxUnits, UINT32 InitialUnits, ACPI_HANDLE *OutHandle) AcpiOsCreateSemaphore(UINT32 MaxUnits, UINT32 InitialUnits,
ACPI_HANDLE *OutHandle)
{ {
#ifndef ACPI_NO_SEMAPHORES #ifndef ACPI_NO_SEMAPHORES
struct acpi_semaphore *as; struct acpi_semaphore *as;
@ -93,14 +94,13 @@ AcpiOsCreateSemaphore(UINT32 MaxUnits, UINT32 InitialUnits, ACPI_HANDLE *OutHand
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
if (OutHandle == NULL) if (OutHandle == NULL)
return(AE_BAD_PARAMETER); return_ACPI_STATUS (AE_BAD_PARAMETER);
if (InitialUnits > MaxUnits) if (InitialUnits > MaxUnits)
return_ACPI_STATUS(AE_BAD_PARAMETER); return_ACPI_STATUS (AE_BAD_PARAMETER);
if ((as = malloc(sizeof(*as), M_ACPISEM, M_NOWAIT)) == NULL) if ((as = malloc(sizeof(*as), M_ACPISEM, M_NOWAIT | M_ZERO)) == NULL)
return_ACPI_STATUS(AE_NO_MEMORY); return_ACPI_STATUS (AE_NO_MEMORY);
bzero(as, sizeof(*as));
#if __FreeBSD_version >= 500000 #if __FreeBSD_version >= 500000
mtx_init(&as->as_mtx, "ACPI semaphore", NULL, MTX_DEF); mtx_init(&as->as_mtx, "ACPI semaphore", NULL, MTX_DEF);
#endif #endif
@ -113,15 +113,15 @@ AcpiOsCreateSemaphore(UINT32 MaxUnits, UINT32 InitialUnits, ACPI_HANDLE *OutHand
as, InitialUnits, MaxUnits)); as, InitialUnits, MaxUnits));
*OutHandle = (ACPI_HANDLE)as; *OutHandle = (ACPI_HANDLE)as;
return_ACPI_STATUS(AE_OK);
#else #else
*OutHandle = (ACPI_HANDLE)OutHandle; *OutHandle = (ACPI_HANDLE)OutHandle;
return(AE_OK); #endif /* !ACPI_NO_SEMAPHORES */
#endif
return_ACPI_STATUS (AE_OK);
} }
ACPI_STATUS ACPI_STATUS
AcpiOsDeleteSemaphore (ACPI_HANDLE Handle) AcpiOsDeleteSemaphore(ACPI_HANDLE Handle)
{ {
#ifndef ACPI_NO_SEMAPHORES #ifndef ACPI_NO_SEMAPHORES
struct acpi_semaphore *as = (struct acpi_semaphore *)Handle; struct acpi_semaphore *as = (struct acpi_semaphore *)Handle;
@ -133,10 +133,9 @@ AcpiOsDeleteSemaphore (ACPI_HANDLE Handle)
mtx_destroy(&as->as_mtx); mtx_destroy(&as->as_mtx);
#endif #endif
free(Handle, M_ACPISEM); free(Handle, M_ACPISEM);
return_ACPI_STATUS(AE_OK); #endif /* !ACPI_NO_SEMAPHORES */
#else
return(AE_OK); return_ACPI_STATUS (AE_OK);
#endif
} }
/* /*
@ -148,8 +147,8 @@ ACPI_STATUS
AcpiOsWaitSemaphore(ACPI_HANDLE Handle, UINT32 Units, UINT16 Timeout) AcpiOsWaitSemaphore(ACPI_HANDLE Handle, UINT32 Units, UINT16 Timeout)
{ {
#ifndef ACPI_NO_SEMAPHORES #ifndef ACPI_NO_SEMAPHORES
struct acpi_semaphore *as = (struct acpi_semaphore *)Handle;
ACPI_STATUS result; ACPI_STATUS result;
struct acpi_semaphore *as = (struct acpi_semaphore *)Handle;
int rv, tmo; int rv, tmo;
struct timeval timeouttv, currenttv, timelefttv; struct timeval timeouttv, currenttv, timelefttv;
AS_LOCK_DECL; AS_LOCK_DECL;
@ -157,10 +156,10 @@ AcpiOsWaitSemaphore(ACPI_HANDLE Handle, UINT32 Units, UINT16 Timeout)
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
if (as == NULL) if (as == NULL)
return_ACPI_STATUS(AE_BAD_PARAMETER); return_ACPI_STATUS (AE_BAD_PARAMETER);
if (cold) if (cold)
return_ACPI_STATUS(AE_OK); return_ACPI_STATUS (AE_OK);
#if 0 #if 0
if (as->as_units < Units && as->as_timeouts > 10) { if (as->as_units < Units && as->as_timeouts > 10) {
@ -172,12 +171,11 @@ AcpiOsWaitSemaphore(ACPI_HANDLE Handle, UINT32 Units, UINT16 Timeout)
as->as_timeouts = 0; as->as_timeouts = 0;
wakeup(as); wakeup(as);
AS_UNLOCK(as); AS_UNLOCK(as);
return_ACPI_STATUS(AE_TIME); return_ACPI_STATUS (AE_TIME);
} }
if (as->as_resetting) { if (as->as_resetting)
return_ACPI_STATUS(AE_TIME); return_ACPI_STATUS (AE_TIME);
}
#endif #endif
/* a timeout of ACPI_WAIT_FOREVER means "forever" */ /* a timeout of ACPI_WAIT_FOREVER means "forever" */
@ -264,19 +262,22 @@ AcpiOsWaitSemaphore(ACPI_HANDLE Handle, UINT32 Units, UINT16 Timeout)
getmicrotime(&currenttv); getmicrotime(&currenttv);
timevalsub(&timelefttv, &currenttv); timevalsub(&timelefttv, &currenttv);
if (timelefttv.tv_sec < 0) { if (timelefttv.tv_sec < 0) {
ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "await semaphore %p timeout\n", as)); ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "await semaphore %p timeout\n",
as));
result = AE_TIME; result = AE_TIME;
break; break;
} }
/* adjust timeout for the next sleep */ /* adjust timeout for the next sleep */
tmo = (timelefttv.tv_sec * 1000000 + timelefttv.tv_usec) / (1000000 / hz); tmo = (timelefttv.tv_sec * 1000000 + timelefttv.tv_usec) /
(1000000 / hz);
if (tmo <= 0) if (tmo <= 0)
tmo = 1; tmo = 1;
if (acpi_semaphore_debug) { if (acpi_semaphore_debug) {
printf("%s: Wakeup timeleft(%lu, %lu), tmo %u, semaphore %p, thread %d\n", printf("%s: Wakeup timeleft(%lu, %lu), tmo %u, sem %p, thread %d\n",
__func__, timelefttv.tv_sec, timelefttv.tv_usec, tmo, as, AcpiOsGetThreadId()); __func__, timelefttv.tv_sec, timelefttv.tv_usec, tmo, as,
AcpiOsGetThreadId());
} }
} }
@ -286,23 +287,22 @@ AcpiOsWaitSemaphore(ACPI_HANDLE Handle, UINT32 Units, UINT16 Timeout)
__func__, Timeout, as->as_pendings, as); __func__, Timeout, as->as_pendings, as);
} }
if (result == AE_OK && (as->as_timeouts > 0 || as->as_pendings > 0)) { if (result == AE_OK && (as->as_timeouts > 0 || as->as_pendings > 0)) {
printf("%s: Acquire %d, units %d, pending %d, semaphore %p, thread %d\n", printf("%s: Acquire %d, units %d, pending %d, sem %p, thread %d\n",
__func__, Units, as->as_units, as->as_pendings, as, AcpiOsGetThreadId()); __func__, Units, as->as_units, as->as_pendings, as,
AcpiOsGetThreadId());
} }
} }
if (result == AE_TIME) { if (result == AE_TIME)
as->as_timeouts++; as->as_timeouts++;
} else { else
as->as_timeouts = 0; as->as_timeouts = 0;
}
AS_UNLOCK(as); AS_UNLOCK(as);
return_ACPI_STATUS (result);
return_ACPI_STATUS(result);
#else #else
return(AE_OK); return_ACPI_STATUS (AE_OK);
#endif #endif /* !ACPI_NO_SEMAPHORES */
} }
ACPI_STATUS ACPI_STATUS
@ -334,10 +334,9 @@ AcpiOsSignalSemaphore(ACPI_HANDLE Handle, UINT32 Units)
wakeup(as); wakeup(as);
AS_UNLOCK(as); AS_UNLOCK(as);
return_ACPI_STATUS(AE_OK); #endif /* !ACPI_NO_SEMAPHORES */
#else
return(AE_OK); return_ACPI_STATUS (AE_OK);
#endif
} }
ACPI_STATUS ACPI_STATUS
@ -347,7 +346,7 @@ AcpiOsCreateLock (ACPI_HANDLE *OutHandle)
if (OutHandle == NULL) if (OutHandle == NULL)
return (AE_BAD_PARAMETER); return (AE_BAD_PARAMETER);
MALLOC(m, struct mtx *, sizeof(*m), M_ACPISEM, M_NOWAIT | M_ZERO); m = malloc(sizeof(*m), M_ACPISEM, M_NOWAIT | M_ZERO);
if (m == NULL) if (m == NULL)
return (AE_NO_MEMORY); return (AE_NO_MEMORY);
@ -377,7 +376,7 @@ AcpiOsAcquireLock (ACPI_HANDLE Handle, UINT32 Flags)
struct mtx *m = (struct mtx *)Handle; struct mtx *m = (struct mtx *)Handle;
if (Handle == NULL) if (Handle == NULL)
return; return;
mtx_lock(m); mtx_lock(m);
} }
@ -387,6 +386,6 @@ AcpiOsReleaseLock (ACPI_HANDLE Handle, UINT32 Flags)
struct mtx *m = (struct mtx *)Handle; struct mtx *m = (struct mtx *)Handle;
if (Handle == NULL) if (Handle == NULL)
return; return;
mtx_unlock(m); mtx_unlock(m);
} }