1
0
mirror of synced 2025-12-17 18:48:09 +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 ncpu;
extern int spin; extern int spin;
void spin_lock(atomic_t* lock, uint32_t pid) void spin_lock(atomic_t *lock, uint32_t pid)
{ {
int i, n; int i, n;
@@ -36,11 +36,7 @@ void spin_lock(atomic_t* lock, uint32_t pid)
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
{ {
#ifdef WIN32 atomic_cpu_pause();
MemoryBarrier();
#else
__asm("pause");
#endif
} }
if (*lock == 0 && if (*lock == 0 &&
@@ -63,7 +59,7 @@ 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 #ifdef WIN32
InterlockedCompareExchange(lock, 0, pid); InterlockedCompareExchange(lock, 0, pid);

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); 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 #endif

View File

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