Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions common/cancellation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Phoenix-RTOS
*
* libphoenix
*
* Cancellation point handling
*
* Copyright 2026 Phoenix Systems
* Author: Adam Greloch
*
* SPDX-License-Identifier: BSD-3-Clause
*/

#ifndef _LIBPHOENIX_WRAP_CANCEL_H_
#define _LIBPHOENIX_WRAP_CANCEL_H_

#include <pthread.h>

#define CANCELLATION_POINT(rettype, function, args) ({ \
int __oldval = _pthread_enable_asynccancel(); \
rettype __ret = function args; \
_pthread_disable_asynccancel(__oldval); \
__ret; \
})


#define WRAP_ERRNO_DEF_CANCELLATION(rettype, function, arguments, argnames) \
extern rettype sys_##function arguments; \
rettype function arguments \
{ \
return SET_ERRNO(CANCELLATION_POINT(rettype, sys_##function, argnames)); \
}


#define WRAP_CANCELLATION(rettype, function, arguments, argnames) \
extern rettype sys_##function arguments; \
rettype function arguments \
{ \
return CANCELLATION_POINT(rettype, sys_##function, argnames); \
}

#endif
24 changes: 23 additions & 1 deletion include/pthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ extern "C" {

#define PTHREAD_CANCEL_DISABLE 0
#define PTHREAD_CANCEL_ENABLE 1
#define PTHREAD_CANCELED 2

#define PTHREAD_CANCELED ((void *)-1)

#define PTHREAD_CANCEL_DEFERRED 0
#define PTHREAD_CANCEL_ASYNCHRONOUS 1

/* clang-format off */
#define PTHREAD_MUTEX_INITIALIZER { 0, 0 }
Expand All @@ -78,6 +82,9 @@ int pthread_detach(pthread_t thread);
int pthread_setcancelstate(int state, int *oldstate);


int pthread_setcanceltype(int type, int *oldtype);


int pthread_cancel(pthread_t thread);


Expand Down Expand Up @@ -293,6 +300,21 @@ void _pthread_atfork_parent(void);
void _pthread_atfork_child(void);


void _pthread_fork_child_reinit(pthread_t self);


void _pthread_nocancel_begin(void);


void _pthread_nocancel_end(void);


int _pthread_enable_asynccancel(void);


void _pthread_disable_asynccancel(int oldval);


void pthread_cleanup_push(void (*routine)(void *), void *arg);


Expand Down
Loading
Loading