summaryrefslogtreecommitdiff
path: root/console-client/kbd-repeat.c
diff options
context:
space:
mode:
Diffstat (limited to 'console-client/kbd-repeat.c')
-rw-r--r--console-client/kbd-repeat.c51
1 files changed, 26 insertions, 25 deletions
diff --git a/console-client/kbd-repeat.c b/console-client/kbd-repeat.c
index b9000b22..ddfd1cf4 100644
--- a/console-client/kbd-repeat.c
+++ b/console-client/kbd-repeat.c
@@ -23,6 +23,7 @@
#include <error.h>
#include <string.h>
#include <fcntl.h>
+#include <pthread.h>
#include <sys/mman.h>
#include "kdioctl_S.h"
@@ -44,15 +45,15 @@ static struct kbdbuf
char keybuffer[KBDBUFSZ];
int pos;
size_t size;
- struct condition readcond;
- struct condition writecond;
+ pthread_cond_t readcond;
+ pthread_cond_t writecond;
} kbdbuf;
/* Wakeup for select */
-static struct condition select_alert;
+static pthread_cond_t select_alert;
/* The global lock */
-static struct mutex global_lock;
+static pthread_mutex_t global_lock;
/* Amount of times the device was opened. Normally this translator
should be only opened once. */
@@ -65,13 +66,13 @@ kbd_repeat_key (kd_event *key)
{
kd_event *ev;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
while (kbdbuf.size + sizeof (kd_event) > KBDBUFSZ)
{
/* The input buffer is full, wait until there is some space. */
- if (hurd_condition_wait (&kbdbuf.writecond, &global_lock))
+ if (pthread_hurd_cond_wait_np (&kbdbuf.writecond, &global_lock))
{
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
/* Interrupt, silently continue. */
}
}
@@ -80,9 +81,9 @@ kbd_repeat_key (kd_event *key)
kbdbuf.size += sizeof (kd_event);
memcpy (ev, key, sizeof (kd_event));
- condition_broadcast (&kbdbuf.readcond);
- condition_broadcast (&select_alert);
- mutex_unlock (&global_lock);
+ pthread_cond_broadcast (&kbdbuf.readcond);
+ pthread_cond_broadcast (&select_alert);
+ pthread_mutex_unlock (&global_lock);
}
@@ -99,22 +100,22 @@ repeater_select (struct protid *cred, mach_port_t reply,
if (*type == 0)
return 0;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
while (1)
{
if (kbdbuf.size > 0)
{
*type = SELECT_READ;
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return 0;
}
ports_interrupt_self_on_port_death (cred, reply);
- if (hurd_condition_wait (&select_alert, &global_lock))
+ if (pthread_hurd_cond_wait_np (&select_alert, &global_lock))
{
*type = 0;
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return EINTR;
}
@@ -133,18 +134,18 @@ repeater_read (struct protid *cred, char **data,
else if (! (cred->po->openstat & O_READ))
return EBADF;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
while (amount > kbdbuf.size)
{
if (cred->po->openstat & O_NONBLOCK && amount > kbdbuf.size)
{
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return EWOULDBLOCK;
}
- if (hurd_condition_wait (&kbdbuf.readcond, &global_lock))
+ if (pthread_hurd_cond_wait_np (&kbdbuf.readcond, &global_lock))
{
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return EINTR;
}
}
@@ -160,7 +161,7 @@ repeater_read (struct protid *cred, char **data,
*data = mmap (0, amount, PROT_READ|PROT_WRITE, MAP_ANON, 0, 0);
if (*data == MAP_FAILED)
{
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return ENOMEM;
}
}
@@ -174,11 +175,11 @@ repeater_read (struct protid *cred, char **data,
kbdbuf.pos = KBDBUF_POS (kbdbuf.pos);
}
kbdbuf.size -= amount;
- condition_broadcast (&kbdbuf.writecond);
+ pthread_cond_broadcast (&kbdbuf.writecond);
}
*datalen = amount;
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return 0;
}
@@ -228,11 +229,11 @@ kbd_setrepeater (const char *nodename, consnode_t *cn)
(*cn)->close = repeater_close;
(*cn)->demuxer = kdioctl_server;
- mutex_init (&global_lock);
+ pthread_mutex_init (&global_lock, NULL);
- condition_init (&kbdbuf.readcond);
- condition_init (&kbdbuf.writecond);
- condition_init (&select_alert);
+ pthread_cond_init (&kbdbuf.readcond, NULL);
+ pthread_cond_init (&kbdbuf.writecond, NULL);
+ pthread_cond_init (&select_alert, NULL);
console_register_consnode (*cn);