/branches/rcu/uspace/libc/include/async.h |
---|
116,12 → 116,13 |
void async_msg_3(int phoneid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2, |
ipcarg_t arg3); |
void async_msg_2(int phoneid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2); |
#define async_msg(ph,m,a1) async_msg_2(ph,m,a1,0) |
#define async_msg(ph, m, a1) async_msg_2(ph, m, a1, 0) |
static inline void async_serialize_start(void) |
{ |
psthread_inc_sercount(); |
} |
static inline void async_serialize_end(void) |
{ |
psthread_dec_sercount(); |
/branches/rcu/uspace/libc/include/unistd.h |
---|
44,8 → 44,9 |
extern ssize_t write(int fd, const void * buf, size_t count); |
extern ssize_t read(int fd, void * buf, size_t count); |
extern void _exit(int status); |
void *sbrk(ssize_t incr); |
void usleep(unsigned long usec); |
extern void *sbrk(ssize_t incr); |
extern void usleep(unsigned long usec); |
extern unsigned int sleep(unsigned int seconds); |
#endif |
/branches/rcu/uspace/libc/include/thread.h |
---|
39,11 → 39,16 |
#include <libarch/thread.h> |
#include <types.h> |
typedef uint64_t thread_id_t; |
extern void __thread_entry(void); |
extern void __thread_main(uspace_arg_t *uarg); |
extern int thread_create(void (* function)(void *arg), void *arg, char *name); |
extern int thread_create(void (* function)(void *), void *arg, char *name, thread_id_t *tid); |
extern void thread_exit(int status); |
extern void thread_detach(thread_id_t thread); |
extern int thread_join(thread_id_t thread); |
extern thread_id_t thread_get_id(void); |
extern tcb_t * __make_tls(void); |
extern tcb_t * __alloc_tls(void **data, size_t size); |
extern void __free_tls(tcb_t *); |
/branches/rcu/uspace/libc/generic/time.c |
---|
108,14 → 108,31 |
return 0; |
} |
/** Wait unconditionally for specified microseconds */ |
/** Wait unconditionally for specified number of microseconds */ |
void usleep(unsigned long usec) |
{ |
atomic_t futex = FUTEX_INITIALIZER; |
futex_initialize(&futex,0); |
futex_initialize(&futex, 0); |
futex_down_timeout(&futex, usec, 0); |
} |
/** Wait unconditionally for specified number of seconds */ |
unsigned int sleep(unsigned int seconds) |
{ |
atomic_t futex = FUTEX_INITIALIZER; |
futex_initialize(&futex, 0); |
/* Sleep in 1000 second steps to support |
full argument range */ |
while (seconds > 0) { |
unsigned int period = (seconds > 1000) ? 1000 : seconds; |
futex_down_timeout(&futex, period * 1000000, 0); |
seconds -= period; |
} |
} |
/** @} |
*/ |
/branches/rcu/uspace/libc/generic/thread.c |
---|
124,10 → 124,11 |
* @param function Function implementing the thread. |
* @param arg Argument to be passed to thread. |
* @param name Symbolic name of the thread. |
* @param tid Thread ID of the newly created thread. |
* |
* @return TID of the new thread on success or -1 on failure. |
* @return Zero on success or a code from @ref errno.h on failure. |
*/ |
int thread_create(void (* function)(void *), void *arg, char *name) |
int thread_create(void (* function)(void *), void *arg, char *name, thread_id_t *tid) |
{ |
char *stack; |
uspace_arg_t *uarg; |
148,7 → 149,7 |
uarg->uspace_thread_arg = arg; |
uarg->uspace_uarg = uarg; |
return __SYSCALL2(SYS_THREAD_CREATE, (sysarg_t) uarg, (sysarg_t) name); |
return __SYSCALL3(SYS_THREAD_CREATE, (sysarg_t) uarg, (sysarg_t) name, (sysarg_t) tid); |
} |
/** Terminate current thread. |
160,5 → 161,40 |
__SYSCALL1(SYS_THREAD_EXIT, (sysarg_t) status); |
} |
/** Detach thread. |
* |
* Currently not implemented. |
* |
* @param thread TID. |
*/ |
void thread_detach(thread_id_t thread) |
{ |
} |
/** Join thread. |
* |
* Currently not implemented. |
* |
* @param thread TID. |
* |
* @return Thread exit status. |
*/ |
int thread_join(thread_id_t thread) |
{ |
} |
/** Get current thread ID. |
* |
* @return Current thread ID. |
*/ |
thread_id_t thread_get_id(void) |
{ |
thread_id_t thread_id; |
(void) __SYSCALL1(SYS_THREAD_GET_ID, (sysarg_t) &thread_id); |
return thread_id; |
} |
/** @} |
*/ |
/branches/rcu/uspace/libc/generic/io/printf.c |
---|
56,5 → 56,3 |
/** @} |
*/ |
/branches/rcu/uspace/libc/generic/io/io.c |
---|
37,18 → 37,17 |
#include <stdio.h> |
#include <io/io.h> |
static char nl = '\n'; |
const static char nl = '\n'; |
int puts(const char * str) |
int puts(const char *str) |
{ |
size_t count; |
if (str == NULL) { |
return putnchars("(NULL)",6 ); |
} |
if (str == NULL) |
return putnchars("(NULL)", 6); |
for (count = 0; str[count] != 0; count++); |
if (write(1, (void * ) str, count) == count) { |
if (write(1, (void *) str, count) == count) { |
if (write(1, &nl, 1) == 1) |
return 0; |
} |
61,11 → 60,10 |
* @param count |
* @return 0 on succes, EOF on fail |
*/ |
int putnchars(const char * buf, size_t count) |
int putnchars(const char *buf, size_t count) |
{ |
if (write(1, (void * ) buf, count) == count) { |
if (write(1, (void *) buf, count) == count) |
return 0; |
} |
return EOF; |
} |
73,18 → 71,16 |
/** Same as puts, but does not print newline at end |
* |
*/ |
int putstr(const char * str) |
int putstr(const char *str) |
{ |
size_t count; |
if (str == NULL) { |
return putnchars("(NULL)",6 ); |
} |
if (str == NULL) |
return putnchars("(NULL)", 6); |
for (count = 0; str[count] != 0; count++); |
if (write(1, (void * ) str, count) == count) { |
if (write(1, (void *) str, count) == count) |
return 0; |
} |
return EOF; |
} |
92,9 → 88,8 |
int putchar(int c) |
{ |
unsigned char ch = c; |
if (write(1, (void *)&ch , 1) == 1) { |
if (write(1, (void *) &ch, 1) == 1) |
return c; |
} |
return EOF; |
} |
102,9 → 97,8 |
int getchar(void) |
{ |
unsigned char c; |
if (read(0, (void *)&c , 1) == 1) { |
if (read(0, (void *) &c, 1) == 1) |
return c; |
} |
return EOF; |
} |
/branches/rcu/uspace/libc/generic/io/vprintf.c |
---|
36,10 → 36,12 |
#include <stdio.h> |
#include <unistd.h> |
#include <io/printf_core.h> |
#include <futex.h> |
#include <async.h> |
int vprintf_write(const char *str, size_t count, void *unused); |
static atomic_t printf_futex = FUTEX_INITIALIZER; |
int vprintf_write(const char *str, size_t count, void *unused) |
static int vprintf_write(const char *str, size_t count, void *unused) |
{ |
return write(1, str, count); |
} |
51,9 → 53,23 |
*/ |
int vprintf(const char *fmt, va_list ap) |
{ |
struct printf_spec ps = {(int(*)(void *, size_t, void *))vprintf_write, NULL}; |
return printf_core(fmt, &ps, ap); |
struct printf_spec ps = { |
(int (*)(void *, size_t, void *)) vprintf_write, |
NULL |
}; |
/* |
* Prevent other threads to execute printf_core() |
*/ |
futex_down(&printf_futex); |
/* |
* Prevent other pseudo threads of the same thread |
* to execute printf_core() |
*/ |
async_serialize_start(); |
int ret = printf_core(fmt, &ps, ap); |
async_serialize_end(); |
futex_up(&printf_futex); |
return ret; |
} |
/** @} |
/branches/rcu/uspace/libc/generic/io/vsnprintf.c |
---|
43,8 → 43,6 |
char *string; /* destination string */ |
}; |
int vsnprintf_write(const char *str, size_t count, struct vsnprintf_data *data); |
/** Write string to given buffer. |
* Write at most data->size characters including trailing zero. According to C99 has snprintf to return number |
* of characters that would have been written if enough space had been available. Hence the return value is not |
55,7 → 53,7 |
* @param data structure with destination string, counter of used space and total string size. |
* @return number of characters to print (not characters really printed!) |
*/ |
int vsnprintf_write(const char *str, size_t count, struct vsnprintf_data *data) |
static int vsnprintf_write(const char *str, size_t count, struct vsnprintf_data *data) |
{ |
size_t i; |
i = data->size - data->len; |
97,7 → 95,7 |
int vsnprintf(char *str, size_t size, const char *fmt, va_list ap) |
{ |
struct vsnprintf_data data = {size, 0, str}; |
struct printf_spec ps = {(int(*)(void *, size_t, void *))vsnprintf_write, &data}; |
struct printf_spec ps = {(int(*)(void *, size_t, void *)) vsnprintf_write, &data}; |
/* Print 0 at end of string - fix the case that nothing will be printed */ |
if (size > 0) |
/branches/rcu/uspace/libc/generic/io/printf_core.c |
---|
40,8 → 40,6 |
#include <io/printf_core.h> |
#include <ctype.h> |
#include <string.h> |
/* For serialization */ |
#include <async.h> |
#define __PRINTF_FLAG_PREFIX 0x00000001 /**< show prefixes 0x or 0*/ |
#define __PRINTF_FLAG_SIGNED 0x00000002 /**< signed / unsigned number */ |
92,15 → 90,13 |
{ |
size_t count; |
if (str == NULL) { |
if (str == NULL) |
return printf_putnchars("(NULL)", 6, ps); |
} |
for (count = 0; str[count] != 0; count++); |
if (ps->write((void *) str, count, ps->data) == count) { |
if (ps->write((void *) str, count, ps->data) == count) |
return 0; |
} |
return EOF; |
} |
447,9 → 443,6 |
int width, precision; |
uint64_t flags; |
/* Don't let other threads interfere */ |
async_serialize_start(); |
counter = 0; |
while ((c = fmt[i])) { |
681,10 → 674,8 |
counter += retval; |
} |
async_serialize_end(); |
return counter; |
minus_out: |
async_serialize_end(); |
return -counter; |
} |
/branches/rcu/uspace/libc/generic/io/vsprintf.c |
---|
44,7 → 44,7 |
*/ |
int vsprintf(char *str, const char *fmt, va_list ap) |
{ |
return vsnprintf(str, (size_t)-1, fmt, ap); |
return vsnprintf(str, (size_t) - 1, fmt, ap); |
} |
/** @} |
/branches/rcu/uspace/libc/arch/sparc64/include/atomic.h |
---|
51,9 → 51,11 |
uint64_t a, b; |
do { |
a = val->count; |
volatile uintptr_t x = (uint64_t) &val->count; |
a = *((uint64_t *) x); |
b = a + i; |
asm volatile ("casx %0, %2, %1\n" : "+m" (*val), "+r" (b) : "r" (a)); |
asm volatile ("casx %0, %2, %1\n" : "+m" (*((uint64_t *)x)), "+r" (b) : "r" (a)); |
} while (a != b); |
return a; |
/branches/rcu/uspace/libc/arch/sparc64/src/thread_entry.s |
---|
34,7 → 34,7 |
# |
# |
__thread_entry: |
sethi %hi(_gp), %l7 |
sethi %hi(_gp), %l7 |
call __thread_main ! %o0 contains address of uarg |
or %l7, %lo(_gp), %l7 |