mirror of https://github.com/yandex/odyssey.git
machinarium: free coroutine on cache limit reach
This commit is contained in:
parent
8136104e31
commit
65b65fcad7
|
@ -49,6 +49,11 @@ void mm_coroutine_cache_push(mm_coroutine_cache_t *cache, mm_coroutine_t *corout
|
||||||
{
|
{
|
||||||
assert(coroutine->state == MM_CFREE);
|
assert(coroutine->state == MM_CFREE);
|
||||||
pthread_spin_lock(&cache->lock);
|
pthread_spin_lock(&cache->lock);
|
||||||
|
if (cache->count > cache->limit) {
|
||||||
|
pthread_spin_unlock(&cache->lock);
|
||||||
|
mm_coroutine_free(coroutine);
|
||||||
|
return;
|
||||||
|
}
|
||||||
mm_list_append(&cache->list, &coroutine->link);
|
mm_list_append(&cache->list, &coroutine->link);
|
||||||
cache->count++;
|
cache->count++;
|
||||||
pthread_spin_unlock(&cache->lock);
|
pthread_spin_unlock(&cache->lock);
|
||||||
|
|
|
@ -153,8 +153,10 @@ machine_coroutine_create(machine_coroutine_t function, void *arg)
|
||||||
mm_errno_set(0);
|
mm_errno_set(0);
|
||||||
mm_coroutine_t *coroutine;
|
mm_coroutine_t *coroutine;
|
||||||
coroutine = mm_coroutine_cache_pop(&machinarium.coroutine_cache);
|
coroutine = mm_coroutine_cache_pop(&machinarium.coroutine_cache);
|
||||||
if (coroutine == NULL)
|
if (coroutine == NULL) {
|
||||||
|
mm_errno_set(ENOMEM);
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
mm_scheduler_new(&mm_self->scheduler, coroutine, function, arg);
|
mm_scheduler_new(&mm_self->scheduler, coroutine, function, arg);
|
||||||
return coroutine->id;
|
return coroutine->id;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue