Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

[0a1223]: mt / TSS_Object.cpp Maximize Restore History

Download this file

TSS_Object.cpp    103 lines (86 with data), 3.2 kB

  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
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
/***************************************************************************
TSS_Object.h - base class for usage of TSS (supports asynchronous exits)
-------------------
begin : Sun Oct 01 2000
copyright : (C) 2000 by Thomas Eschenbacher
email : Thomas.Eschenbacher@gmx.de
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "config.h"
#include <kapp.h> // only for debug() and warning()
#include "mt/TSS_Object.h"
#ifdef HAVE_DEMANGLE_H
extern "C" {
#include <demangle.h>
}
#endif // HAVE_DEMANGLE_H
#ifdef HAVE_TYPEINFO
#include <typeinfo>
#endif // HAVE_TYPEINFO
//***************************************************************************
/**
* Cleanup handler function for the TSS_Object class.
* @param ptr pointer to a TSS_Object instance
*/
extern "C" void TSS_Object_cleanup_func(void *ptr)
{
if (!ptr) {
warning("cleanup handler for NULL pointer ?\n");
}
#ifdef HAVE_TYPEINFO
try {
TSS_Object *tssobj = (TSS_Object *)ptr;
const char *obj_name = typeid(*tssobj).name();
if (obj_name) {
/* try to demangle the symbol name */
#ifdef HAVE_DEMANGLE_H
char *res = cplus_demangle(obj_name,
DMGL_ANSI | DMGL_PARAMS | DMGL_AUTO);
if (res) {
/* use the damangeled name instead */
warning("cleanup handler for class %s", res);
free(res);
} else {
#endif // HAVE_DEMANGLE_H
warning("cleanup handler for class `%s'", obj_name);
#ifdef HAVE_DEMANGLE_H
}
#endif // HAVE_DEMANGLE_H
} else {
warning("cleanup handler for unknown class `%s'", obj_name);
}
if (tssobj) delete tssobj;
}
catch (...) {
warning("cleanup handler for %p failed", ptr);
}
#else // HAVE_TYPEINFO
warning("cleanup handler for %p", ptr);
#endif // HAVE_TYPEINFO
}
//***************************************************************************
TSS_Object::TSS_Object()
:m_key(0)
{
if (pthread_key_create(&m_key, TSS_Object_cleanup_func) == -1) {
warning("TSS_Object::keycreate failed");
}
if (pthread_setspecific(m_key, (void *)this) == -1) {
warning("TSS_Object::setspecific failed");
}
}
//***************************************************************************
TSS_Object::~TSS_Object()
{
pthread_key_delete(m_key);
}
//***************************************************************************
//***************************************************************************
/* end of TSS_Object.cpp */