Twitch SDK (Internal)
thread.h
Go to the documentation of this file.
1 /********************************************************************************************
2 * Twitch Broadcasting SDK
3 *
4 * This software is supplied under the terms of a license agreement with Twitch Interactive, Inc. and
5 * may not be copied or used except in accordance with the terms of that agreement
6 * Copyright (c) 2012-2016 Twitch Interactive, Inc.
7 *********************************************************************************************/
8 
9 #pragma once
10 
13 
14 #include <functional>
15 #include <memory>
16 
17 
18 namespace ttv
19 {
20  class IThread;
21  class IThreadFactory;
22  class IThreadApi;
23 
24  typedef std::function<void()> ThreadProc;
25 
26  TTV_ErrorCode SetThreadFactory(std::shared_ptr<IThreadFactory> factory);
27  TTV_ErrorCode SetThreadApi(std::shared_ptr<IThreadApi> api);
28 
32  void Sleep(uint64_t milliseconds);
33 
34  TTV_ErrorCode CreateThread(ThreadProc threadProc, const std::string& name, std::shared_ptr<IThread>& result);
35 }
36 
37 
39 {
40 public:
41  virtual ~IThread();
42 
46  virtual void Run() = 0;
47  virtual bool Joinable() const = 0;
48  virtual void Join() = 0;
49 };
50 
51 
53 {
54 public:
55  virtual ~IThreadFactory();
56 
57  virtual TTV_ErrorCode CreateThread(ThreadProc threadProc, const std::string& name, std::shared_ptr<IThread>& result) = 0;
58 };
59 
60 
62 {
63 public:
64  virtual ~IThreadApi();
65 
69  virtual void Sleep(uint64_t milliseconds) = 0;
70 };
TTV_ErrorCode SetThreadApi(std::shared_ptr< IThreadApi > api)
virtual bool Joinable() const =0
virtual void Join()=0
void Sleep(uint64_t milliseconds)
virtual ~IThread()
JSON (JavaScript Object Notation).
Definition: adsapi.h:16
TTV_ErrorCode CreateThread(ThreadProc threadProc, const std::string &name, std::shared_ptr< IThread > &result)
uint32_t TTV_ErrorCode
Definition: errortypes.h:30
std::function< void()> ThreadProc
Definition: thread.h:22
virtual void Run()=0
TTV_ErrorCode SetThreadFactory(std::shared_ptr< IThreadFactory > factory)
Definition: thread.h:61
Definition: thread.h:52
Definition: thread.h:38