14 #define _XOPEN_SOURCE 700
21 #define sion_assert(expr, args) (assert(expr))
35 int (*user_lock)(
void *);
36 int (*user_unlock)(
void *);
45 #ifdef SION_USE_PTHREADS
49 #define _USE_NOT_PTHREADS
54 #define SION_FDDATA_INITIALIZER {PTHREAD_MUTEX_INITIALIZER}
56 #define SION_FDDATA_INITIALIZER {}
60 static struct _sion_lockdata {
62 } sion_lockdata = SION_FDDATA_INITIALIZER;
65 int _sion_lock_register_lock_callbacks(
int lock(
void *),
int unlock(
void *),
void *lock_data) {
66 int rc = SION_SUCCESS;
70 DPRINTFP((2,
"_sion_lock_register_lock_callbacks", _SION_DEFAULT_RANK,
"enter\n"));
71 if(_sion_lock_user_cb.lock_defined==1) {
74 _sion_lock_user_cb.lock_defined=1;
75 _sion_lock_user_cb.user_lock=lock;
76 _sion_lock_user_cb.user_unlock=unlock;
77 _sion_lock_user_cb.user_lock_data=lock_data;
79 DPRINTFP((2,
"_sion_lock_register_lock_callbacks", _SION_DEFAULT_RANK,
"lock and unlock function defined, rc=%d\n",rc));
86 int _sion_lock_user_callbacks_defined(
void) {
89 rc=_sion_lock_user_cb.lock_defined;
91 DPRINTFP((2,
"_sion_lock_user_callbacks_defined", _SION_DEFAULT_RANK,
"check user lock cbs, rc=%d\n",rc));
97 int _sion_lock(
void) {
99 if(_sion_lock_user_cb.lock_defined==1) {
100 _sion_lock_user_cb.user_lock(_sion_lock_user_cb.user_lock_data);
102 if(pthread_mutex_lock(&sion_lockdata.lock)) {
109 int _sion_unlock(
void) {
111 if(_sion_lock_user_cb.lock_defined==1) {
112 _sion_lock_user_cb.user_unlock(_sion_lock_user_cb.user_lock_data);
114 if(pthread_mutex_unlock(&sion_lockdata.lock)) {
123 int _sion_lock(
void) {
124 if(_sion_lock_user_cb.lock_defined==1) {
125 _sion_lock_user_cb.user_lock(_sion_lock_user_cb.user_lock_data);
127 return(SION_SUCCESS);
129 int _sion_unlock(
void) {
130 if(_sion_lock_user_cb.lock_defined==1) {
131 _sion_lock_user_cb.user_unlock(_sion_lock_user_cb.user_lock_data);
133 return(SION_SUCCESS);
callback wrappers for OMP thread safe fd manipulation