本文整理汇总了C++中std::condition_variable类的典型用法代码示例。如果您正苦于以下问题:C++ condition_variable类的具体用法?C++ condition_variable怎么用?C++ condition_variable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了condition_variable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: switch
namespace kernel
{
static std::thread
sIpcThread;
static std::atomic_bool
sIpcThreadRunning;
static std::mutex
sIpcMutex;
static std::condition_variable
sIpcCond;
static std::queue<IPCBuffer *>
sIpcRequests;
static std::queue<IPCBuffer *>
sIpcResponses[3];
static void
ipcThreadEntry();
/**
* Start the IPC thread.
*/
void
ipcStart()
{
std::unique_lock<std::mutex> lock { sIpcMutex };
sIpcThreadRunning.store(true);
sIpcThread = std::thread { ipcThreadEntry };
}
/**
* Stop the IPC thread.
*/
void
ipcShutdown()
{
std::unique_lock<std::mutex> lock { sIpcMutex };
if (sIpcThreadRunning.exchange(false)) {
sIpcCond.notify_all();
lock.unlock();
sIpcThread.join();
}
}
/**
* Submit an buffer to the IPC queue.
*/
void
ipcDriverKernelSubmitRequest(IPCBuffer *buffer)
{
switch (cpu::this_core::id()) {
case 0:
buffer->cpuId = IOSCpuId::PPC0;
break;
case 1:
buffer->cpuId = IOSCpuId::PPC1;
break;
case 2:
buffer->cpuId = IOSCpuId::PPC2;
break;
default:
decaf_abort("Unexpected core id");
}
sIpcMutex.lock();
sIpcRequests.push(buffer);
sIpcCond.notify_all();
sIpcMutex.unlock();
}
/**
* Handle PPC interrupt for when we have IPC responses to dispatch.
*/
void
ipcDriverKernelHandleInterrupt()
{
auto driver = coreinit::internal::getIPCDriver();
auto &responses = sIpcResponses[driver->coreId];
// Copy respones to IPCDriver structure
sIpcMutex.lock();
while (responses.size()) {
driver->responses[driver->numResponses] = responses.front();
driver->numResponses++;
responses.pop();
}
sIpcMutex.unlock();
//.........这里部分代码省略.........
示例2: s_currentNativeWindowId
namespace glws {
static char TAG[]="apitrace";
static JavaVM *s_javaVM = nullptr;
static jobject s_activityObject = nullptr;
static std::mutex s_activityObjectMutex;
static jmethodID s_setSurfaceSizeMethodID = nullptr;
static jfieldID s_descriptor = nullptr;
typedef std::shared_ptr<ANativeWindow> AndroidWindow;
static AndroidWindow s_currentNativeWindow;
static std::atomic_int s_currentNativeWindowId(0);
static std::mutex s_currentNativeWindowMutex;
static int s_stdout_fd = -1;
static int s_stderr_fd = -1;
static std::mutex s_stateMutex;
static std::condition_variable s_stateWait;
static EGLDisplay eglDisplay = EGL_NO_DISPLAY;
static char const *eglExtensions = NULL;
static bool has_EGL_KHR_create_context = false;
struct ResourceTracker;
static std::mutex s_resourcesMutex;
static std::vector<ResourceTracker*> s_resources;
class FdWriter : public std::streambuf
{
public:
FdWriter(int fd)
{
m_fd = fd;
int opts = fcntl(m_fd, F_GETFL);
opts = opts & (~O_NONBLOCK);
fcntl(m_fd, F_SETFL, opts);
}
// basic_streambuf interface
protected:
std::streamsize xsputn(const char_type *__s, std::streamsize __n)
{
std::streamsize ret = 0;
while( __n ) {
ssize_t written = write(m_fd, __s, __n);
if (written > 0) {
__n -= written;
__s += written;
ret += written;
} else {
switch (errno) {
case EBADF:
case EINVAL:
case EPIPE:
std::exit(1);
break;
}
}
}
return ret;
}
int_type overflow(int_type __c)
{
return xsputn(reinterpret_cast<const char_type *>(&__c), 1) == 1 ? __c : traits_type::eof();
}
private:
int m_fd = -1;
};
static EGLenum
translateAPI(glfeatures::Profile profile)
{
switch (profile.api) {
case glfeatures::API_GL:
return EGL_OPENGL_API;
case glfeatures::API_GLES:
return EGL_OPENGL_ES_API;
default:
assert(0);
return EGL_NONE;
}
}
/* Must be called before
*
* - eglCreateContext
* - eglGetCurrentContext
* - eglGetCurrentDisplay
* - eglGetCurrentSurface
* - eglMakeCurrent (when its ctx parameter is EGL_NO_CONTEXT ),
* - eglWaitClient
* - eglWaitNative
*/
static void
bindAPI(EGLenum api)
//.........这里部分代码省略.........
示例3: ErrMsg
//.........这里部分代码省略.........
str_errs += "нет включения М2\n";
if (errs.fault_m3)
str_errs += "нет включения М3\n";
if (errs.fault_m4)
str_errs += "нет включения М4\n";
if (errs.fault_m5)
str_errs += "нет включения М5\n";
if (errs.fault_m6)
str_errs += "нет включения М6\n";
if (errs.fault_m8)
str_errs += "нет включения М8\n";
if (errs.fault_m10)
str_errs += "нет включения М10\n";
if (errs.fault_m12)
str_errs += "нет включения М12\n";
if (errs.fault_phasing)
str_errs += "не правильная фазировка\n";
if (errs.p_no)
str_errs += "давление в системе не установилось\n";
if (errs.p_upr_no)
str_errs += "давление в канале Х не установилось\n";
if (errs.q_no)
str_errs += "расход не установился\n";
if (errs.v_no)
str_errs += "Напряжение не в допуске\n";
if (errs.fault_p_op12)
str_errs += "Аварийное давление\n";
if (errs.fault_p_op22)
str_errs += "Аварийное давление\n";
return str_errs;
}
std::condition_variable CondVar;
TestCommonData::TestCommonData( TestCase* test_case, QString const& name, uint8_t number, uint8_t id ):
test::Test( test_case, name, number, id ),
OilTemp(0),
mCommand( cpu::CpuMemory::Instance().DB31 )
{}
QJsonObject TestCommonData::Serialise() const
{
QJsonObject obj;
obj.insert("OilTemp", OilTemp );
obj.insert("TestingTime", TestingTime );
return obj;
}
bool TestCommonData::Deserialize( QJsonObject const& obj )
{
OilTemp = obj.value("OilTemp").toDouble();
TestingTime = obj.value("TestingTime").toInt();
return true;
}
uint8_t TestCommonData::CommandID()
{
return mId;
}
void TestCommonData::Start()
{
mCommand.N_Operation = CommandID();
mCommand.Start_Oper = true;
mCommand.Stop_Oper = false;
mCommand.Nasos_M2 = app::Settings::Instance().MainPupm() == "M2";
示例4: close
void close() noexcept {
std::unique_lock< std::mutex > lk{ mtx_ };
closed_.store( true, std::memory_order_release);
not_full_cnd_.notify_all();
not_empty_cnd_.notify_all();
}
示例5: _pop
std::shared_ptr<T> wait_pop()
{
std::unique_lock<std::mutex> lock(_mtx);
_data_cond.wait(lock, [this]() { return _terminate || !_data.empty(); });
return _pop();
}
示例6: push
void push(T&& new_value)
{
std::lock_guard<std::mutex> lock(_mtx);
_data.push(std::move(new_value));
_data_cond.notify_one();
}
示例7: Signal
void Signal(void) {
(std::lock_guard<std::mutex>)m_lock,
(m_shouldContinue = true),
s_continueCond.notify_all();
}
示例8: notify
void notify()
{
std::lock_guard<std::mutex> lock(_mtx);
_data_cond.notify_all();
}
示例9: cancelAbort
void cancelAbort() {
std::unique_lock<std::mutex> lk(abortMutex);
abortCondVar.notify_one();
}
示例10: mainLoader
void mainLoader(int, char*[], ServiceManager* services)
{
//dispatcher thread
g_game.setGameState(GAME_STATE_STARTUP);
srand(static_cast<unsigned int>(OTSYS_TIME()));
#ifdef _WIN32
SetConsoleTitle(STATUS_SERVER_NAME);
#endif
std::cout << STATUS_SERVER_NAME << " - Version " << STATUS_SERVER_VERSION << std::endl;
std::cout << "Compiled with " << BOOST_COMPILER << std::endl;
std::cout << "Compiled on " << __DATE__ << ' ' << __TIME__ << " for platform ";
#if defined(__amd64__) || defined(_M_X64)
std::cout << "x64" << std::endl;
#elif defined(__i386__) || defined(_M_IX86) || defined(_X86_)
std::cout << "x86" << std::endl;
#elif defined(__arm__)
std::cout << "ARM" << std::endl;
#else
std::cout << "unknown" << std::endl;
#endif
std::cout << std::endl;
std::cout << "A server developed by " << STATUS_SERVER_DEVELOPERS << std::endl;
std::cout << "Visit our forum for updates, support, and resources: http://otland.net/." << std::endl;
std::cout << std::endl;
// read global config
std::cout << ">> Loading config" << std::endl;
if (!g_config.load()) {
startupErrorMessage("Unable to load config.lua!");
return;
}
#ifdef _WIN32
const std::string& defaultPriority = g_config.getString(ConfigManager::DEFAULT_PRIORITY);
if (strcasecmp(defaultPriority.c_str(), "high") == 0) {
SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS);
} else if (strcasecmp(defaultPriority.c_str(), "above-normal") == 0) {
SetPriorityClass(GetCurrentProcess(), ABOVE_NORMAL_PRIORITY_CLASS);
}
#endif
//set RSA key
const char* p("14299623962416399520070177382898895550795403345466153217470516082934737582776038882967213386204600674145392845853859217990626450972452084065728686565928113");
const char* q("7630979195970404721891201847792002125535401292779123937207447574596692788513647179235335529307251350570728407373705564708871762033017096809910315212884101");
g_RSA.setKey(p, q);
std::cout << ">> Establishing database connection..." << std::flush;
Database* db = Database::getInstance();
if (!db->connect()) {
startupErrorMessage("Failed to connect to database.");
return;
}
std::cout << " MySQL " << Database::getClientVersion() << std::endl;
// run database manager
std::cout << ">> Running database manager" << std::endl;
if (!DatabaseManager::isDatabaseSetup()) {
startupErrorMessage("The database you have specified in config.lua is empty, please import the schema.sql to your database.");
return;
}
g_databaseTasks.start();
DatabaseManager::updateDatabase();
if (g_config.getBoolean(ConfigManager::OPTIMIZE_DATABASE) && !DatabaseManager::optimizeTables()) {
std::cout << "> No tables were optimized." << std::endl;
}
//load vocations
std::cout << ">> Loading vocations" << std::endl;
if (!g_vocations.loadFromXml()) {
startupErrorMessage("Unable to load vocations!");
return;
}
// load item data
std::cout << ">> Loading items" << std::endl;
if (Item::items.loadFromOtb("data/items/items.otb") != ERROR_NONE) {
startupErrorMessage("Unable to load items (OTB)!");
return;
}
if (!Item::items.loadFromXml()) {
startupErrorMessage("Unable to load items (XML)!");
return;
}
std::cout << ">> Loading script systems" << std::endl;
if (!ScriptingManager::getInstance()->loadScriptSystems()) {
startupErrorMessage("Failed to load script systems");
return;
}
std::cout << ">> Loading monsters" << std::endl;
//.........这里部分代码省略.........
示例11: go
void go() {
std::unique_lock<std::mutex> lck(mtx);
ready = true;
cv.notify_all();
}
示例12: up
int up() {
std::lock_guard<std::mutex> lock(mtx);
if (++value > 0)
cv.notify_one();
return value;
}
示例13: wakeUp
/**
* Wakes up the worker if it was sleeping because it didn't have anything
* to do.
*/
inline void wakeUp() {
_cv.notify_one();
}
示例14: print_id
void print_id(int id) {
std::unique_lock<std::mutex> lck(mtx);
while (!ready) cv.wait(lck);
// ...
std::cout << "thread " << id << '\n';
}
示例15: main
int main(int argc, char* argv[])
{
ostringstream requestURI;
requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=a.collection";
PlatformConfig config
{ OC::ServiceType::InProc, ModeType::Client, "0.0.0.0", 0, OC::QualityOfService::LowQos };
bool isRun = true;
try
{
OCPlatform::Configure(config);
string resourceTypeName = "a.collection";
OCPlatform::findResource("", requestURI.str(),
CT_DEFAULT, &foundResource);
//Non-intensive block until foundResource callback is called by OCPlatform
//and onGet gets resource.
//isResourceReady takes care of spurious wake-up
std::unique_lock<std::mutex> lock(blocker);
cv.wait(lock, isResourceReady);
isReady = false;
while (isRun)
{
int selectedMenu;
cout << endl << "0 :: Quit 1 :: CREATE ACTIONSET 2 :: EXECUTE ACTION SET \n";
cout << "3 :: GET ACTIONSET 4 :: DELETE ACTIONSET \n" << endl;
cin >> selectedMenu;
OCRepresentation rep;
string actionsetDesc;
switch(selectedMenu)
{
case 0:
isRun = false;
break;
case 1:
actionsetDesc = buildActionSetDesc();
if(!actionsetDesc.empty())
{
cout << "ActionSet :: " << actionsetDesc << endl;
rep.setValue("ActionSet", actionsetDesc);
}
if (g_resource)
{
g_resource->put("a.collection", GROUP_INTERFACE, rep, QueryParamsMap(),
&onPut);
}
break;
case 2:
rep.setValue(DO_ACTION, std::string("allbulboff"));
if (g_resource)
{
g_resource->post("a.collection", GROUP_INTERFACE, rep, QueryParamsMap(),
&onPost);
}
break;
case 3:
rep.setValue(GET_ACTIONSET, std::string("allbulboff"));
if (g_resource)
{
g_resource->post("a.collection", GROUP_INTERFACE, rep, QueryParamsMap(),
&onPost);
}
break;
case 4:
rep.setValue("DelActionSet", std::string("allbulboff"));
if (g_resource)
{
g_resource->put("a.collection", GROUP_INTERFACE, rep, QueryParamsMap(),
&onPut);
}
break;
default:
cout << "Invalid option" << endl;
break;
}
fflush(stdin);
}
}
catch (OCException& e)
{
cout << e.what() << endl;
}
return 0;
}