Changeset 3183 for trunk/module-stat.c
- Timestamp:
- 09/23/10 10:02:05 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/module-stat.c
r3181 r3183 11 11 #define DEFAULT_NFB 1 12 12 13 struct timeb nulltime; 13 static struct timeb nulltime; 14 static pthread_mutex_t stat_busy; 14 15 15 16 int ecm_send_cache_idx = 0; … … 41 42 cfg->lb_reopen_seconds = DEFAULT_REOPEN_SECONDS; 42 43 44 //init mutex lock with recusive attribute: 45 pthread_mutexattr_t mta; 46 pthread_mutexattr_init(&mta); 47 pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_RECURSIVE); 48 pthread_mutex_init(&stat_busy, &mta); 43 49 } 44 50 … … 103 109 READER_STAT *get_stat(int ridx, ushort caid, ulong prid, ushort srvid) 104 110 { 111 pthread_mutex_lock(&stat_busy); 105 112 if (!reader_stat[ridx]) { 106 113 reader_stat[ridx] = llist_create(); … … 112 119 READER_STAT *stat = llist_itr_init(reader_stat[ridx], &itr); 113 120 while (stat) { 114 if (stat->caid==caid && stat->prid==prid && stat->srvid==srvid) 121 if (stat->caid==caid && stat->prid==prid && stat->srvid==srvid) { 122 pthread_mutex_unlock(&stat_busy); 115 123 return stat; 124 } 116 125 117 126 stat = llist_itr_next(&itr); 118 127 } 128 pthread_mutex_unlock(&stat_busy); 119 129 return NULL; 120 130 } … … 128 138 return 0; 129 139 140 pthread_mutex_lock(&stat_busy); 130 141 int c = 0; 131 142 LLIST_ITR itr; … … 141 152 } 142 153 clear_from_cache(caid); 154 pthread_mutex_unlock(&stat_busy); 143 155 return c; 144 156 } … … 169 181 void save_stat_to_file(int ridx) 170 182 { 183 pthread_mutex_lock(&stat_busy); 171 184 char fname[40]; 172 185 sprintf(fname, "%s/stat.%d", get_tmp_dir(), ridx); 173 186 if (!reader_stat[ridx] || !llist_count(reader_stat[ridx])) { 174 187 remove(fname); 188 pthread_mutex_unlock(&stat_busy); 175 189 return; 176 190 } … … 181 195 if (!stat) { 182 196 remove(fname); 197 pthread_mutex_unlock(&stat_busy); 183 198 return; 184 199 } 185 200 186 201 FILE *file = fopen(fname, "w"); 187 if (!file) 202 if (!file) { 203 pthread_mutex_unlock(&stat_busy); 188 204 return; 205 } 189 206 190 207 while (stat) { … … 194 211 } 195 212 fclose(file); 213 pthread_mutex_unlock(&stat_busy); 196 214 } 197 215 198 216 void save_all_stat_to_file() 199 217 { 218 pthread_mutex_lock(&stat_busy); 200 219 int i; 201 220 for (i = 0; i < CS_MAXREADER; i++) 202 221 save_stat_to_file(i); 222 pthread_mutex_unlock(&stat_busy); 203 223 } 204 224 … … 208 228 void add_stat(int ridx, ushort caid, ulong prid, ushort srvid, int ecm_time, int rc) 209 229 { 230 pthread_mutex_lock(&stat_busy); 210 231 READER_STAT *stat = get_stat(ridx, caid, prid, srvid); 211 232 if (!stat) { … … 287 308 } 288 309 } 310 pthread_mutex_unlock(&stat_busy); 289 311 } 290 312 … … 299 321 void reset_stat(ushort caid, ulong prid, ushort srvid) 300 322 { 323 pthread_mutex_lock(&stat_busy); 301 324 //cs_debug_mask(D_TRACE, "loadbalance: resetting ecm count"); 302 325 int i; … … 311 334 } 312 335 } 336 pthread_mutex_unlock(&stat_busy); 313 337 } 314 338 … … 322 346 int get_best_reader(GET_READER_STAT *grs, int *result) 323 347 { 348 pthread_mutex_lock(&stat_busy); 324 349 int i; 325 350 i = chk_send_cache(grs->caid, grs->ecmd5); … … 333 358 result[8], result[9], result[10], result[11], result[12], result[13], result[14], result[15]); 334 359 360 pthread_mutex_unlock(&stat_busy); 335 361 return best_ridx; 336 362 } … … 484 510 nulltime = new_nulltime; 485 511 512 pthread_mutex_unlock(&stat_busy); 513 486 514 return best_ridx; 487 515 } … … 492 520 void clear_reader_stat(int ridx) 493 521 { 494 if (!reader_stat[ridx]) 522 if (!reader_stat[ridx]) 495 523 return; 496 524 525 pthread_mutex_lock(&stat_busy); 526 497 527 LLIST_ITR itr; 498 528 READER_STAT *stat = llist_itr_init(reader_stat[ridx], &itr); … … 503 533 llist_destroy(reader_stat[ridx]); 504 534 reader_stat[ridx] = NULL; 505 } 535 536 pthread_mutex_unlock(&stat_busy); 537 }
Note:
See TracChangeset
for help on using the changeset viewer.