1
0
mirror of synced 2025-12-13 00:28:26 +08:00

!21 !修复多平台编译问题

Merge pull request !21 from 微希夷/master
This commit is contained in:
yitter
2023-09-13 06:27:25 +00:00
committed by Gitee
4 changed files with 24 additions and 34 deletions

View File

@@ -10,7 +10,7 @@
extern int ncpu;
extern int spin;
void spin_lock(atomic_t* lock, uint32_t pid)
void spin_lock(atomic_t *lock, uint32_t pid)
{
int i, n;
@@ -22,8 +22,8 @@ void spin_lock(atomic_t* lock, uint32_t pid)
InterlockedCompareExchange(lock, pid, 0) == 0
#else
__sync_bool_compare_and_swap(lock, 0, pid)
#endif
)
#endif
)
{
return;
}
@@ -36,11 +36,7 @@ void spin_lock(atomic_t* lock, uint32_t pid)
for (i = 0; i < n; i++)
{
#ifdef WIN32
MemoryBarrier();
#else
__asm("pause");
#endif
atomic_cpu_pause();
}
if (*lock == 0 &&
@@ -48,8 +44,8 @@ void spin_lock(atomic_t* lock, uint32_t pid)
InterlockedCompareExchange(lock, pid, 0) == 0
#else
__sync_bool_compare_and_swap(lock, 0, pid)
#endif
)
#endif
)
{
return;
}
@@ -63,11 +59,11 @@ void spin_lock(atomic_t* lock, uint32_t pid)
}
}
void spin_unlock(atomic_t* lock, uint32_t pid)
void spin_unlock(atomic_t *lock, uint32_t pid)
{
#ifdef WIN32
InterlockedCompareExchange(lock, 0, pid);
#else
__sync_bool_compare_and_swap(lock, pid, 0);
#endif
#endif
}

View File

@@ -8,4 +8,14 @@ extern void spin_lock(atomic_t *lock, uint32_t pid);
extern void spin_unlock(atomic_t *lock, uint32_t pid);
#if defined(WIN32)
#define atomic_cpu_pause() MemoryBarrier();
#elif defined(__x86_64__)
#define atomic_cpu_pause() __asm__ __volatile__("pause")
#elif defined(__aarch64__)
#define atomic_cpu_pause() __asm__ __volatile__("yield")
#else
#define atomic_cpu_pause()
#endif
#endif

View File

@@ -1,16 +1,15 @@
--TEST--
Check for snowdrift serial
Check for snowdrift batch get unique
--SKIPIF--
<?php if (!extension_loaded("snowdrift")) print "skip"; ?>
--FILE--
<?php
$arr = [];
$max = 1024;
for ($i = 0; $i < $max; $i++) {
$arr[$i] = SnowDrift::NextId();
$max = 100000;
foreach (SnowDrift::NextNumId($max) as $id) {
$arr[$id] = '';
}
var_dump(($arr[$max-1] - $arr[0]) == ($max-1));
var_dump(count($arr));
?>
--EXPECT--
bool(true)
int(100000)

View File

@@ -1,15 +0,0 @@
--TEST--
Check for snowdrift batch get unique
--SKIPIF--
<?php if (!extension_loaded("snowdrift")) print "skip"; ?>
--FILE--
<?php
$arr = [];
$max = 100000;
foreach (SnowDrift::NextNumId($max) as $id) {
$arr[$id] = '';
}
var_dump(count($arr));
?>
--EXPECT--
int(100000)