Subversion Repositories HelenOS

Rev

Rev 2131 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2131 Rev 2307
Line 34... Line 34...
34
 
34
 
35
#include <stdarg.h>
35
#include <stdarg.h>
36
#include <stdio.h>
36
#include <stdio.h>
37
#include <unistd.h>
37
#include <unistd.h>
38
#include <io/printf_core.h>
38
#include <io/printf_core.h>
-
 
39
#include <futex.h>
-
 
40
#include <async.h>
39
 
41
 
40
int vprintf_write(const char *str, size_t count, void *unused);
42
static atomic_t printf_futex = FUTEX_INITIALIZER;
41
 
43
 
42
int vprintf_write(const char *str, size_t count, void *unused)
44
static int vprintf_write(const char *str, size_t count, void *unused)
43
{
45
{
44
    return write(1, str, count);
46
    return write(1, str, count);
45
}
47
}
46
 
48
 
47
/** Print formatted text.
49
/** Print formatted text.
Line 49... Line 51...
49
 * @param ap    format parameters
51
 * @param ap    format parameters
50
 * \see For more details about format string see printf_core.
52
 * \see For more details about format string see printf_core.
51
 */
53
 */
52
int vprintf(const char *fmt, va_list ap)
54
int vprintf(const char *fmt, va_list ap)
53
{
55
{
-
 
56
    struct printf_spec ps = {
54
    struct printf_spec ps = {(int(*)(void *, size_t, void *))vprintf_write, NULL};
57
        (int (*)(void *, size_t, void *)) vprintf_write,
-
 
58
         NULL
-
 
59
    };
-
 
60
    /*
-
 
61
     * Prevent other threads to execute printf_core()
-
 
62
     */
55
    return printf_core(fmt, &ps, ap);
63
    futex_down(&printf_futex);
56
 
64
    /*
-
 
65
     * Prevent other pseudo threads of the same thread
-
 
66
     * to execute printf_core()
-
 
67
     */
-
 
68
    async_serialize_start();
-
 
69
    int ret = printf_core(fmt, &ps, ap);
-
 
70
    async_serialize_end();
-
 
71
    futex_up(&printf_futex);
-
 
72
    return ret;
57
}
73
}
58
 
74
 
59
/** @}
75
/** @}
60
 */
76
 */