LWP: Avoid casting functions to void pointer

Commit 09aba81c50 (Cast LWP event functions to void pointer) fixed a
compiler warning when building binaries with LWP threaded, but did so in
a way that appeased the compiler but did not address the underlying
undefined behavior.

The ISO C standard states "a pointer to any object type may be converted
to a pointer to void and back again; the result shall compare equal to
the original pointer", but since a function is not defined as an object,
the conversion of function pointer to a void pointer is undefined.

Fix this by creating dummy integer globals to be used as the event ids
for the few places function pointers are used for event ids.  The values
of the dummy variables are set but are never read.

Change-Id: I00084b882fe62cb0a82963ef45c390e5082c6fab
Reviewed-on: https://gerrit.openafs.org/15794
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Mark Vitale <mvitale@sinenomine.net>
Reviewed-by: Cheyenne Wills <cwills@sinenomine.net>
Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>
This commit is contained in:
Michael Meffie 2024-08-01 16:18:48 -04:00
parent ad526abaab
commit c78e2b4c64

View File

@ -118,6 +118,9 @@ pthread_cond_t vol_sleep_cond;
pthread_cond_t vol_init_attach_cond;
pthread_cond_t vol_vinit_cond;
int vol_attach_threads = 1;
#else
int VInitAttachVolumes_event = 1;
int VPutVolume_event = 2;
#endif /* AFS_PTHREAD_ENV */
#ifdef AFS_DEMAND_ATTACH_FS
@ -659,7 +662,7 @@ VInitAttachVolumes(ProgramType pt)
}
VOL_LOCK;
VSetVInit_r(2); /* Initialized, and all volumes have been attached */
LWP_NoYieldSignal((void *)VInitAttachVolumes);
LWP_NoYieldSignal(&VInitAttachVolumes_event);
VOL_UNLOCK;
return 0;
}
@ -1326,7 +1329,7 @@ VShutdown_r(void)
#ifdef AFS_PTHREAD_ENV
VOL_CV_WAIT(&vol_init_attach_cond);
#else
LWP_WaitProcess((void *)VInitAttachVolumes);
LWP_WaitProcess(&VInitAttachVolumes_event);
#endif /* AFS_PTHREAD_ENV */
}
}
@ -4237,7 +4240,7 @@ GetVolume(Error * ec, Error * client_ec, VolumeId volumeId, Volume * hint,
/* LWP has no timed wait, so the caller better not be
* expecting one */
opr_Assert(!timeout);
LWP_WaitProcess((void *)VPutVolume);
LWP_WaitProcess(&VPutVolume_event);
#endif /* AFS_PTHREAD_ENV */
continue;
}
@ -4384,7 +4387,7 @@ VForceOffline_r(Volume * vp, int flags)
#ifdef AFS_PTHREAD_ENV
opr_cv_broadcast(&vol_put_volume_cond);
#else /* AFS_PTHREAD_ENV */
LWP_NoYieldSignal((void *)VPutVolume);
LWP_NoYieldSignal(&VPutVolume_event);
#endif /* AFS_PTHREAD_ENV */
VReleaseVolumeHandles_r(vp);
@ -5070,7 +5073,7 @@ VCheckDetach(Volume * vp)
#if defined(AFS_PTHREAD_ENV)
opr_cv_broadcast(&vol_put_volume_cond);
#else /* AFS_PTHREAD_ENV */
LWP_NoYieldSignal((void *)VPutVolume);
LWP_NoYieldSignal(&VPutVolume_event);
#endif /* AFS_PTHREAD_ENV */
}
}
@ -5170,7 +5173,7 @@ VCheckOffline(Volume * vp)
#ifdef AFS_PTHREAD_ENV
opr_cv_broadcast(&vol_put_volume_cond);
#else /* AFS_PTHREAD_ENV */
LWP_NoYieldSignal((void *)VPutVolume);
LWP_NoYieldSignal(&VPutVolume_event);
#endif /* AFS_PTHREAD_ENV */
}
return ret;