2017-09-22 12:27:21 +08:00
|
|
|
#pragma once
|
2018-01-10 17:48:45 +08:00
|
|
|
#include "fiber_cpp_define.hpp"
|
2017-09-22 12:27:21 +08:00
|
|
|
|
|
|
|
struct ACL_FIBER_SEM;
|
|
|
|
|
|
|
|
namespace acl {
|
|
|
|
|
2018-01-10 17:48:45 +08:00
|
|
|
class FIBER_CPP_API fiber_sem
|
2017-09-22 12:27:21 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
fiber_sem(int max);
|
|
|
|
~fiber_sem(void);
|
|
|
|
|
|
|
|
int wait(void);
|
|
|
|
int trywait(void);
|
|
|
|
int post(void);
|
|
|
|
|
|
|
|
private:
|
|
|
|
ACL_FIBER_SEM* sem_;
|
|
|
|
fiber_sem(const fiber_sem&);
|
|
|
|
const fiber_sem& operator=(const fiber_sem&);
|
|
|
|
};
|
|
|
|
|
2018-01-10 17:48:45 +08:00
|
|
|
class FIBER_CPP_API fiber_sem_guard
|
2017-09-22 12:27:21 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
fiber_sem_guard(fiber_sem& sem) : sem_(sem)
|
|
|
|
{
|
|
|
|
(void) sem_.wait();
|
|
|
|
}
|
|
|
|
|
|
|
|
~fiber_sem_guard(void)
|
|
|
|
{
|
|
|
|
sem_.post();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
fiber_sem& sem_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace acl
|