-
Notifications
You must be signed in to change notification settings - Fork 127
Expand file tree
/
Copy pathClientMainloop.h
More file actions
60 lines (49 loc) · 1.73 KB
/
Copy pathClientMainloop.h
File metadata and controls
60 lines (49 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/** @file
@brief Header
@date 2015
@author
Sensics, Inc.
<http://sensics.com/osvr>
*/
// Copyright 2015 Sensics, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef INCLUDED_ClientMainloop_h_GUID_CE5D82DA_5A69_46A0_55BA_BE9DB68B61CE
#define INCLUDED_ClientMainloop_h_GUID_CE5D82DA_5A69_46A0_55BA_BE9DB68B61CE
// Internal Includes
#include <osvr/ClientKit/ClientKit.h>
// Library/third-party includes
#include <boost/noncopyable.hpp>
#include <boost/thread/recursive_mutex.hpp>
#include <boost/thread/locks.hpp>
// Standard includes
// - none
/// @brief Simple class to handle running a client mainloop in another thread,
/// but easily pausable.
class ClientMainloop : boost::noncopyable {
public:
typedef boost::recursive_mutex mutex_type;
typedef boost::unique_lock<mutex_type> lock_type;
ClientMainloop(osvr::clientkit::ClientContext &ctx) : m_ctx(ctx) {}
void mainloop() {
lock_type lock(m_mutex, boost::try_to_lock);
if (lock) {
m_ctx.update();
}
}
mutex_type &getMutex() { return m_mutex; }
private:
osvr::clientkit::ClientContext &m_ctx;
mutex_type m_mutex;
};
#endif // INCLUDED_ClientMainloop_h_GUID_CE5D82DA_5A69_46A0_55BA_BE9DB68B61CE