#include <stdio.h>
#include "rlm_eap.h"
+#ifdef HAVE_PTHREAD_H
+#define PTHREAD_MUTEX_LOCK pthread_mutex_lock
+#define PTHREAD_MUTEX_UNLOCK pthread_mutex_unlock
+#else
+#define PTHREAD_MUTEX_LOCK(_x)
+#define PTHREAD_MUTEX_UNLOCK(_x)
+#endif
+
/*
* Allocate a new EAP_PACKET
*/
memset(handler, 0, sizeof(EAP_HANDLER));
if (fr_debug_flag && inst->handler_tree) {
- pthread_mutex_lock(&(inst->handler_mutex));
+ PTHREAD_MUTEX_LOCK(&(inst->handler_mutex));
rbtree_insert(inst->handler_tree, handler);
- pthread_mutex_unlock(&(inst->handler_mutex));
+ PTHREAD_MUTEX_UNLOCK(&(inst->handler_mutex));
}
return handler;
return;
if (inst->handler_tree) {
- pthread_mutex_lock(&(inst->handler_mutex));
+ PTHREAD_MUTEX_LOCK(&(inst->handler_mutex));
rbtree_deletebydata(inst->handler_tree, handler);
- pthread_mutex_unlock(&(inst->handler_mutex));
+ PTHREAD_MUTEX_UNLOCK(&(inst->handler_mutex));
}
if (handler->identity) {
return;
}
- pthread_mutex_lock(&(check->inst->handler_mutex));
+ PTHREAD_MUTEX_LOCK(&(check->inst->handler_mutex));
if (!rbtree_finddata(check->inst->handler_tree, check->handler)) {
goto done;
}
}
done:
- pthread_mutex_unlock(&(check->inst->handler_mutex));
+ PTHREAD_MUTEX_UNLOCK(&(check->inst->handler_mutex));
free(check);
if (do_warning) {
* Playing with a data structure shared among threads
* means that we need a lock, to avoid conflict.
*/
- pthread_mutex_lock(&(inst->session_mutex));
+ PTHREAD_MUTEX_LOCK(&(inst->session_mutex));
/*
* If we have a DoS attack, discard new sessions.
*/
if (status > 0) handler->request = NULL;
- pthread_mutex_unlock(&(inst->session_mutex));
+ PTHREAD_MUTEX_UNLOCK(&(inst->session_mutex));
if (status <= 0) {
pairfree(&state);
* Playing with a data structure shared among threads
* means that we need a lock, to avoid conflict.
*/
- pthread_mutex_lock(&(inst->session_mutex));
+ PTHREAD_MUTEX_LOCK(&(inst->session_mutex));
eaplist_expire(inst, request->timestamp);
handler = eaplist_delete(inst, &myHandler);
- pthread_mutex_unlock(&(inst->session_mutex));
+ PTHREAD_MUTEX_UNLOCK(&(inst->session_mutex));
/*
* Might not have been there.
inst = (rlm_eap_t *)instance;
+#ifdef HAVE_PTHREAD_H
+ pthread_mutex_destroy(&(inst->session_mutex));
+ if (inst->handler_tree) pthread_mutex_destroy(&(inst->handler_mutex));
+#endif
+
rbtree_free(inst->session_tree);
if (inst->handler_tree) rbtree_free(inst->handler_tree);
inst->session_tree = NULL;
inst->types[i] = NULL;
}
- pthread_mutex_destroy(&(inst->session_mutex));
- if (fr_debug_flag) pthread_mutex_destroy(&(inst->handler_mutex));
-
free(inst);
return 0;
return -1;
}
+#ifdef HAVE_PTHREAD_H
if (pthread_mutex_init(&(inst->handler_mutex), NULL) < 0) {
radlog(L_ERR|L_CONS, "rlm_eap: Failed initializing mutex: %s", strerror(errno));
eap_detach(inst);
return -1;
}
+#endif
}
+#ifdef HAVE_PTHREAD_H
if (pthread_mutex_init(&(inst->session_mutex), NULL) < 0) {
radlog(L_ERR|L_CONS, "rlm_eap: Failed initializing mutex: %s", strerror(errno));
eap_detach(inst);
return -1;
}
+#endif
*instance = inst;
return 0;