-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathAPIThread.cpp
More file actions
57 lines (52 loc) · 979 Bytes
/
APIThread.cpp
File metadata and controls
57 lines (52 loc) · 979 Bytes
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
#include "APIThread.h"
APIThread::APIThread()
{
api = 0;
type = 0;
}
APIThread::APIThread(CoreAPI *API, int Type)
{
api = API;
type = Type;
}
bool APIThread::createThread()
{
pthread_t tid;
int ret = -1;
std::string infoStr;
if(1 == type)
{
ret = pthread_create(&tid, NULL, send_call, (void*)api);
infoStr = "sendPoll";
}
else if(2 == type)
{
ret = pthread_create(&tid, NULL, read_call, (void*)api);
infoStr = "readPoll";
}
else
{
infoStr = "error type number";
}
if(0 != ret)
{
API_LOG(api->getDriver(), ERROR_LOG, "fail to create thread for %s!\n",
infoStr.c_str());
return false;
}
return true;
}
void *APIThread::send_call(void *param)
{
while(true)
{
((CoreAPI*)param)->sendPoll();
}
}
void *APIThread::read_call(void *param)
{
while(true)
{
((CoreAPI*)param)->readPoll();
}
}