FS-10167: Committing for a clean revert point prior to work on ks_pool internal allocator issues that were identified as the cause of the complicated bug related to freeing pages introduced by switching to malloc/free.
This commit is contained in:
parent
80e06c214c
commit
48d9f3aa85
|
@ -463,6 +463,7 @@ static void *alloc_pages(ks_pool_t *mp_p, const unsigned int page_n, ks_status_t
|
|||
|
||||
mem = malloc(size);
|
||||
ks_assert(mem);
|
||||
memset(mem, 0, size);
|
||||
|
||||
mp_p->mp_top += size;
|
||||
mp_p->mp_page_c += page_n;
|
||||
|
@ -1024,7 +1025,6 @@ static int free_mem(ks_pool_t *mp_p, void *addr)
|
|||
return ret;
|
||||
}
|
||||
|
||||
|
||||
ret = free_pointer(mp_p, addr, size);
|
||||
|
||||
if (ret != KS_STATUS_SUCCESS) {
|
||||
|
@ -1286,7 +1286,15 @@ static ks_status_t ks_pool_raw_close(ks_pool_t *mp_p)
|
|||
/* record the next pointer because it might be invalidated below */
|
||||
next_p = block_p->mb_next_p;
|
||||
|
||||
if (next_p && (next_p->mb_magic != BLOCK_MAGIC || next_p->mb_magic2 != BLOCK_MAGIC)) {
|
||||
final = KS_STATUS_POOL_OVER;
|
||||
break;
|
||||
}
|
||||
ret = free_pages(block_p, (unsigned long)((char *) block_p->mb_bounds_p - (char *) block_p));
|
||||
if (next_p && (next_p->mb_magic != BLOCK_MAGIC || next_p->mb_magic2 != BLOCK_MAGIC)) {
|
||||
final = KS_STATUS_POOL_OVER;
|
||||
break;
|
||||
}
|
||||
|
||||
if (ret != KS_STATUS_SUCCESS) {
|
||||
final = ret;
|
||||
|
@ -1455,6 +1463,8 @@ KS_DECLARE(void *) ks_pool_alloc_ex(ks_pool_t *mp_p, const unsigned long byte_si
|
|||
|
||||
ks_assert(mp_p);
|
||||
|
||||
//if (1) return calloc(1, byte_size);
|
||||
|
||||
if (mp_p->mp_magic != KS_POOL_MAGIC) {
|
||||
if (!(mp_p->mp_flags & KS_POOL_FLAG_NO_ASSERT)) {
|
||||
abort();
|
||||
|
@ -1552,6 +1562,8 @@ KS_DECLARE(void *) ks_pool_calloc_ex(ks_pool_t *mp_p, const unsigned long ele_n,
|
|||
|
||||
ks_assert(mp_p);
|
||||
|
||||
//if (1) return calloc(ele_n, ele_size);
|
||||
|
||||
if (mp_p->mp_magic != KS_POOL_MAGIC) {
|
||||
if (!(mp_p->mp_flags & KS_POOL_FLAG_NO_ASSERT)) {
|
||||
abort();
|
||||
|
@ -1651,10 +1663,16 @@ KS_DECLARE(ks_status_t) ks_pool_free_ex(ks_pool_t *mp_p, void **addrP)
|
|||
ks_assert(addrP);
|
||||
|
||||
addr = *addrP;
|
||||
|
||||
|
||||
ks_assert(mp_p);
|
||||
ks_assert(addr);
|
||||
|
||||
//if (1) {
|
||||
// *addrP = NULL;
|
||||
// free(addr);
|
||||
// return KS_STATUS_SUCCESS;
|
||||
//}
|
||||
|
||||
ks_mutex_lock(mp_p->mutex);
|
||||
|
||||
if (mp_p->mp_magic != KS_POOL_MAGIC) {
|
||||
|
@ -1674,7 +1692,7 @@ KS_DECLARE(ks_status_t) ks_pool_free_ex(ks_pool_t *mp_p, void **addrP)
|
|||
}
|
||||
|
||||
if (mp_p->mp_log_func != NULL) {
|
||||
alloc_prefix_t *prefix = (alloc_prefix_t *) ((char *) addr - PREFIX_SIZE);
|
||||
alloc_prefix_t *prefix = (alloc_prefix_t *)((char *)addr - PREFIX_SIZE);
|
||||
if (prefix->refs == 1) {
|
||||
mp_p->mp_log_func(mp_p, KS_POOL_FUNC_FREE, prefix->size, prefix->refs - 1, NULL, addr, 0);
|
||||
} else {
|
||||
|
@ -1796,6 +1814,8 @@ KS_DECLARE(void *) ks_pool_resize_ex(ks_pool_t *mp_p, void *old_addr, const unsi
|
|||
|
||||
ks_assert(mp_p);
|
||||
//ks_assert(old_addr);
|
||||
|
||||
//if (1) return realloc(old_addr, new_byte_size);
|
||||
|
||||
if (!old_addr) {
|
||||
return ks_pool_alloc_ex(mp_p, new_byte_size, error_p);
|
||||
|
|
|
@ -101,7 +101,9 @@ static void ks_thread_cleanup(ks_pool_t *mpool, void *ptr, void *arg, int type,
|
|||
case KS_MPCL_DESTROY:
|
||||
|
||||
#ifdef WIN32
|
||||
CloseHandle(thread->handle);
|
||||
if (!(thread->flags & KS_THREAD_FLAG_DETACHED)) {
|
||||
CloseHandle(thread->handle);
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
@ -177,15 +179,16 @@ KS_DECLARE(int) ks_thread_set_priority(int nice_val)
|
|||
KS_DECLARE(uint8_t) ks_thread_priority(ks_thread_t *thread) {
|
||||
uint8_t priority = 0;
|
||||
#ifdef WIN32
|
||||
int pri = GetThreadPriority(thread->handle);
|
||||
//int pri = GetThreadPriority(thread->handle);
|
||||
|
||||
if (pri >= THREAD_PRIORITY_TIME_CRITICAL) {
|
||||
priority = 99;
|
||||
} else if (pri >= THREAD_PRIORITY_ABOVE_NORMAL) {
|
||||
priority = 50;
|
||||
} else {
|
||||
priority = 10;
|
||||
}
|
||||
//if (pri >= THREAD_PRIORITY_TIME_CRITICAL) {
|
||||
// priority = 99;
|
||||
//} else if (pri >= THREAD_PRIORITY_ABOVE_NORMAL) {
|
||||
// priority = 50;
|
||||
//} else {
|
||||
// priority = 10;
|
||||
//}
|
||||
priority = thread->priority;
|
||||
#else
|
||||
int policy;
|
||||
struct sched_param param = { 0 };
|
||||
|
@ -260,7 +263,7 @@ KS_DECLARE(ks_status_t) ks_thread_create_ex(ks_thread_t **rthread, ks_thread_fun
|
|||
}
|
||||
|
||||
if (flags & KS_THREAD_FLAG_DETACHED) {
|
||||
//CloseHandle(thread->handle);
|
||||
CloseHandle(thread->handle);
|
||||
}
|
||||
|
||||
status = KS_STATUS_SUCCESS;
|
||||
|
|
|
@ -1007,7 +1007,6 @@ KS_DECLARE(ks_ssize_t) kws_read_frame(kws_t *kws, kws_opcode_t *oc, uint8_t **da
|
|||
void *tmp;
|
||||
|
||||
kws->bbuflen = need + blen + kws->rplen;
|
||||
|
||||
if ((tmp = ks_pool_resize(kws->pool, kws->bbuffer, (unsigned long)kws->bbuflen))) {
|
||||
kws->bbuffer = tmp;
|
||||
} else {
|
||||
|
@ -1020,10 +1019,12 @@ KS_DECLARE(ks_ssize_t) kws_read_frame(kws_t *kws, kws_opcode_t *oc, uint8_t **da
|
|||
kws->rplen = kws->plen - need;
|
||||
|
||||
if (kws->rplen) {
|
||||
ks_assert((kws->body + kws->rplen) <= (kws->bbuffer + kws->bbuflen));
|
||||
memcpy(kws->body, kws->payload, kws->rplen);
|
||||
}
|
||||
|
||||
|
||||
while(need) {
|
||||
ks_assert((kws->body + need + kws->rplen) <= (kws->bbuffer + kws->bbuflen));
|
||||
ks_ssize_t r = kws_raw_read(kws, kws->body + kws->rplen, need, WS_BLOCK);
|
||||
|
||||
if (r < 1) {
|
||||
|
|
Loading…
Reference in New Issue