Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Mutex refactoring
  • Loading branch information
djphoenix committed May 23, 2019
1 parent 25b35cd commit 1575e16
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 25 deletions.
21 changes: 19 additions & 2 deletions src/kernlib/include/kernlib/mutex.hpp
Expand Up @@ -9,6 +9,23 @@ class Mutex {
bool state;
public:
Mutex(): state(0) {}
void lock();
void release();
inline void lock() {
asm volatile(
"1:"
"testw $1, %0; jnz 1b;"
"lock btsw $0, %0; jc 1b;"
::"m"(state));
}
inline bool try_lock() {
bool ret = 0;
asm volatile(
"lock btsw $0, %1; jc 1f;"
"mov $1, %0;"
"1:"
:"=r"(ret):"m"(state));
return ret;
}
inline void release() {
asm volatile("movw $0, %0"::"m"(state));
}
};
23 changes: 0 additions & 23 deletions src/kernlib/mutex.cpp

This file was deleted.

0 comments on commit 1575e16

Please sign in to comment.