-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge commit 'origin/filestore' into unstable
Conflicts: src/os/FileStore.cc src/os/FileStore.h
- Loading branch information
Showing
25 changed files
with
1,586 additions
and
585 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
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,68 @@ | ||
#ifndef _CEPH_THROTTLE_H | ||
#define _CEPH_THROTTLE_H | ||
|
||
#include "Mutex.h" | ||
#include "Cond.h" | ||
|
||
class Throttle { | ||
__u64 count, want, max; | ||
Mutex lock; | ||
Cond cond; | ||
|
||
public: | ||
Throttle(__u64 m = 0) : count(0), max(m), | ||
lock("Throttle::lock") {} | ||
|
||
private: | ||
void _reset_max(__u64 m) { | ||
if (m) { | ||
if (m < max) | ||
cond.SignalAll(); | ||
max = m; | ||
} | ||
} | ||
bool _wait(__u64 c) { | ||
bool waited = false; | ||
while (max && count + c > max) { | ||
waited = true; | ||
cond.Wait(lock); | ||
} | ||
return waited; | ||
} | ||
|
||
public: | ||
__u64 get_current() { | ||
Mutex::Locker l(lock); | ||
return count; | ||
} | ||
|
||
bool wait(__u64 m = 0) { | ||
Mutex::Locker l(lock); | ||
_reset_max(m); | ||
return _wait(0); | ||
} | ||
|
||
__u64 take(__u64 c = 1) { | ||
Mutex::Locker l(lock); | ||
count += c; | ||
return count; | ||
} | ||
|
||
bool get(__u64 c = 1, __u64 m = 0) { | ||
Mutex::Locker l(lock); | ||
_reset_max(m); | ||
bool waited = _wait(c); | ||
count += c; | ||
return waited; | ||
} | ||
|
||
__u64 put(__u64 c = 1) { | ||
Mutex::Locker l(lock); | ||
cond.SignalAll(); | ||
count -= c; | ||
return count; | ||
} | ||
}; | ||
|
||
|
||
#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
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
Oops, something went wrong.