Changeset 4502 for trunk/oscam-garbage.c
- Timestamp:
- 01/16/11 23:44:26 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/oscam-garbage.c
r4449 r4502 10 10 }; 11 11 12 struct cs_garbage *garbage_first ;12 struct cs_garbage *garbage_first = NULL; 13 13 pthread_mutex_t garbage_lock; 14 pthread_t garbage_thread; 15 int garbage_collector_active = 0; 14 16 15 17 void add_garbage(void *data) { 16 18 if (!data) 17 19 return; 20 21 if (!garbage_collector_active) { 22 free(data); 23 return; 24 } 18 25 19 26 pthread_mutex_lock(&garbage_lock); … … 32 39 struct cs_garbage *garbage, *next, *prev; 33 40 34 while (1) { 35 cs_sleepms(1000); 41 while (garbage_collector_active) { 36 42 37 43 pthread_mutex_lock(&garbage_lock); … … 57 63 } 58 64 pthread_mutex_unlock(&garbage_lock); 65 66 cs_sleepms(1000); 59 67 } 60 68 } … … 65 73 66 74 garbage_first = NULL; 67 pthread_t temp;68 75 pthread_attr_t attr; 69 76 pthread_attr_init(&attr); 77 78 garbage_collector_active = 1; 79 70 80 #ifndef TUXBOX 71 81 pthread_attr_setstacksize(&attr, PTHREAD_STACK_SIZE); 72 82 #endif 73 pthread_create(& temp, &attr, (void*)&garbage_collector, NULL);74 pthread_detach( temp);83 pthread_create(&garbage_thread, &attr, (void*)&garbage_collector, NULL); 84 pthread_detach(garbage_thread); 75 85 pthread_attr_destroy(&attr); 76 86 } 77 87 88 void stop_garbage_collector() 89 { 90 if (garbage_collector_active) { 91 garbage_collector_active = 0; 92 pthread_mutex_lock(&garbage_lock); 93 94 pthread_cancel(garbage_thread); 95 96 while (garbage_first) { 97 struct cs_garbage *next = garbage_first->next; 98 free(garbage_first->data); 99 free(garbage_first); 100 garbage_first = next; 101 } 102 pthread_mutex_unlock(&garbage_lock); 103 pthread_mutex_destroy(&garbage_lock); 104 } 105 }
Note:
See TracChangeset
for help on using the changeset viewer.