Migrated thread_value_t to INIT/METHOD macros.

This commit is contained in:
Tobias Brunner
2011-10-03 14:57:07 +02:00
parent 71b6235ad8
commit 242f7c857f
+15 -17
View File
@@ -35,27 +35,20 @@ struct private_thread_value_t {
}; };
METHOD(thread_value_t, set, void,
/** private_thread_value_t *this, void *val)
* Implementation of thread_value_t.set.
*/
static void set(private_thread_value_t *this, void *val)
{ {
pthread_setspecific(this->key, val); pthread_setspecific(this->key, val);
} }
/** METHOD(thread_value_t, get, void*,
* Implementation of thread_value_t.get. private_thread_value_t *this)
*/
static void *get(private_thread_value_t *this)
{ {
return pthread_getspecific(this->key); return pthread_getspecific(this->key);
} }
/** METHOD(thread_value_t, destroy, void,
* Implementation of thread_value_t.destroy. private_thread_value_t *this)
*/
static void destroy(private_thread_value_t *this)
{ {
pthread_key_delete(this->key); pthread_key_delete(this->key);
free(this); free(this);
@@ -67,10 +60,15 @@ static void destroy(private_thread_value_t *this)
*/ */
thread_value_t *thread_value_create(thread_cleanup_t destructor) thread_value_t *thread_value_create(thread_cleanup_t destructor)
{ {
private_thread_value_t *this = malloc_thing(private_thread_value_t); private_thread_value_t *this;
this->public.set = (void(*)(thread_value_t*,void*))set;
this->public.get = (void*(*)(thread_value_t*))get; INIT(this,
this->public.destroy = (void(*)(thread_value_t*))destroy; .public = {
.set = _set,
.get = _get,
.destroy = _destroy,
},
);
pthread_key_create(&this->key, destructor); pthread_key_create(&this->key, destructor);
return &this->public; return &this->public;