#include <mach/mach_time.h>
#endif
-
/* Recent absolute time of day */
struct timeval recent_time;
static struct timeval last_recent_time;
return FD_ISSET (fd, fdset);
}
-static int
-fd_set_read_write (int fd, thread_fd_set *fdset)
-{
- if (FD_ISSET (fd, fdset))
- return 0;
-
- FD_SET (fd, fdset);
-
- return 1;
-}
-
static int
fd_clear_read_write (int fd, thread_fd_set *fdset)
{
/* Add new read thread. */
struct thread *
-funcname_thread_add_read (struct thread_master *m,
- int (*func) (struct thread *), void *arg, int fd, const char* funcname)
+funcname_thread_add_read_write (int dir, struct thread_master *m,
+ int (*func) (struct thread *), void *arg, int fd, const char* funcname)
{
- struct thread *thread;
+ struct thread *thread = NULL;
+ thread_fd_set *fdset = NULL;
- assert (m != NULL);
+ if (dir == THREAD_READ)
+ fdset = &m->readfd;
+ else
+ fdset = &m->writefd;
- if (!fd_set_read_write (fd, &m->readfd))
+ if (FD_ISSET (fd, fdset))
{
- zlog (NULL, LOG_WARNING, "There is already read fd [%d]", fd);
+ zlog (NULL, LOG_WARNING, "There is already %s fd [%d]", (dir = THREAD_READ) ? "read" : "write", fd);
return NULL;
}
- thread = thread_get (m, THREAD_READ, func, arg, funcname);
- thread->u.fd = fd;
- thread_add_fd (m->read, thread);
-
- return thread;
-}
-
-/* Add new write thread. */
-struct thread *
-funcname_thread_add_write (struct thread_master *m,
- int (*func) (struct thread *), void *arg, int fd, const char* funcname)
-{
- struct thread *thread;
-
- assert (m != NULL);
-
- if (!fd_set_read_write (fd, &m->writefd))
- {
- zlog (NULL, LOG_WARNING, "There is already write fd [%d]", fd);
- return NULL;
- }
+ FD_SET (fd, fdset);
- thread = thread_get (m, THREAD_WRITE, func, arg, funcname);
+ thread = thread_get (m, dir, func, arg, funcname);
thread->u.fd = fd;
- thread_add_fd (m->write, thread);
+ if (dir == THREAD_READ)
+ thread_add_fd (m->read, thread);
+ else
+ thread_add_fd (m->write, thread);
return thread;
}
#define THREAD_WRITE_OFF(thread) THREAD_OFF(thread)
#define THREAD_TIMER_OFF(thread) THREAD_OFF(thread)
-#define thread_add_read(m,f,a,v) funcname_thread_add_read(m,f,a,v,#f)
-#define thread_add_write(m,f,a,v) funcname_thread_add_write(m,f,a,v,#f)
+#define thread_add_read(m,f,a,v) funcname_thread_add_read_write(THREAD_READ,m,f,a,v,#f)
+#define thread_add_write(m,f,a,v) funcname_thread_add_read_write(THREAD_WRITE,m,f,a,v,#f)
#define thread_add_timer(m,f,a,v) funcname_thread_add_timer(m,f,a,v,#f)
#define thread_add_timer_msec(m,f,a,v) funcname_thread_add_timer_msec(m,f,a,v,#f)
#define thread_add_event(m,f,a,v) funcname_thread_add_event(m,f,a,v,#f)
extern void thread_master_free (struct thread_master *);
extern void thread_master_free_unused(struct thread_master *);
-extern struct thread *funcname_thread_add_read (struct thread_master *,
+extern struct thread *funcname_thread_add_read_write (int dir, struct thread_master *,
int (*)(struct thread *),
void *, int, const char*);
-extern struct thread *funcname_thread_add_write (struct thread_master *,
- int (*)(struct thread *),
- void *, int, const char*);
extern struct thread *funcname_thread_add_timer (struct thread_master *,
int (*)(struct thread *),
void *, long, const char*);