/trunk/uspace/tester/thread/thread1.c |
---|
33,7 → 33,6 |
#include <thread.h> |
#include <stdio.h> |
#include <unistd.h> |
#include <futex.h> |
#include "../tester.h" |
static atomic_t finish; |
40,18 → 39,13 |
static atomic_t threads_finished; |
static bool sh_quiet; |
static atomic_t srlz = FUTEX_INITIALIZER; |
static void threadtest(void *data) |
{ |
thread_detach(thread_get_id()); |
while (atomic_get(&finish)) { |
if (!sh_quiet) { |
futex_down(&srlz); |
if (!sh_quiet) |
printf("%llu ", thread_get_id()); |
futex_up(&srlz); |
} |
usleep(100000); |
} |
atomic_inc(&threads_finished); |
74,11 → 68,8 |
total++; |
} |
if (!quiet) { |
futex_down(&srlz); |
if (!quiet) |
printf("Running threads for 10 seconds...\n"); |
futex_up(&srlz); |
} |
sleep(10); |
atomic_set(&finish, 0); |
/trunk/uspace/libc/generic/io/vprintf.c |
---|
36,7 → 36,11 |
#include <stdio.h> |
#include <unistd.h> |
#include <io/printf_core.h> |
#include <futex.h> |
#include <async.h> |
static atomic_t printf_futex = FUTEX_INITIALIZER; |
static int vprintf_write(const char *str, size_t count, void *unused) |
{ |
return write(1, str, count); |
49,10 → 53,22 |
*/ |
int vprintf(const char *fmt, va_list ap) |
{ |
struct printf_spec ps = {(int(*)(void *, size_t, void *)) vprintf_write, NULL}; |
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; |
} |
/trunk/uspace/libc/generic/io/printf_core.c |
---|
40,7 → 40,6 |
#include <io/printf_core.h> |
#include <ctype.h> |
#include <string.h> |
#include <async.h> /* for pseudo thread serialization */ |
#define __PRINTF_FLAG_PREFIX 0x00000001 /**< show prefixes 0x or 0*/ |
#define __PRINTF_FLAG_SIGNED 0x00000002 /**< signed / unsigned number */ |
444,9 → 443,6 |
int width, precision; |
uint64_t flags; |
/* Don't let other pseudo threads interfere. */ |
async_serialize_start(); |
counter = 0; |
while ((c = fmt[i])) { |
678,10 → 674,8 |
counter += retval; |
} |
async_serialize_end(); |
return counter; |
minus_out: |
async_serialize_end(); |
return -counter; |
} |