Changeset 38d8849 in mainline


Ignore:
Timestamp:
2018-07-16T15:58:51Z (6 years ago)
Author:
Jiří Zárevúcky <jiri.zarevucky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
db51219f
Parents:
c124c985
git-author:
Jiří Zárevúcky <jiri.zarevucky@…> (2018-07-14 16:53:46)
git-committer:
Jiří Zárevúcky <jiri.zarevucky@…> (2018-07-16 15:58:51)
Message:

Privatize <thread.h>.

Location:
uspace
Files:
1 deleted
15 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/rcubench/rcubench.c

    rc124c985 r38d8849  
    4040#include <mem.h>
    4141#include <errno.h>
    42 #include <thread.h>
    4342#include <assert.h>
    4443#include <async.h>
     
    105104}
    106105
    107 static void thread_func(void *arg)
     106static errno_t thread_func(void *arg)
    108107{
    109108        bench_t *bench = (bench_t *)arg;
     
    113112        /* Signal another thread completed. */
    114113        futex_up(&bench->done_threads);
     114        return EOK;
    115115}
    116116
     
    123123        }
    124124
     125        fibril_test_spawn_runners(bench->nthreads - 1);
     126
    125127        /* Create and run the first nthreads - 1 threads.*/
    126128        for (size_t k = 1; k < bench->nthreads; ++k) {
    127                 thread_id_t tid;
    128                 /* Also sets up a fibril for the thread. */
    129                 errno_t ret = thread_create(thread_func, bench, "rcubench-t", &tid);
    130                 if (ret != EOK) {
     129                fid_t f = fibril_create(thread_func, bench);
     130                if (!f) {
    131131                        printf("Error: Failed to create benchmark thread.\n");
    132132                        abort();
    133133                }
    134                 thread_detach(tid);
     134                fibril_detach(f);
     135                fibril_add_ready(f);
    135136        }
    136137
  • uspace/app/rcutest/rcutest.c

    rc124c985 r38d8849  
    4141#include <mem.h>
    4242#include <errno.h>
    43 #include <thread.h>
    4443#include <assert.h>
    4544#include <async.h>
     
    759758/*--------------------------------------------------------------------*/
    760759
    761 static FIBRIL_MUTEX_INITIALIZE(blocking_mtx);
    762 
    763 static void dummy_fibril(void *arg)
    764 {
    765         /* Block on an already locked mutex - enters the fibril manager. */
    766         fibril_mutex_lock(&blocking_mtx);
    767         assert(false);
    768 }
    769 
    770760static bool create_threads(size_t cnt)
    771761{
    772762        /* Sanity check. */
    773763        assert(cnt < 1024);
    774 
    775         /* Keep this mutex locked so that dummy fibrils never exit. */
    776         bool success = fibril_mutex_trylock(&blocking_mtx);
    777         assert(success);
    778 
    779         for (size_t k = 0; k < cnt; ++k) {
    780                 thread_id_t tid;
    781 
    782                 errno_t ret = thread_create(dummy_fibril, NULL, "urcu-test-worker", &tid);
    783                 if (EOK != ret) {
    784                         printf("Failed to create thread '%zu' (error: %s)\n", k + 1, str_error_name(ret));
    785                         return false;
    786                 }
    787         }
    788 
     764        fibril_test_spawn_runners(cnt);
    789765        return true;
    790766}
  • uspace/app/tester/float/float1.c

    rc124c985 r38d8849  
    3333#include <stddef.h>
    3434#include <atomic.h>
    35 #include <thread.h>
     35#include <fibril.h>
     36#include <fibril_synch.h>
    3637#include <inttypes.h>
    3738#include "../tester.h"
     
    4344#define PRECISION  100000000
    4445
    45 static atomic_t threads_finished;
     46static FIBRIL_SEMAPHORE_INITIALIZE(threads_finished, 0);
    4647static atomic_t threads_fault;
    4748
    48 static void e(void *data)
     49static errno_t e(void *data)
    4950{
    5051        for (unsigned int i = 0; i < ATTEMPTS; i++) {
     
    6465        }
    6566
    66         atomic_inc(&threads_finished);
     67        fibril_semaphore_up(&threads_finished);
     68        return EOK;
    6769}
    6870
     
    7173        atomic_count_t total = 0;
    7274
    73         atomic_set(&threads_finished, 0);
    7475        atomic_set(&threads_fault, 0);
     76        fibril_test_spawn_runners(THREADS);
    7577
    7678        TPRINTF("Creating threads");
    7779        for (unsigned int i = 0; i < THREADS; i++) {
    78                 if (thread_create(e, NULL, "e", NULL) != EOK) {
     80                fid_t f = fibril_create(e, NULL);
     81                if (!f) {
    7982                        TPRINTF("\nCould not create thread %u\n", i);
    8083                        break;
    8184                }
     85                fibril_detach(f);
     86                fibril_add_ready(f);
    8287
    8388                TPRINTF(".");
     
    8792        TPRINTF("\n");
    8893
    89         while (atomic_get(&threads_finished) < total) {
    90                 TPRINTF("Threads left: %" PRIua "\n",
    91                     total - atomic_get(&threads_finished));
    92                 thread_sleep(1);
     94        for (unsigned int i = 0; i < total; i++) {
     95                TPRINTF("Threads left: %" PRIua "\n", total - i);
     96                fibril_semaphore_down(&threads_finished);
    9397        }
    9498
  • uspace/app/tester/thread/thread1.c

    rc124c985 r38d8849  
    3333#include <atomic.h>
    3434#include <errno.h>
    35 #include <thread.h>
     35#include <fibril.h>
     36#include <fibril_synch.h>
    3637#include <stdio.h>
    3738#include <stddef.h>
     
    4041
    4142static atomic_t finish;
    42 static atomic_t threads_finished;
    4343
    44 static void threadtest(void *data)
     44static FIBRIL_SEMAPHORE_INITIALIZE(threads_finished, 0);
     45
     46static errno_t threadtest(void *data)
    4547{
    46         thread_detach(thread_get_id());
     48        fibril_detach(fibril_get_id());
    4749
    4850        while (atomic_get(&finish))
    49                 thread_usleep(100000);
     51                fibril_usleep(100000);
    5052
    51         atomic_inc(&threads_finished);
     53        fibril_semaphore_up(&threads_finished);
     54        return EOK;
    5255}
    5356
     
    5861
    5962        atomic_set(&finish, 1);
    60         atomic_set(&threads_finished, 0);
     63
     64        fibril_test_spawn_runners(THREADS);
    6165
    6266        TPRINTF("Creating threads");
    6367        for (i = 0; i < THREADS; i++) {
    64                 if (thread_create(threadtest, NULL, "threadtest", NULL) != EOK) {
     68                fid_t f = fibril_create(threadtest, NULL);
     69                if (!f) {
    6570                        TPRINTF("\nCould not create thread %u\n", i);
    6671                        break;
    6772                }
     73                fibril_add_ready(f);
    6874                TPRINTF(".");
    6975                total++;
     
    7177
    7278        TPRINTF("\nRunning threads for %u seconds...", DELAY);
    73         thread_sleep(DELAY);
     79        fibril_sleep(DELAY);
    7480        TPRINTF("\n");
    7581
    7682        atomic_set(&finish, 0);
    77         while (atomic_get(&threads_finished) < total) {
     83        for (i = 0; i < total; i++) {
    7884                TPRINTF("Threads left: %" PRIua "\n",
    79                     total - atomic_get(&threads_finished));
    80                 thread_sleep(1);
     85                    total - i);
     86                fibril_semaphore_down(&threads_finished);
    8187        }
    8288
  • uspace/lib/c/arch/arm32/include/libarch/fibril.h

    rc124c985 r38d8849  
    3939#include <types/common.h>
    4040#include <align.h>
    41 #include <thread.h>
    4241#include <libarch/fibril_context.h>
    4342
  • uspace/lib/c/generic/fibril.c

    rc124c985 r38d8849  
    3636#include <adt/list.h>
    3737#include <fibril.h>
    38 #include <thread.h>
    3938#include <stack.h>
    4039#include <tls.h>
     
    4948#include <async.h>
    5049
     50#include "private/thread.h"
    5151#include "private/fibril.h"
    5252
  • uspace/lib/c/generic/private/thread.h

    rc124c985 r38d8849  
    3636#define LIBC_PRIVATE_THREAD_H_
    3737
     38#include <time.h>
    3839#include <abi/proc/uarg.h>
     40#include <libarch/thread.h>
     41#include <abi/proc/thread.h>
    3942
    4043extern void __thread_entry(void);
    4144extern void __thread_main(uspace_arg_t *);
     45
     46extern errno_t thread_create(void (*)(void *), void *, const char *, thread_id_t *);
     47extern void thread_exit(int) __attribute__((noreturn));
     48extern void thread_detach(thread_id_t);
     49extern thread_id_t thread_get_id(void);
     50extern int thread_usleep(useconds_t);
     51extern unsigned int thread_sleep(unsigned int);
    4252
    4353#endif
  • uspace/lib/c/generic/rcu.c

    rc124c985 r38d8849  
    8080#include <assert.h>
    8181#include <time.h>
    82 #include <thread.h>
    8382
    8483#include "private/fibril.h"
  • uspace/lib/c/generic/stats.c

    rc124c985 r38d8849  
    184184}
    185185
    186 /** Get single thread statistics
    187  *
    188  * @param thread_id Thread ID we are interested in.
    189  *
    190  * @return Pointer to the stats_thread_t structure.
    191  *         If non-NULL then it should be eventually freed
    192  *         by free().
    193  *
    194  */
    195 stats_thread_t *stats_get_thread(thread_id_t thread_id)
    196 {
    197         char name[SYSINFO_STATS_MAX_PATH];
    198         snprintf(name, SYSINFO_STATS_MAX_PATH, "system.threads.%" PRIu64, thread_id);
    199 
    200         size_t size = 0;
    201         stats_thread_t *stats_thread =
    202             (stats_thread_t *) sysinfo_get_data(name, &size);
    203 
    204         if (size != sizeof(stats_thread_t)) {
    205                 if (stats_thread != NULL)
    206                         free(stats_thread);
    207                 return NULL;
    208         }
    209 
    210         return stats_thread;
    211 }
    212 
    213186/** Get exception statistics.
    214187 *
  • uspace/lib/c/generic/thread.c

    rc124c985 r38d8849  
    3333 */
    3434
    35 #include <thread.h>
    3635#include <libc.h>
    3736#include <stdbool.h>
     
    159158}
    160159
    161 /** Join thread.
    162  *
    163  * Currently not implemented.
    164  *
    165  * @param thread TID.
    166  *
    167  * @return Thread exit status.
    168  */
    169 errno_t thread_join(thread_id_t thread)
    170 {
    171         return 0;
    172 }
    173 
    174160/** Get current thread ID.
    175161 *
  • uspace/lib/c/include/stats.h

    rc124c985 r38d8849  
    3737
    3838#include <task.h>
    39 #include <thread.h>
    4039#include <stdint.h>
    4140#include <stdbool.h>
     
    5352
    5453extern stats_thread_t *stats_get_threads(size_t *);
    55 extern stats_thread_t *stats_get_thread(thread_id_t);
    5654
    5755extern stats_exc_t *stats_get_exceptions(size_t *);
  • uspace/lib/pcut/tests/timeout.c

    rc124c985 r38d8849  
    3030
    3131#ifdef __helenos__
    32 #include <thread.h>
     32#include <fibril.h>
    3333#else
    3434#ifdef __unix
     
    4646{
    4747#ifdef __helenos__
    48         thread_sleep(sec);
     48        fibril_sleep(sec);
    4949#else
    5050#ifdef __unix
  • uspace/lib/posix/include/posix/pthread.h

    rc124c985 r38d8849  
    3333#define POSIX_PTHREAD_H_
    3434
    35 #include "libc/thread.h"
    3635#include "time.h"
    3736
    38 typedef thread_id_t pthread_t;
     37typedef void *pthread_t;
    3938
    4039typedef struct {
  • uspace/lib/posix/src/pthread/threads.c

    rc124c985 r38d8849  
    3636#include "errno.h"
    3737#include "posix/stdlib.h"
    38 #include "libc/thread.h"
     38#include <fibril.h>
    3939#include "../internal/common.h"
    4040
    4141pthread_t pthread_self(void)
    4242{
    43         return thread_get_id();
     43        return (pthread_t) fibril_get_id();
    4444}
    4545
  • uspace/lib/posix/src/unistd.c

    rc124c985 r38d8849  
    4545
    4646#include "libc/task.h"
    47 #include "libc/thread.h"
    4847#include "libc/stats.h"
    4948#include "libc/malloc.h"
     
    7069unsigned int sleep(unsigned int seconds)
    7170{
    72         return thread_sleep(seconds);
     71        fibril_sleep(seconds);
     72        return 0;
    7373}
    7474
Note: See TracChangeset for help on using the changeset viewer.