Threads_win.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ALVAR, A Library for Virtual and Augmented Reality.
3  *
4  * Copyright 2007-2012 VTT Technical Research Centre of Finland
5  *
6  * Contact: VTT Augmented Reality Team <alvar.info@vtt.fi>
7  * <http://www.vtt.fi/multimedia/alvar.html>
8  *
9  * ALVAR is free software; you can redistribute it and/or modify it under the
10  * terms of the GNU Lesser General Public License as published by the Free
11  * Software Foundation; either version 2.1 of the License, or (at your option)
12  * any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
17  * for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with ALVAR; if not, see
21  * <http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html>.
22  */
23 
24 #include "Threads_private.h"
25 
26 #include <vector>
27 #include <windows.h>
28 
29 namespace alvar {
30 
32 {
33  void *(*method)(void *);
34  void *parameters;
35 };
36 
37 static DWORD WINAPI startThread(void *parameters)
38 {
39  DWORD value;
40  struct StartThreadParameters *p = (struct StartThreadParameters *)parameters;
41  value = (DWORD)p->method(p->parameters);
42  delete p;
43  return value;
44 }
45 
47 {
48 public:
50  : mHandles()
51  {
52  }
53 
54  std::vector<HANDLE> mHandles;
55 };
56 
58  : d(new ThreadsPrivateData())
59 {
60 }
61 
63 {
64  for (int i = 0; i < (int)d->mHandles.size(); ++i) {
65  CloseHandle(d->mHandles.at(i));
66  }
67  d->mHandles.clear();
68 
69  delete d;
70 }
71 
72 bool ThreadsPrivate::create(void *(*method)(void *), void *parameters)
73 {
75  p->method = method;
76  p->parameters = parameters;
77 
78  HANDLE thread = CreateThread(
79  NULL,
80  0,
81  (LPTHREAD_START_ROUTINE)startThread,
82  p,
83  0,
84  NULL);
85 
86  if (thread != NULL) {
87  d->mHandles.push_back(thread);
88  return true;
89  }
90  return false;
91 }
92 
93 } // namespace alvar
Main ALVAR namespace.
Definition: Alvar.h:174
std::vector< HANDLE > mHandles
Definition: Threads_win.cpp:54
static DWORD WINAPI startThread(void *parameters)
Definition: Threads_win.cpp:37
bool create(void *(*method)(void *), void *parameters)
Drawable d[32]
void *(* method)(void *)
Definition: Threads_win.cpp:33


ar_track_alvar
Author(s): Scott Niekum
autogenerated on Thu Jun 6 2019 19:27:24