#include <stdlib.h>
#include <unistd.h>
#include <string.h>
+#ifndef __CYGWIN__
+#include <syscall.h>
+#endif
+#include <sys/socket.h>
#include <procbridge.h>
#include <pqtimer.h>
#include <dispatch.h>
#include <errno.h>
+/* XXX CFS workaround, to give a chance to let nal thread wake up
+ * from waiting in select
+ */
+static int procbridge_notifier_handler(void *arg)
+{
+ static char buf[8];
+ procbridge p = (procbridge) arg;
+
+ syscall(SYS_read, p->notifier[1], buf, sizeof(buf));
+ return 1;
+}
+
+void procbridge_wakeup_nal(procbridge p)
+{
+ static char buf[8];
+ syscall(SYS_write, p->notifier[0], buf, sizeof(buf));
+}
+
/* Function: forward
* Arguments: nal_t *nal: pointer to my top-side nal structure
* id: the command to pass to the lower layer
procbridge p=(procbridge)b->local;
p->nal_flags |= NAL_FLAG_STOPPING;
+ procbridge_wakeup_nal(p);
do {
pthread_mutex_lock(&p->mutex);
}
+/* FIXME cfs temporary workaround! FIXME
+ * global time out value
+ */
+int __tcpnal_eqwait_timeout_value = 0;
+int __tcpnal_eqwait_timedout = 0;
+
/* Function: yield
* Arguments: pid:
*
procbridge p=(procbridge)b->local;
pthread_mutex_lock(&p->mutex);
- pthread_cond_wait(&p->cond,&p->mutex);
+ if (!__tcpnal_eqwait_timeout_value) {
+ pthread_cond_wait(&p->cond,&p->mutex);
+ } else {
+ struct timeval now;
+ struct timespec timeout;
+
+ gettimeofday(&now, NULL);
+ timeout.tv_sec = now.tv_sec + __tcpnal_eqwait_timeout_value;
+ timeout.tv_nsec = now.tv_usec * 1000;
+
+ __tcpnal_eqwait_timedout =
+ pthread_cond_timedwait(&p->cond, &p->mutex, &timeout);
+ }
pthread_mutex_unlock(&p->mutex);
}
p->nal_flags = 0;
pthread_mutex_init(&p->nal_cb_lock, 0);
+ /* initialize notifier */
+ if (socketpair(AF_UNIX, SOCK_STREAM, 0, p->notifier)) {
+ perror("socketpair failed");
+ return NULL;
+ }
+
+ if (!register_io_handler(p->notifier[1], READ_HANDLER,
+ procbridge_notifier_handler, p)) {
+ perror("fail to register notifier handler");
+ return NULL;
+ }
+
+ /* create nal thread */
if (pthread_create(&p->t, NULL, nal_thread, &args)) {
perror("nal_init: pthread_create");
return(NULL);