summaryrefslogtreecommitdiff
path: root/libvxi11client/libvxi11client.c
diff options
context:
space:
mode:
authordaniel <danieruru@gmail.com>2013-01-10 20:08:21 +0900
committerdaniel <danieruru@gmail.com>2013-01-10 20:08:21 +0900
commitb38f3285a31547b528c0767bc268242ad0bed7fa (patch)
tree01c346f22dcebe42ba4b934b8d460cd3b9f265bc /libvxi11client/libvxi11client.c
parent845db4b79f9b72592e662a6daa5917f84ff12e04 (diff)
More interrupt channel bits
Diffstat (limited to 'libvxi11client/libvxi11client.c')
-rw-r--r--libvxi11client/libvxi11client.c40
1 files changed, 31 insertions, 9 deletions
diff --git a/libvxi11client/libvxi11client.c b/libvxi11client/libvxi11client.c
index d0eef3d..7c7878c 100644
--- a/libvxi11client/libvxi11client.c
+++ b/libvxi11client/libvxi11client.c
@@ -26,6 +26,14 @@
static CLIENT* clnt = NULL;
static CLIENT* abortclnt = NULL;
static Device_Link link;
+static GThread* interruptthread;
+static bool interruptchannelopen = false;
+
+static void killinterruptthreadandwait() {
+ interruptchannelopen = false;
+ g_thread_join(interruptthread);
+ interruptthread = NULL;
+}
void *
device_intr_srq_1_svc(Device_SrqParms *argp, struct svc_req *rqstp) {
@@ -359,7 +367,7 @@ static gpointer interruptthreadfunc(gpointer data) {
//svc_run();
// stolen from: http://pic.dhe.ibm.com/infocenter/aix/v6r1/index.jsp?topic=%2Fcom.ibm.aix.commtechref%2Fdoc%2Fcommtrf1%2Fsvc_getreq_poll.htm
- while (1) {
+ while (interruptchannelopen) {
/* initialize the pollfd_set array and
get no of file descriptors in "no_of_fds"*/
@@ -384,17 +392,20 @@ static gpointer interruptthreadfunc(gpointer data) {
* create an interrupt channel from the connected device
*/
int vxi11_create_intr_chan() {
- if (clnt == NULL)
+ if (interruptchannelopen)
+ return 0;
+ else if (clnt == NULL)
+ return 0;
+ else if (interruptthread != NULL)
return 0;
+ interruptchannelopen = true;
u_short port = 0;
g_thread_init(NULL);
- GThread* interruptthread = g_thread_create(interruptthreadfunc, &port, false, NULL);
+ interruptthread = g_thread_create(interruptthreadfunc, &port, true, NULL);
sleep(2);
- //
-
struct sockaddr_in myaddress;
get_myaddress(&myaddress);
@@ -403,10 +414,14 @@ int vxi11_create_intr_chan() {
Device_Error* error = create_intr_chan_1(&remotefunc, clnt);
if (error != NULL && error->error == 0)
return 1;
- else if (error == NULL)
+ else if (error == NULL) {
+ killinterruptthreadandwait();
return 0;
- else
+ }
+ else {
+ killinterruptthreadandwait();
return -(error->error);
+ }
}
/**
@@ -414,11 +429,18 @@ int vxi11_create_intr_chan() {
*/
int vxi11_destroy_intr_chan() {
- if (clnt == NULL)
+ if (!interruptchannelopen)
+ return 0;
+ else if (clnt == NULL)
return 0;
+ else if (interruptthread == NULL)
+ return 0;
+
Device_Error* error = destroy_intr_chan_1(NULL, clnt);
- if (error != NULL && error->error == 0)
+ if (error != NULL && error->error == 0) {
+ killinterruptthreadandwait();
return 1;
+ }
else if (error == NULL)
return 0;
else