Init commit of jobs output/error message peek project.

This commit is contained in:
Lei Chen 2026-05-09 16:57:54 +08:00
parent c772d7e601
commit d2b47e3985
38 changed files with 2267 additions and 21 deletions

View file

@ -187,6 +187,32 @@ int cbuf_tryget(cbuf_t* b, void* it)
return rc;
}
int cbuf_timedget(cbuf_t* b, void* it, const struct timespec* deadline)
{
if ((b == NULL) || (it == NULL) || (deadline == NULL)) {
return -EINVAL;
}
pthread_mutex_lock(&(b->mutex));
while (b->len == 0) {
int rc = pthread_cond_timedwait(&(b->condget), &(b->mutex), deadline);
if (rc == ETIMEDOUT) {
pthread_mutex_unlock(&(b->mutex));
return -ETIMEDOUT;
}
}
memcpy(it, (void*)((char*)b->data) + b->isize * b->head, b->isize);
b->head = (b->head + 1) % b->ncap;
b->len--;
pthread_cond_signal(&(b->condput));
pthread_mutex_unlock(&(b->mutex));
return 0;
}
int my_rwlock_init(my_rwlock_t* l)
{
if (l == NULL) {