Mercurial > mplayer.hg
comparison loader/win32.c @ 2579:d10f16ef155c
introduced new critical section handling
author | alex |
---|---|
date | Tue, 30 Oct 2001 22:40:40 +0000 |
parents | 9009b6d24296 |
children | 958d10763c34 |
comparison
equal
deleted
inserted
replaced
2578:d363fde389b5 | 2579:d10f16ef155c |
---|---|
964 void *newp; | 964 void *newp; |
965 orgsize = my_size(lpMem); | 965 orgsize = my_size(lpMem); |
966 dbgprintf("HeapReAlloc() Size %ld org %d\n",orgsize,size); | 966 dbgprintf("HeapReAlloc() Size %ld org %d\n",orgsize,size); |
967 if (size < orgsize) | 967 if (size < orgsize) |
968 return lpMem; | 968 return lpMem; |
969 | |
969 newp=my_mreq(size, flags & 8); | 970 newp=my_mreq(size, flags & 8); |
970 memcpy(newp, lpMem, orgsize); | 971 memcpy(newp, lpMem, orgsize); |
971 my_release(lpMem); | 972 my_release(lpMem); |
972 return newp; | 973 return newp; |
973 } | 974 } |
989 { | 990 { |
990 int result=VirtualFree(v1,v2,v3); | 991 int result=VirtualFree(v1,v2,v3); |
991 dbgprintf("VirtualFree(0x%x, %d, %d) => %d\n",v1,v2,v3, result); | 992 dbgprintf("VirtualFree(0x%x, %d, %d) => %d\n",v1,v2,v3, result); |
992 return result; | 993 return result; |
993 } | 994 } |
995 | |
996 /* -- critical sections -- */ | |
994 struct CRITSECT | 997 struct CRITSECT |
995 { | 998 { |
996 pthread_t id; | 999 pthread_t id; |
997 pthread_mutex_t mutex; | 1000 pthread_mutex_t mutex; |
998 int locked; | 1001 int locked; |
999 }; | 1002 }; |
1000 | 1003 |
1004 /* we're building a table of critical sections. cs_win pointer uses the DLL | |
1005 cs_unix is the real structure, we're using cs_win only to identifying cs_unix */ | |
1006 struct critsecs_list_t | |
1007 { | |
1008 CRITICAL_SECTION *cs_win; | |
1009 struct CRITSECT *cs_unix; | |
1010 }; | |
1011 | |
1012 #define CRITSECS_LIST_MAX 20 | |
1013 static struct critsecs_list_t critsecs_list[CRITSECS_LIST_MAX]; | |
1014 | |
1015 int critsecs_get_pos(CRITICAL_SECTION *cs_win) | |
1016 { | |
1017 int i; | |
1018 | |
1019 for (i=0; i < CRITSECS_LIST_MAX; i++) | |
1020 if (critsecs_list[i].cs_win == cs_win) | |
1021 return(i); | |
1022 return(-1); | |
1023 } | |
1024 | |
1025 int critsecs_get_unused(void) | |
1026 { | |
1027 int i; | |
1028 | |
1029 for (i=0; i < CRITSECS_LIST_MAX; i++) | |
1030 if (critsecs_list[i].cs_win == NULL) | |
1031 return(i); | |
1032 return(-1); | |
1033 } | |
1034 | |
1035 #if 0 | |
1036 #define critsecs_get_unix(cs_win) (critsecs_list[critsecs_get_pos(cs_win)].cs_win) | |
1037 #else | |
1038 struct CRITSECT *critsecs_get_unix(CRITICAL_SECTION *cs_win) | |
1039 { | |
1040 int i; | |
1041 | |
1042 for (i=0; i < CRITSECS_LIST_MAX; i++) | |
1043 if (critsecs_list[i].cs_win == cs_win) | |
1044 return(critsecs_list[i].cs_unix); | |
1045 return(NULL); | |
1046 } | |
1047 #endif | |
1048 | |
1049 #define CRITSECS_NEWTYPE 1 | |
1050 | |
1001 void WINAPI expInitializeCriticalSection(CRITICAL_SECTION* c) | 1051 void WINAPI expInitializeCriticalSection(CRITICAL_SECTION* c) |
1002 { | 1052 { |
1003 struct CRITSECT cs; | |
1004 dbgprintf("InitializeCriticalSection(0x%x)\n", c); | 1053 dbgprintf("InitializeCriticalSection(0x%x)\n", c); |
1005 /* if(sizeof(pthread_mutex_t)>sizeof(CRITICAL_SECTION)) | 1054 /* if(sizeof(pthread_mutex_t)>sizeof(CRITICAL_SECTION)) |
1006 { | 1055 { |
1007 printf(" ERROR:::: sizeof(pthread_mutex_t) is %d, expected <=%d!\n", | 1056 printf(" ERROR:::: sizeof(pthread_mutex_t) is %d, expected <=%d!\n", |
1008 sizeof(pthread_mutex_t), sizeof(CRITICAL_SECTION)); | 1057 sizeof(pthread_mutex_t), sizeof(CRITICAL_SECTION)); |
1009 return; | 1058 return; |
1010 }*/ | 1059 }*/ |
1011 /* pthread_mutex_init((pthread_mutex_t*)c, NULL); */ | 1060 /* pthread_mutex_init((pthread_mutex_t*)c, NULL); */ |
1012 pthread_mutex_init(&cs.mutex, NULL); | 1061 #ifdef CRITSECS_NEWTYPE |
1062 { | |
1063 struct CRITSECT *cs; | |
1064 int i = critsecs_get_unused(); | |
1065 | |
1066 if (i < 0) | |
1067 { | |
1068 printf("InitializeCriticalSection(%p) - no more space in list\n", c); | |
1069 return; | |
1070 } | |
1071 cs = malloc(sizeof(struct CRITSECT)); | |
1072 pthread_mutex_init(&cs->mutex, NULL); | |
1073 cs->locked = 0; | |
1074 critsecs_list[i].cs_win = c; | |
1075 critsecs_list[i].cs_unix = cs; | |
1076 dbgprintf("InitializeCriticalSection -> itemno=%d, cs_win=%p, cs_unix=%p\n", | |
1077 i, c, cs); | |
1078 } | |
1079 #else | |
1080 { | |
1081 struct CRITSECT cs; | |
1082 pthread_mutex_init(&cs.mutex, NULL); | |
1013 cs.locked=0; | 1083 cs.locked=0; |
1014 *(void**)c=malloc(sizeof cs); | 1084 *(void**)c=malloc(sizeof cs); |
1015 memcpy(*(void**)c, &cs, sizeof cs); | 1085 memcpy(*(void**)c, &cs, sizeof cs); |
1086 } | |
1087 #endif | |
1016 return; | 1088 return; |
1017 } | 1089 } |
1090 | |
1018 void WINAPI expEnterCriticalSection(CRITICAL_SECTION* c) | 1091 void WINAPI expEnterCriticalSection(CRITICAL_SECTION* c) |
1019 { | 1092 { |
1093 #ifdef CRITSECS_NEWTYPE | |
1094 struct CRITSECT* cs = critsecs_get_unix(c); | |
1095 #else | |
1020 struct CRITSECT* cs=*(struct CRITSECT**)c; | 1096 struct CRITSECT* cs=*(struct CRITSECT**)c; |
1097 #endif | |
1021 dbgprintf("EnterCriticalSection(0x%x)\n",c); | 1098 dbgprintf("EnterCriticalSection(0x%x)\n",c); |
1022 if (!cs) | 1099 if (!cs) |
1023 { | 1100 { |
1024 expInitializeCriticalSection(c); | 1101 expInitializeCriticalSection(c); |
1102 #ifdef CRITSECS_NEWTYPE | |
1103 cs=critsecs_get_unix(c); | |
1104 #else | |
1025 cs=*(struct CRITSECT**)c; | 1105 cs=*(struct CRITSECT**)c; |
1106 #endif | |
1026 printf("Win32 Warning: Accessed uninitialized Critical Section (%p)!\n", c); | 1107 printf("Win32 Warning: Accessed uninitialized Critical Section (%p)!\n", c); |
1027 } | 1108 } |
1028 // cs.id=pthread_self(); | 1109 // cs.id=pthread_self(); |
1029 if(cs->locked) | 1110 if(cs->locked) |
1030 if(cs->id==pthread_self()) | 1111 if(cs->id==pthread_self()) |
1034 cs->id=pthread_self(); | 1115 cs->id=pthread_self(); |
1035 return; | 1116 return; |
1036 } | 1117 } |
1037 void WINAPI expLeaveCriticalSection(CRITICAL_SECTION* c) | 1118 void WINAPI expLeaveCriticalSection(CRITICAL_SECTION* c) |
1038 { | 1119 { |
1120 #ifdef CRITSECS_NEWTYPE | |
1121 struct CRITSECT* cs = critsecs_get_unix(c); | |
1122 #else | |
1039 struct CRITSECT* cs=*(struct CRITSECT**)c; | 1123 struct CRITSECT* cs=*(struct CRITSECT**)c; |
1124 #endif | |
1040 // struct CRITSECT* cs=(struct CRITSECT*)c; | 1125 // struct CRITSECT* cs=(struct CRITSECT*)c; |
1041 dbgprintf("LeaveCriticalSection(0x%x)\n",c); | 1126 dbgprintf("LeaveCriticalSection(0x%x)\n",c); |
1042 if (!cs) | 1127 if (!cs) |
1043 { | 1128 { |
1044 printf("Win32 Warning: Leaving noninitialized Critical Section %p!!\n", c); | 1129 printf("Win32 Warning: Leaving noninitialized Critical Section %p!!\n", c); |
1048 pthread_mutex_unlock(&(cs->mutex)); | 1133 pthread_mutex_unlock(&(cs->mutex)); |
1049 return; | 1134 return; |
1050 } | 1135 } |
1051 void WINAPI expDeleteCriticalSection(CRITICAL_SECTION *c) | 1136 void WINAPI expDeleteCriticalSection(CRITICAL_SECTION *c) |
1052 { | 1137 { |
1138 #ifdef CRITSECS_NEWTYPE | |
1139 struct CRITSECT* cs = critsecs_get_unix(c); | |
1140 #else | |
1053 struct CRITSECT* cs=*(struct CRITSECT**)c; | 1141 struct CRITSECT* cs=*(struct CRITSECT**)c; |
1142 #endif | |
1054 // struct CRITSECT* cs=(struct CRITSECT*)c; | 1143 // struct CRITSECT* cs=(struct CRITSECT*)c; |
1055 dbgprintf("DeleteCriticalSection(0x%x)\n",c); | 1144 dbgprintf("DeleteCriticalSection(0x%x)\n",c); |
1056 pthread_mutex_destroy(&(cs->mutex)); | 1145 pthread_mutex_destroy(&(cs->mutex)); |
1057 free(cs); | 1146 // free(cs); |
1147 #ifdef CRITSECS_NEWTYPE | |
1148 { | |
1149 int i = critsecs_get_pos(c); | |
1150 | |
1151 if (i < 0) | |
1152 { | |
1153 printf("DeleteCriticalSection(%p) error (critsec not found)\n", c); | |
1154 return; | |
1155 } | |
1156 | |
1157 critsecs_list[i].cs_win = NULL; | |
1158 free(critsecs_list[i].cs_unix); | |
1159 critsecs_list[i].cs_unix = NULL; | |
1160 dbgprintf("DeleteCriticalSection -> itemno=%d\n", i); | |
1161 } | |
1162 #endif | |
1058 return; | 1163 return; |
1059 } | 1164 } |
1060 int WINAPI expGetCurrentThreadId() | 1165 int WINAPI expGetCurrentThreadId() |
1061 { | 1166 { |
1062 dbgprintf("GetCurrentThreadId() => %d\n", getpid()); | 1167 dbgprintf("GetCurrentThreadId() => %d\n", getpid()); |
2992 continue; | 3097 continue; |
2993 for(j=0; j<libraries[i].length; j++) | 3098 for(j=0; j<libraries[i].length; j++) |
2994 { | 3099 { |
2995 if(ordinal!=libraries[i].exps[j].id) | 3100 if(ordinal!=libraries[i].exps[j].id) |
2996 continue; | 3101 continue; |
2997 printf("Hit: 0x%p\n", libraries[i].exps[j].func); | 3102 printf("Hit: %p\n", libraries[i].exps[j].func); |
2998 return libraries[i].exps[j].func; | 3103 return libraries[i].exps[j].func; |
2999 } | 3104 } |
3000 } | 3105 } |
3001 if(pos>150)return 0; | 3106 if(pos>150)return 0; |
3002 answ=(char*)extcode+pos*0x64; | 3107 answ=(char*)extcode+pos*0x64; |