piaodazhu / dyco-coroutine

☄️ Dynamic Coroutine Framework for C. A user-friendly but powerful coroutine framework. Features include but are not limited to Socket, SSL, Channel, semaphore, waitgroup and multi-thread.
GNU General Public License v3.0
81 stars 4 forks source link

The parameter value of the `dyco_semaphore_create` can be `0` #4

Closed echoechoin closed 1 year ago

echoechoin commented 1 year ago
dyco_semaphore* dyco_semaphore_create(size_t value)
{
-   if (value == 0) return NULL;
+       if (value < 0) return NULL;
    dyco_semaphore *sem = (dyco_semaphore*)malloc(sizeof(dyco_semaphore));
    if (sem == NULL)
        return NULL;
    sem->semval = value;
    sem->wqueue = NULL;
    sem->wtail = NULL;
    return sem;
}

The initial value of the semaphore can be either a positive value (i.e., greater than zero) indicating an unlocked semaphore or a value of 0 (zero) indicating a locked semaphore.

refers to https://www.qnx.com/developers/docs/6.4.0/neutrino/lib_ref/s/sem_init.html

piaodazhu commented 1 year ago

size_t is an unsigned integer, so value < 0 will never happen. And we can define SEM_VALUE_MAX to limit the max of value.

Could you modify this PR so that I can merge it?

It's awkward that these parts (semaphore, channel, pool) lack testing and may have some bugs...

echoechoin commented 1 year ago

No problem, I will fix it.

echoechoin commented 1 year ago

just for learn coroutine and raise some issues by the way.

piaodazhu commented 1 year ago

It has been merged.