This repository has been archived by the owner on May 31, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
19 additions
and
11 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
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 |
---|---|---|
@@ -1,7 +1,19 @@ | ||
#pragma once | ||
|
||
typedef volatile int spin_lock_t[2]; | ||
extern void spin_init(spin_lock_t lock); | ||
typedef volatile struct { | ||
volatile int latch[1]; | ||
int owner; | ||
const char * func; | ||
} spin_lock_t; | ||
#define spin_init(lock) do { (lock).owner = 0; (lock).latch[0] = 0; (lock).func = NULL; } while (0) | ||
|
||
#define spin_lock(lock) while (__sync_lock_test_and_set(lock, 0x01)) | ||
#define spin_unlock(lock) __sync_lock_release(lock) | ||
#define DEBUG_LOCKS | ||
#ifdef DEBUG_LOCKS | ||
#define spin_lock(lock) do { while (__sync_lock_test_and_set((lock).latch, 0x01)); (lock).owner = this_core->cpu_id+1; (lock).func = __func__; } while (0) | ||
#define spin_unlock(lock) do { (lock).func = NULL; (lock).owner = -1; __sync_lock_release((lock).latch); } while (0) | ||
#else | ||
#define spin_lock(lock) do { while (__sync_lock_test_and_set((lock).latch, 0x01)); } while(0) | ||
#define spin_unlock(lock) __sync_lock_release((lock).latch); | ||
#endif | ||
|
||
#include <kernel/process.h> |
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