-
Notifications
You must be signed in to change notification settings - Fork 318
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
regressions: add pthread_mutex to spinlock test.
- Loading branch information
Samy Al Bahra
committed
Jan 13, 2025
1 parent
d20bc48
commit bf3b784
Showing
3 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include "../pthread.h" | ||
|
||
#ifdef THROUGHPUT | ||
#include "throughput.h" | ||
#elif defined(LATENCY) | ||
#include "latency.h" | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include <ck_cc.h> | ||
#include <pthread.h> | ||
|
||
CK_CC_INLINE static void | ||
spin_lock(volatile unsigned int *lock) | ||
{ | ||
#ifdef __x86_64__ | ||
__asm__ __volatile__( | ||
"\n1:\t" | ||
"lock ; decl %0\n\t" | ||
"jns 2f\n" | ||
"3:\n" | ||
"rep;nop\n\t" | ||
"cmpl $0,%0\n\t" | ||
"jle 3b\n\t" | ||
"jmp 1b\n" | ||
"2:\t" : "=m" (*lock) : : "memory"); | ||
#else | ||
*lock = 1; | ||
#endif | ||
|
||
return; | ||
} | ||
|
||
CK_CC_INLINE static void | ||
spin_unlock(volatile unsigned int *lock) | ||
{ | ||
#ifdef __x86_64__ | ||
__asm__ __volatile__("movl $1,%0" :"=m" (*lock) :: "memory"); | ||
#else | ||
*lock = 0; | ||
return; | ||
#endif | ||
} | ||
|
||
#define LOCK_NAME "pthread_mutex" | ||
#define LOCK_DEFINE pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER | ||
#define LOCK pthread_mutex_lock(&lock) | ||
#define UNLOCK pthread_mutex_unlock(&lock) | ||
|