cheshirekow  v0.1.0
key.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Josh Bialkowski (jbialk@mit.edu)
3  *
4  * This file is part of cpp-pthreads.
5  *
6  * cpp-pthreads is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * cpp-pthreads is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with cpp-pthreads. If not, see <http://www.gnu.org/licenses/>.
18  */
27 #ifndef CPP_PTHREADS_KEY_H_
28 #define CPP_PTHREADS_KEY_H_
29 
30 #include <pthread.h>
31 
32 namespace pthreads {
33 
36 class Key {
37  public:
40  typedef void (*Destructor_t)(void*);
41 
42  private:
43  pthread_key_t m_data;
44 
45  public:
48 
52  int create(Destructor_t destruct = 0);
53 
56  int destroy();
57 
59  void* getSpecific();
60 
62  int setSpecific(void* value);
63 };
64 
65 } // namespace pthreads
66 
67 #endif // KEY_H_
int create(Destructor_t destruct=0)
create a key that can be used to identify per-thread specific objects
void(* Destructor_t)(void *)
type of a function which is used to destroy the object if the object is not null when the key is dest...
Definition: key.h:40
pthread_key_t m_data
Definition: key.h:43
int setSpecific(void *value)
set this threads data in the box associated with this key
int destroy()
destroy the key, call destructor on data if it is set and data is not null
A key is an identifier used to specify a storage location where the thing stored is different for eac...
Definition: key.h:36
void * getSpecific()
return the data associated with this key that belongs to this thread