11//#include "memory_limit.h"
22#include <fcntl.h>
33#include <dlfcn.h>
4+ #include <pthread.h>
45#include "include/nvml_prefix.h"
56#include <nvml.h>
67#include "include/nvml_prefix.h"
@@ -40,7 +41,7 @@ fp_dlsym real_dlsym = NULL;
4041
4142pthread_mutex_t dlsym_lock ;
4243typedef struct {
43- int tid ;
44+ pthread_t tid ;
4445 void * pointer ;
4546}tid_dl_map ;
4647
@@ -55,11 +56,11 @@ void init_dlsym(){
5556 memset (dlmap , 0 , sizeof (tid_dl_map )* DLMAP_SIZE );
5657}
5758
58- int check_dlmap (int tid ,void * pointer ){
59+ int check_dlmap (pthread_t tid , void * pointer ){
5960 int i ;
6061 int cursor = (dlmap_count < DLMAP_SIZE ) ? dlmap_count : DLMAP_SIZE ;
6162 for (i = cursor - 1 ; i >=0 ; i -- ) {
62- if ((dlmap [i ].tid == tid ) && (dlmap [i ].pointer == pointer ))
63+ if ((dlmap [i ].pointer == pointer ) && pthread_equal (dlmap [i ].tid , tid ))
6364 return 1 ;
6465 }
6566 cursor = dlmap_count % DLMAP_SIZE ;
@@ -89,9 +90,8 @@ FUNC_ATTR_VISIBLE void* dlsym(void* handle, const char* symbol) {
8990 }
9091 if (handle == RTLD_NEXT ) {
9192 void * h = real_dlsym (RTLD_NEXT ,symbol );
92- int tid ;
9393 pthread_mutex_lock (& dlsym_lock );
94- tid = pthread_self ();
94+ pthread_t tid = pthread_self ();
9595 if (check_dlmap (tid ,h )){
9696 LOG_WARN ("recursive dlsym : %s\n" ,symbol );
9797 h = NULL ;
0 commit comments