Changeset 183788f1 in mainline


Ignore:
Timestamp:
2007-04-09T16:17:25Z (18 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
36f19c0
Parents:
de33dab
Message:

Remove printf() serialization from thread1 test in tester.
The agreement among developers seems to be that:

  • there _must_ be a futex to serialize access to printf()
  • there _must_ be pseudo thread serialization in printf()
  • the best place for this is vprintf(), the one that goes to console
Location:
uspace
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/libc/generic/io/printf_core.c

    rde33dab r183788f1  
    4141#include <ctype.h>
    4242#include <string.h>
    43 #include <async.h>      /* for pseudo thread serialization */
    4443
    4544#define __PRINTF_FLAG_PREFIX            0x00000001      /**< show prefixes 0x or 0*/
     
    444443        int width, precision;
    445444        uint64_t flags;
    446        
    447         /* Don't let other pseudo threads interfere. */
    448         async_serialize_start();
    449445       
    450446        counter = 0;
     
    679675        }
    680676       
    681         async_serialize_end();
    682677        return counter;
    683678minus_out:
    684         async_serialize_end();
    685679        return -counter;
    686680}
  • uspace/libc/generic/io/vprintf.c

    rde33dab r183788f1  
    3737#include <unistd.h>
    3838#include <io/printf_core.h>
     39#include <futex.h>
     40#include <async.h>
     41
     42static atomic_t printf_futex = FUTEX_INITIALIZER;
    3943
    4044static int vprintf_write(const char *str, size_t count, void *unused)
     
    5054int vprintf(const char *fmt, va_list ap)
    5155{
    52         struct printf_spec ps = {(int(*)(void *, size_t, void *)) vprintf_write, NULL};
    53        
     56        struct printf_spec ps = {
     57                (int (*)(void *, size_t, void *)) vprintf_write,
     58                 NULL
     59        };
     60        /*
     61         * Prevent other threads to execute printf_core()
     62         */
     63        futex_down(&printf_futex);
     64        /*
     65         * Prevent other pseudo threads of the same thread
     66         * to execute printf_core()
     67         */
     68        async_serialize_start();
    5469        int ret = printf_core(fmt, &ps, ap);
    55        
     70        async_serialize_end();
     71        futex_up(&printf_futex);
    5672        return ret;
    5773}
  • uspace/tester/thread/thread1.c

    rde33dab r183788f1  
    3434#include <stdio.h>
    3535#include <unistd.h>
    36 #include <futex.h>
    3736#include "../tester.h"
    3837
     
    4140static bool sh_quiet;
    4241
    43 static atomic_t srlz = FUTEX_INITIALIZER;
    44 
    4542static void threadtest(void *data)
    4643{
     
    4845
    4946        while (atomic_get(&finish)) {
    50                 if (!sh_quiet) {
    51                         futex_down(&srlz);
     47                if (!sh_quiet)
    5248                        printf("%llu ", thread_get_id());
    53                         futex_up(&srlz);
    54                 }
    5549                usleep(100000);
    5650        }
     
    7569        }
    7670       
    77         if (!quiet) {
    78                 futex_down(&srlz);
     71        if (!quiet)
    7972                printf("Running threads for 10 seconds...\n");
    80                 futex_up(&srlz);
    81         }
    8273        sleep(10);
    8374       
Note: See TracChangeset for help on using the changeset viewer.