-
Notifications
You must be signed in to change notification settings - Fork 607
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The logger is a low-level mechanism that should not depend on sophisticated Rubinius code, but still needs synchronization to produce intelligible results when any thread at any time may log some activity. We switch to a custom spinlock mutex implemented with C++11 features (unfortunate that C++11 didn't think it was essential to provide such a mutex but it's trivial to create). Since the process may log something at any time from any thread, running managed or unmanaged, even while fork'ing, we always reset the state of the lock after fork().
- Loading branch information
Showing
4 changed files
with
53 additions
and
48 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
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,27 @@ | ||
#include <atomic> | ||
|
||
namespace rubinius { | ||
namespace locks { | ||
// Adapted from: Anthony Williams. “C++ Concurrency In Action.” | ||
|
||
class spinlock_mutex { | ||
std::atomic_flag flag; | ||
public: | ||
spinlock_mutex() | ||
: flag() | ||
{ | ||
flag.clear(); | ||
} | ||
|
||
void lock() { | ||
while(flag.test_and_set(std::memory_order_acquire)) { | ||
; // spin | ||
} | ||
} | ||
|
||
void unlock() { | ||
flag.clear(std::memory_order_release); | ||
} | ||
}; | ||
} | ||
} |