thread.cc
Go to the documentation of this file.
1 /* Copyright 2017 UFACTORY Inc. All Rights Reserved.
2  *
3  * Software License Agreement (BSD License)
4  *
5  * Author: Jimy Zhang <jimy92@163.com>
6  ============================================================================*/
7 
8 
9 #include <stdio.h>
10 #include "xarm/core/os/thread.h"
11 
12 #define PRINT_ERR printf
13 
14 #ifdef _WIN32
15 HANDLE thread_init(fun_point_t fun_point, void *arg) {
16  HANDLE m_handle;
17  /*
18  pthread_attr_t attr;
19 
20  pthread_attr_init(&attr);
21  pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
22  char ret = pthread_create(&id, &attr, fun_point, arg);
23  */
24  m_handle = (HANDLE)_beginthreadex(NULL, 0, fun_point, arg, 0, NULL);
25  if (NULL == m_handle) PRINT_ERR("error: pthread create failes\n");
26 
27  return m_handle;
28 }
29 
30 void thread_delete(HANDLE m_handle) { CloseHandle(m_handle); }
31 
32 #else
33 pthread_t thread_init(fun_point_t fun_point, void *arg) {
34  pthread_t id;
35  pthread_attr_t attr;
36 
37  pthread_attr_init(&attr);
38  pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
39  char ret = pthread_create(&id, &attr, fun_point, arg);
40  if (0 != ret) PRINT_ERR("error: pthread create failes\n");
41 
42  return id;
43 }
44 
45 void thread_delete(pthread_t id) { pthread_cancel(id); }
46 #endif
47 
48 
49 
void thread_delete(pthread_t id)
Definition: thread.cc:45
#define PRINT_ERR
Definition: thread.cc:12
pthread_t thread_init(fun_point_t fun_point, void *arg)
Definition: thread.cc:33
void *(* fun_point_t)(void *)
Definition: thread.h:37


xarm_api
Author(s):
autogenerated on Sat May 8 2021 02:51:23