#include <pexpert/pexpert.h>
/* XXX should be in a common header somewhere */
-extern void klogwakeup(void);
extern void logwakeup(void);
#define LOG_RDPRI (PZERO + 1)
#define LOG_ASYNC 0x04
#define LOG_RDWAIT 0x08
+#define MAX_UNREAD_CHARS (CONFIG_MSG_BSIZE/2)
/* All globals should be accessed under LOG_LOCK() */
/* logsoftc only valid while log_open=1 */
int log_open; /* also used in log() */
char smsg_bufc[CONFIG_MSG_BSIZE]; /* static buffer */
struct msgbuf msgbuf = {MSG_MAGIC,sizeof(smsg_bufc),0,0,smsg_bufc};
-struct msgbuf *msgbufp = &msgbuf;
-static int logentrypend = 0;
+struct msgbuf *msgbufp __attribute__((used)) = &msgbuf;
/* the following are implemented in osfmk/kern/printf.c */
extern void bsd_log_lock(void);
logsoftc.sc_state |= LOG_RDWAIT;
LOG_UNLOCK();
/*
- * If the wakeup is missed the ligtening bolt will wake this up
- * if there are any new characters. If that doesn't do it
+ * If the wakeup is missed
* then wait for 5 sec and reevaluate
*/
if ((error = tsleep((caddr_t)msgbufp, LOG_RDPRI | PCATCH,
LOG_UNLOCK();
}
-void
-klogwakeup(void)
-{
- LOG_LOCK();
- if (logentrypend && log_open) {
- logentrypend = 0; /* only reset if someone will be reading */
- LOG_UNLOCK();
- logwakeup();
- } else {
- LOG_UNLOCK();
- }
-}
/*ARGSUSED*/
int
mbp = msgbufp;
mbp->msg_bufc[mbp->msg_bufx++] = c;
- logentrypend = 1;
if (mbp->msg_bufx >= msgbufp->msg_size)
mbp->msg_bufx = 0;
}
void
log_putc(char c)
{
+ int unread_count = 0;
LOG_LOCK();
log_putc_locked(c);
+ unread_count = msgbufp->msg_bufx - msgbufp->msg_bufr;
LOG_UNLOCK();
+
+ if (unread_count < 0)
+ unread_count = 0 - unread_count;
+ if (c == '\n' || unread_count >= MAX_UNREAD_CHARS)
+ logwakeup();
}