📄 get_obj_name.c
字号:
/* Copyright (C) 2004,2005,2006 Bull S.A. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */#if HAVE_CONFIG_H#include <config.h>#endif#include <stdlib.h>#include <string.h>#include <assert.h>#include "glib_hash.h"#include "types.h"#include "modules.h"/* need 3 for the test */#define STACK_SIZE 3struct stack { unsigned int pos; void *stack[STACK_SIZE];};static GHashTable* hashtable;static void * get_name (ptt_event_t event, pid_t pid, void **list_ptr) { char tmp [255]; struct stack *sta; void *obj = NULL; void *tid = list_ptr[0]; sprintf (tmp, "%d-%p", pid, tid); switch (event) { case EVT_BARRIER_DESTROY_IN: case EVT_BARRIER_INIT_IN: case EVT_BARRIER_WAIT_IN: case EVT_COND_DESTROY_IN: case EVT_COND_INIT_IN: case EVT_COND_BROAD_IN: case EVT_COND_SIGNAL_IN: case EVT_COND_WAIT_IN: case EVT_MUTEX_DESTROY_IN: case EVT_MUTEX_INIT_IN: case EVT_MUTEX_LOCK_IN: case EVT_MUTEX_UNLOCK_IN: case EVT_THREAD_SET_PD: case EVT_THREAD_JOIN_IN: case EVT_THREAD_CANCEL_IN: sta = g_hash_table_lookup (hashtable, tmp); if (sta == NULL) { sta = malloc (sizeof (struct stack)); sta->pos = 0; sta->stack[sta->pos] = list_ptr[1]; g_hash_table_insert (hashtable, strdup(tmp), sta); } else { assert (sta->pos < STACK_SIZE - 1); sta->stack[++sta->pos] = list_ptr[1]; } obj = sta->stack[sta->pos]; break; case EVT_BARRIER_DESTROY_OUT: case EVT_BARRIER_INIT_OUT: case EVT_BARRIER_WAIT_OUT: case EVT_COND_DESTROY_OUT: case EVT_COND_INIT_OUT: case EVT_COND_BROAD_OUT: case EVT_COND_SIGNAL_OUT: case EVT_COND_WAIT_OUT: case EVT_MUTEX_DESTROY_OUT: case EVT_MUTEX_INIT_OUT: case EVT_MUTEX_LOCK_OUT: case EVT_MUTEX_UNLOCK_OUT: case EVT_THREAD_CREATE_OUT: case EVT_THREAD_JOIN_OUT: case EVT_THREAD_CANCEL_OUT: sta = g_hash_table_lookup (hashtable, tmp); if (sta == NULL) return NULL; obj = sta->stack[sta->pos]; if (sta->pos > 0) sta->pos--; break; case EVT_START_USER_FUNC: case EVT_END_USER_FUNC: case EVT_THREAD_DETACH: case EVT_THREAD_STATE_DEAD: case EVT_THREAD_STATE_WAIT: case EVT_THREAD_STATE_WAKE: obj = NULL; break; case EVT_THREAD_CREATE_IN: obj = list_ptr[1]; break; case EVT_PROG_FORK: break; default: sta = g_hash_table_lookup (hashtable, tmp); if (sta == NULL) return NULL; obj = sta->stack[sta->pos]; break; } return obj;}static int init () { hashtable = g_hash_table_new (g_str_hash, g_str_equal); return 0;}static void free_hash (gpointer key, gpointer value, gpointer user_data) { struct stack *sta = (struct stack *) value; free(sta); free(key);}static void close () { g_hash_table_foreach (hashtable, free_hash, NULL); g_hash_table_destroy (hashtable);}struct get_obj_name get_obj_name = { .init = init, .get = get_name, .close = close};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -