| 2269:8b165bf6ddc7 | 2270:c65fc356fb68 |
|---|---|
| 20 */ | 20 */ |
| 21 faim_internal void aim_initsnachash(aim_session_t *sess) | 21 faim_internal void aim_initsnachash(aim_session_t *sess) |
| 22 { | 22 { |
| 23 int i; | 23 int i; |
| 24 | 24 |
| 25 for (i = 0; i < FAIM_SNAC_HASH_SIZE; i++) { | 25 for (i = 0; i < FAIM_SNAC_HASH_SIZE; i++) |
| 26 sess->snac_hash[i] = NULL; | 26 sess->snac_hash[i] = NULL; |
| 27 faim_mutex_init(&sess->snac_hash_locks[i]); | |
| 28 } | |
| 29 | 27 |
| 30 return; | 28 return; |
| 31 } | 29 } |
| 32 | 30 |
| 33 faim_internal aim_snacid_t aim_cachesnac(aim_session_t *sess, const fu16_t family, const fu16_t type, const fu16_t flags, const void *data, const int datalen) | 31 faim_internal aim_snacid_t aim_cachesnac(aim_session_t *sess, const fu16_t family, const fu16_t type, const fu16_t flags, const void *data, const int datalen) |
| 66 memcpy(snac, newsnac, sizeof(aim_snac_t)); | 64 memcpy(snac, newsnac, sizeof(aim_snac_t)); |
| 67 snac->issuetime = time(NULL); | 65 snac->issuetime = time(NULL); |
| 68 | 66 |
| 69 index = snac->id % FAIM_SNAC_HASH_SIZE; | 67 index = snac->id % FAIM_SNAC_HASH_SIZE; |
| 70 | 68 |
| 71 faim_mutex_lock(&sess->snac_hash_locks[index]); | |
| 72 snac->next = (aim_snac_t *)sess->snac_hash[index]; | 69 snac->next = (aim_snac_t *)sess->snac_hash[index]; |
| 73 sess->snac_hash[index] = (void *)snac; | 70 sess->snac_hash[index] = (void *)snac; |
| 74 faim_mutex_unlock(&sess->snac_hash_locks[index]); | |
| 75 | 71 |
| 76 return snac->id; | 72 return snac->id; |
| 77 } | 73 } |
| 78 | 74 |
| 79 /* | 75 /* |
| 88 aim_snac_t *cur, **prev; | 84 aim_snac_t *cur, **prev; |
| 89 int index; | 85 int index; |
| 90 | 86 |
| 91 index = id % FAIM_SNAC_HASH_SIZE; | 87 index = id % FAIM_SNAC_HASH_SIZE; |
| 92 | 88 |
| 93 faim_mutex_lock(&sess->snac_hash_locks[index]); | |
| 94 for (prev = (aim_snac_t **)&sess->snac_hash[index]; (cur = *prev); ) { | 89 for (prev = (aim_snac_t **)&sess->snac_hash[index]; (cur = *prev); ) { |
| 95 if (cur->id == id) { | 90 if (cur->id == id) { |
| 96 *prev = cur->next; | 91 *prev = cur->next; |
| 97 return cur; | 92 return cur; |
| 98 } else | 93 } else |
| 99 prev = &cur->next; | 94 prev = &cur->next; |
| 100 } | 95 } |
| 101 faim_mutex_unlock(&sess->snac_hash_locks[index]); | |
| 102 | 96 |
| 103 return cur; | 97 return cur; |
| 104 } | 98 } |
| 105 | 99 |
| 106 /* | 100 /* |
| 116 | 110 |
| 117 for (i = 0; i < FAIM_SNAC_HASH_SIZE; i++) { | 111 for (i = 0; i < FAIM_SNAC_HASH_SIZE; i++) { |
| 118 aim_snac_t *cur, **prev; | 112 aim_snac_t *cur, **prev; |
| 119 time_t curtime; | 113 time_t curtime; |
| 120 | 114 |
| 121 faim_mutex_lock(&sess->snac_hash_locks[i]); | 115 if (!sess->snac_hash[i]) |
| 122 if (!sess->snac_hash[i]) { | |
| 123 faim_mutex_unlock(&sess->snac_hash_locks[i]); | |
| 124 continue; | 116 continue; |
| 125 } | |
| 126 | 117 |
| 127 curtime = time(NULL); /* done here in case we waited for the lock */ | 118 curtime = time(NULL); /* done here in case we waited for the lock */ |
| 128 | 119 |
| 129 for (prev = (aim_snac_t **)&sess->snac_hash[i]; (cur = *prev); ) { | 120 for (prev = (aim_snac_t **)&sess->snac_hash[i]; (cur = *prev); ) { |
| 130 if ((curtime - cur->issuetime) > maxage) { | 121 if ((curtime - cur->issuetime) > maxage) { |
| 136 free(cur); | 127 free(cur); |
| 137 | 128 |
| 138 } else | 129 } else |
| 139 prev = &cur->next; | 130 prev = &cur->next; |
| 140 } | 131 } |
| 141 faim_mutex_unlock(&sess->snac_hash_locks[i]); | |
| 142 } | 132 } |
| 143 | 133 |
| 144 return; | 134 return; |
| 145 } | 135 } |
| 146 | 136 |