#include "holder.h"
#include "SpinLock.h"
+// Uses _rt_aot_lock_internal_t that has CrstStatic as a field
+// This is initialized at the beginning and EventPipe library requires the lock handle to be maintained by the runtime
ep_rt_lock_handle_t _ep_rt_aot_config_lock_handle;
CrstStatic _ep_rt_aot_config_lock;
return static_cast<size_t>(PalInterlockedCompareExchange64 ((volatile int64_t *)target, (int64_t)value, (int64_t)expected));
#else
return static_cast<size_t>(PalInterlockedCompareExchange ((volatile int32_t *)target, (int32_t)value, (int32_t)expected));
-#endif
+#endif
}
ep_char8_t *
{
STATIC_CONTRACT_NOTHROW;
- spin_lock->lock = new (nothrow) SpinLock ();
+ // EventPipe library expects SpinLocks to be used but NativeAOT will use a lock and change as needed if performance is an issue
+ // Uses _rt_aot_lock_internal_t that has CrstStatic as a field
+ // EventPipe library will intialize using thread, EventPipeBufferManager instances and will maintain these on the EventPipe library side
+
+ spin_lock->lock = new (nothrow) CrstStatic ();
+ spin_lock->lock->InitNoThrow (CrstType::CrstEventPipe);
}
void
VolatileStoreWithoutBarrier<void *> ((void **)ptr, value);
}
+void ep_rt_aot_init (void)
+{
+ extern ep_rt_lock_handle_t _ep_rt_aot_config_lock_handle;
+ extern CrstStatic _ep_rt_aot_config_lock;
+
+ _ep_rt_aot_config_lock_handle.lock = &_ep_rt_aot_config_lock;
+ _ep_rt_aot_config_lock_handle.lock->InitNoThrow (CrstType::CrstEventPipeConfig);
+}
+
+bool ep_rt_aot_lock_acquire (ep_rt_lock_handle_t *lock)
+{
+ if (lock) {
+ lock->lock->Enter();
+ return true;
+ }
+ return false;
+}
+
+bool ep_rt_aot_lock_release (ep_rt_lock_handle_t *lock)
+{
+ if (lock) {
+ lock->lock->Leave();
+ return true;
+ }
+ return false;
+}
+
+bool ep_rt_aot_spin_lock_acquire (ep_rt_spin_lock_handle_t *spin_lock)
+{
+ // In NativeAOT, we use a lock, instead of a SpinLock.
+ // The method signature matches the EventPipe library expectation of a SpinLock
+ if (spin_lock) {
+ spin_lock->lock->Enter();
+ return true;
+ }
+ return false;
+}
+
+bool ep_rt_aot_spin_lock_release (ep_rt_spin_lock_handle_t *spin_lock)
+{
+ // In NativeAOT, we use a lock, instead of a SpinLock.
+ // The method signature matches the EventPipe library expectation of a SpinLock
+ if (spin_lock) {
+ spin_lock->lock->Leave();
+ return true;
+ }
+ return false;
+}
+
+#ifdef EP_CHECKED_BUILD
+
+void ep_rt_aot_lock_requires_lock_held (const ep_rt_lock_handle_t *lock)
+{
+ EP_ASSERT (((ep_rt_lock_handle_t *)lock)->lock->OwnedByCurrentThread ());
+}
+
+void ep_rt_aot_lock_requires_lock_not_held (const ep_rt_lock_handle_t *lock)
+{
+ EP_ASSERT (lock->lock == NULL || !((ep_rt_lock_handle_t *)lock)->lock->OwnedByCurrentThread ());
+}
+
+void ep_rt_aot_spin_lock_requires_lock_held (const ep_rt_spin_lock_handle_t *spin_lock)
+{
+ EP_ASSERT (ep_rt_spin_lock_is_valid (spin_lock));
+ EP_ASSERT (spin_lock->lock->OwnedByCurrentThread ());
+}
+
+void ep_rt_aot_spin_lock_requires_lock_not_held (const ep_rt_spin_lock_handle_t *spin_lock)
+{
+ EP_ASSERT (spin_lock->lock == NULL || !spin_lock->lock->OwnedByCurrentThread ());
+}
+
+#endif /* EP_CHECKED_BUILD */
#endif /* ENABLE_PERFTRACING */
ep_rt_lock_handle_t *
ep_rt_aot_config_lock_get (void)
{
- // shipping criteria: no EVENTPIPE-NATIVEAOT-TODO left in the codebase
- // TODO: Implement EventPipe locking for NativeAOT
- return nullptr;
+ extern ep_rt_lock_handle_t _ep_rt_aot_config_lock_handle;
+ return &_ep_rt_aot_config_lock_handle;
}
static
void
ep_rt_init (void)
{
- // shipping criteria: no EVENTPIPE-NATIVEAOT-TODO left in the codebase
- // TODO: Implement EventPipe locking for NativeAOT
+ extern void ep_rt_aot_init (void);
+ ep_rt_aot_init();
}
static
bool
ep_rt_config_acquire (void)
{
- // shipping criteria: no EVENTPIPE-NATIVEAOT-TODO left in the codebase
- // TODO: Implement EventPipe locking for NativeAOT
- return true;
+ return ep_rt_lock_acquire (ep_rt_aot_config_lock_get ());
}
static
bool
ep_rt_config_release (void)
{
- // shipping criteria: no EVENTPIPE-NATIVEAOT-TODO left in the codebase
- // TODO: Implement EventPipe locking for NativeAOT
- return true;
+ return ep_rt_lock_release (ep_rt_aot_config_lock_get ());
}
#ifdef EP_CHECKED_BUILD
void
ep_rt_config_requires_lock_held (void)
{
- // shipping criteria: no EVENTPIPE-NATIVEAOT-TODO left in the codebase
- // TODO: Implement EventPipe locking for NativeAOT
- return;
+ ep_rt_lock_requires_lock_held (ep_rt_aot_config_lock_get ());
}
static
void
ep_rt_config_requires_lock_not_held (void)
{
- // shipping criteria: no EVENTPIPE-NATIVEAOT-TODO left in the codebase
- // TODO: Implement EventPipe locking for NativeAOT
- return;
+ ep_rt_lock_requires_lock_not_held (ep_rt_aot_config_lock_get ());
}
#endif
ep_rt_lock_acquire (ep_rt_lock_handle_t *lock)
{
STATIC_CONTRACT_NOTHROW;
-
- bool result = true;
- // shipping criteria: no EVENTPIPE-NATIVEAOT-TODO left in the codebase
- // TODO: Implement EventPipe locking for NativeAOT
-
- return result;
+ extern bool ep_rt_aot_lock_acquire (ep_rt_lock_handle_t *lock);
+ return ep_rt_aot_lock_acquire(lock);
}
static
ep_rt_lock_release (ep_rt_lock_handle_t *lock)
{
STATIC_CONTRACT_NOTHROW;
-
- bool result = true;
- // shipping criteria: no EVENTPIPE-NATIVEAOT-TODO left in the codebase
- // TODO: Implement EventPipe locking for NativeAOT
-
- return result;
+ extern bool ep_rt_aot_lock_release (ep_rt_lock_handle_t *lock);
+ return ep_rt_aot_lock_release(lock);
}
#ifdef EP_CHECKED_BUILD
{
STATIC_CONTRACT_NOTHROW;
- //EP_ASSERT (((ep_rt_lock_handle_t *)lock)->lock->OwnedByCurrentThread ());
+ extern void ep_rt_aot_lock_requires_lock_held (const ep_rt_lock_handle_t *lock);
+ ep_rt_aot_lock_requires_lock_held(lock);
}
static
ep_rt_lock_requires_lock_not_held (const ep_rt_lock_handle_t *lock)
{
STATIC_CONTRACT_NOTHROW;
- //EP_ASSERT (lock->lock == NULL || !((ep_rt_lock_handle_t *)lock)->lock->OwnedByCurrentThread ());
+ extern void ep_rt_aot_lock_requires_lock_not_held (const ep_rt_lock_handle_t *lock);
+ ep_rt_aot_lock_requires_lock_not_held(lock);
}
#endif
ep_rt_spin_lock_alloc (ep_rt_spin_lock_handle_t *spin_lock)
{
STATIC_CONTRACT_NOTHROW;
- extern void
- ep_rt_aot_spin_lock_alloc (ep_rt_spin_lock_handle_t *spin_lock);
+ extern void ep_rt_aot_spin_lock_alloc (ep_rt_spin_lock_handle_t *spin_lock);
ep_rt_aot_spin_lock_alloc(spin_lock);
}
ep_rt_spin_lock_free (ep_rt_spin_lock_handle_t *spin_lock)
{
STATIC_CONTRACT_NOTHROW;
- extern void
- ep_rt_aot_spin_lock_free (ep_rt_spin_lock_handle_t *spin_lock);
+ extern void ep_rt_aot_spin_lock_free (ep_rt_spin_lock_handle_t *spin_lock);
ep_rt_aot_spin_lock_free(spin_lock);
}
ep_rt_spin_lock_acquire (ep_rt_spin_lock_handle_t *spin_lock)
{
STATIC_CONTRACT_NOTHROW;
-// EP_ASSERT (ep_rt_spin_lock_is_valid (spin_lock));
-
- // shipping criteria: no EVENTPIPE-NATIVEAOT-TODO left in the codebase
- // TODO: Implement locking (maybe by making the manual Lock and Unlock functions public)
- // SpinLock::Lock (*(spin_lock->lock));
- return true;
+ EP_ASSERT (ep_rt_spin_lock_is_valid (spin_lock));
+ extern bool ep_rt_aot_spin_lock_acquire (ep_rt_spin_lock_handle_t *spin_lock);
+ return ep_rt_aot_spin_lock_acquire(spin_lock);
}
static
{
STATIC_CONTRACT_NOTHROW;
EP_ASSERT (ep_rt_spin_lock_is_valid (spin_lock));
-
- // shipping criteria: no EVENTPIPE-NATIVEAOT-TODO left in the codebase
- // TODO: Implement locking (maybe by making the manual Lock and Unlock functions public)
- // SpinLock::Unlock (*(spin_lock->lock));
- return true;
+ extern bool ep_rt_aot_spin_lock_release (ep_rt_spin_lock_handle_t *spin_lock);
+ return ep_rt_aot_spin_lock_release(spin_lock);
}
#ifdef EP_CHECKED_BUILD
ep_rt_spin_lock_requires_lock_held (const ep_rt_spin_lock_handle_t *spin_lock)
{
STATIC_CONTRACT_NOTHROW;
- EP_ASSERT (ep_rt_spin_lock_is_valid (spin_lock));
-
+ extern void ep_rt_aot_spin_lock_requires_lock_held (const ep_rt_spin_lock_handle_t *spin_lock);
+ ep_rt_aot_spin_lock_requires_lock_held(spin_lock);
}
static
ep_rt_spin_lock_requires_lock_not_held (const ep_rt_spin_lock_handle_t *spin_lock)
{
STATIC_CONTRACT_NOTHROW;
-
+ extern void ep_rt_aot_spin_lock_requires_lock_not_held (const ep_rt_spin_lock_handle_t *spin_lock);
+ ep_rt_aot_spin_lock_requires_lock_not_held(spin_lock);
}
#endif