Changeset dc747e3 in mainline


Ignore:
Timestamp:
2005-12-15T10:27:59Z (19 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7dd2561
Parents:
3fc03fd
Message:

Add SPINLOCK_DECLARE and SPINLOCK_INITIALIZE macros.
SPINLOCK_DECLARE is to be used instead of direct spinlock_t declarations
in dynamically allocated structures on which spinlock_initialize() is called after
their creation.
SPINLOCK_INITIALIZE is to be used instead of direct spinlock_t declarations
of global spinlocks. It declares and initializes the spinlock.
Moreover, both macros are empty on UP so that -Wall warnings about unused structures
get supressed.

Files:
31 edited

Legend:

Unmodified
Added
Removed
  • arch/ia32/src/drivers/ega.c

    r3fc03fd rdc747e3  
    4343 */
    4444
    45 static spinlock_t egalock;
     45SPINLOCK_INITIALIZE(egalock);
    4646static __u32 ega_cursor;
    4747
  • arch/ia32/src/drivers/i8042.c

    r3fc03fd rdc747e3  
    6464#define LOCKED_CAPSLOCK         (1<<0)
    6565
    66 static spinlock_t keylock;              /**< keylock protects keyflags and lockflags. */
     66SPINLOCK_INITIALIZE(keylock);           /**< keylock protects keyflags and lockflags. */
    6767static volatile int keyflags;           /**< Tracking of multiple keypresses. */
    6868static volatile int lockflags;          /**< Tracking of multiple keys lockings. */
     
    244244        exc_register(VECTOR_KBD, "i8042_interrupt", i8042_interrupt);
    245245        trap_virtual_enable_irqs(1<<IRQ_KBD);
    246         spinlock_initialize(&keylock, "i8042_lock");
    247246        chardev_initialize("i8042_kbd", &kbrd, &ops);
    248247        stdin = &kbrd;
  • arch/ia32/src/mm/page.c

    r3fc03fd rdc747e3  
    3636#include <arch/interrupt.h>
    3737#include <arch/asm.h>
    38 #include <synch/spinlock.h>
    3938#include <debug.h>
    4039#include <memstr.h>
  • arch/mips32/src/debugger.c

    r3fc03fd rdc747e3  
    3939
    4040bpinfo_t breakpoints[BKPOINTS_MAX];
    41 spinlock_t bkpoint_lock;
     41SPINLOCK_INITIALIZE(bkpoint_lock);
    4242
    4343static int cmd_print_breakpoints(cmd_arg_t *argv);
     
    182182        for (i=0; i<BKPOINTS_MAX; i++)
    183183                breakpoints[i].address = NULL;
    184         spinlock_initialize(&bkpoint_lock, "breakpoint_lock");
    185184       
    186185        cmd_initialize(&pbkpt_info);
  • arch/mips32/src/mm/asid.c

    r3fc03fd rdc747e3  
    3434#include <typedefs.h>
    3535
    36 static spinlock_t asid_usage_lock;
     36SPINLOCK_INITIALIZE(asid_usage_lock);
    3737static count_t asid_usage[ASIDS];       /**< Usage tracking array for ASIDs */
    3838
  • generic/include/console/chardev.h

    r3fc03fd rdc747e3  
    5353       
    5454        waitq_t wq;
    55         spinlock_t lock;                /**< Protects everything below. */
     55        SPINLOCK_DECLARE(lock);         /**< Protects everything below. */
    5656        __u8 buffer[CHARDEV_BUFLEN];
    5757        count_t counter;
  • generic/include/console/kconsole.h

    r3fc03fd rdc747e3  
    5656struct cmd_info {
    5757        link_t link;                    /**< Command list link. */
    58         spinlock_t lock;                /**< This lock protects everything below. */
     58        SPINLOCK_DECLARE(lock);         /**< This lock protects everything below. */
    5959        const char *name;               /**< Command name. */
    6060        const char *description;        /**< Textual description. */
  • generic/include/cpu.h

    r3fc03fd rdc747e3  
    4343
    4444struct cpu {
    45         spinlock_t lock;
     45        SPINLOCK_DECLARE(lock);
    4646        context_t saved_context;
    4747
     
    5050        volatile count_t needs_relink;
    5151
    52         spinlock_t timeoutlock;
     52        SPINLOCK_DECLARE(timeoutlock);
    5353        link_t timeout_active_head;
    5454
  • generic/include/mm/frame.h

    r3fc03fd rdc747e3  
    5555        link_t link;            /**< link to previous and next zone */
    5656
    57         spinlock_t lock;        /**< this lock protects everything below */
     57        SPINLOCK_DECLARE(lock); /**< this lock protects everything below */
    5858        __address base;         /**< physical address of the first frame in the frames array */
    5959        frame_t *frames;        /**< array of frame_t structures in this zone */
  • generic/include/mm/vm.h

    r3fc03fd rdc747e3  
    5858 */
    5959struct vm_area {
    60         spinlock_t lock;
     60        SPINLOCK_DECLARE(lock);
    6161        link_t link;
    6262        vm_type_t type;
     
    7373 */
    7474struct vm {
    75         spinlock_t lock;
     75        SPINLOCK_DECLARE(lock);
    7676        link_t vm_area_head;
    7777        pte_t *ptl0;
  • generic/include/proc/scheduler.h

    r3fc03fd rdc747e3  
    4141/** Scheduler run queue structure. */
    4242struct runq {
    43         spinlock_t lock;
     43        SPINLOCK_DECLARE(lock);
    4444        link_t rq_head;         /**< List of ready threads. */
    4545        count_t n;              /**< Number of threads in rq_ready. */
  • generic/include/proc/task.h

    r3fc03fd rdc747e3  
    3535
    3636struct task {
    37         spinlock_t lock;
     37        SPINLOCK_DECLARE(lock);
    3838        link_t th_head;         /**< List of threads contained in this task. */
    3939        link_t tasks_link;      /**< Link to other tasks within the system. */
  • generic/include/proc/thread.h

    r3fc03fd rdc747e3  
    7171         *
    7272         */
    73         spinlock_t lock;
     73        SPINLOCK_DECLARE(lock);
    7474
    7575        void (* thread_code)(void *);           /**< Function implementing the thread. */
  • generic/include/synch/rwlock.h

    r3fc03fd rdc747e3  
    3434#include <synch/mutex.h>
    3535#include <synch/synch.h>
     36#include <synch/spinlock.h>
    3637
    3738enum rwlock_type {
     
    4243
    4344struct rwlock {
    44         spinlock_t lock;
     45        SPINLOCK_DECLARE(lock);
    4546        mutex_t exclusive;      /**< Mutex for writers, readers can bypass it if readers_in is positive. */
    4647        count_t readers_in;     /**< Number of readers in critical section. */
  • generic/include/synch/spinlock.h

    r3fc03fd rdc747e3  
    4242};
    4343
     44/*
     45 * SPINLOCK_DECLARE is to be used for dynamically allocated spinlocks,
     46 * where the lock gets initialized in run time.
     47 */
     48#define SPINLOCK_DECLARE(slname)        spinlock_t slname
     49
     50/*
     51 * SPINLOCK_INITIALIZE is to be used for statically allocated spinlocks.
     52 * It declares and initializes the lock.
     53 */
     54#ifdef CONFIG_DEBUG_SPINLOCK
     55#define SPINLOCK_INITIALIZE(slname)     \
     56        spinlock_t slname = {           \
     57                .name = #slname,        \
     58                .val = 0                \
     59        }
     60#else
     61#define SPINLOCK_INITIALIZE(slname)     \
     62        spinlock_t slname = {           \
     63                .val = 0                \
     64        }
     65#endif
     66
    4467extern void spinlock_initialize(spinlock_t *sl, char *name);
    4568extern void spinlock_lock(spinlock_t *sl);
     
    4972#else
    5073
    51 struct spinlock {
    52 };
     74/* On UP systems, spinlocks are effectively left out. */
     75#define SPINLOCK_DECLARE(name)
     76#define SPINLOCK_INITIALIZE(name)
    5377
    5478#define spinlock_initialize(x,name)
  • generic/include/synch/waitq.h

    r3fc03fd rdc747e3  
    4646         * Must be acquired before T.lock for each T of type thread_t.
    4747         */
    48         spinlock_t lock;
     48        SPINLOCK_DECLARE(lock);
    4949
    5050        int missed_wakeups;     /**< Number of waitq_wakeup() calls that didn't find a thread to wake up. */
  • generic/include/time/timeout.h

    r3fc03fd rdc747e3  
    4040
    4141struct timeout {
    42         spinlock_t lock;
     42        SPINLOCK_DECLARE(lock);
    4343
    4444        link_t link;                    /**< Link to the list of active timeouts on THE->cpu */
  • generic/src/console/kconsole.c

    r3fc03fd rdc747e3  
    6666 */
    6767 
    68 spinlock_t cmd_lock;    /**< Lock protecting command list. */
    69 link_t cmd_head;        /**< Command list. */
     68SPINLOCK_INITIALIZE(cmd_lock);  /**< Lock protecting command list. */
     69link_t cmd_head;                /**< Command list. */
    7070
    7171static cmd_info_t *parse_cmdline(char *cmdline, size_t len);
     
    7878        int i;
    7979
    80         spinlock_initialize(&cmd_lock, "kconsole_cmd");
    8180        list_initialize(&cmd_head);
    8281
  • generic/src/cpu/cpu.c

    r3fc03fd rdc747e3  
    6767                        cpus[i].id = i;
    6868                       
     69                        spinlock_initialize(&cpus[i].lock, "cpu_t.lock");
     70
    6971                        #ifdef CONFIG_SMP
    7072                        waitq_initialize(&cpus[i].kcpulb_wq);
     
    7274                       
    7375                        for (j = 0; j < RQ_COUNT; j++) {
     76                                spinlock_initialize(&cpus[i].rq[j].lock, "rq_t.lock");
    7477                                list_initialize(&cpus[i].rq[j].rq_head);
    7578                        }
  • generic/src/debug/print.c

    r3fc03fd rdc747e3  
    3636#include <arch.h>
    3737
    38 static char digits[] = "0123456789abcdef"; /**< Hexadecimal characters */
    39 static spinlock_t printflock;              /**< printf spinlock */
     38static char digits[] = "0123456789abcdef";      /**< Hexadecimal characters */
     39SPINLOCK_INITIALIZE(printflock);                /**< printf spinlock */
    4040
    4141#define DEFAULT_DOUBLE_PRECISION 16
  • generic/src/interrupt/interrupt.c

    r3fc03fd rdc747e3  
    4141} exc_table[IVT_ITEMS];
    4242
    43 static spinlock_t exctbl_lock;
     43SPINLOCK_INITIALIZE(exctbl_lock);
    4444
    4545/** Register exception handler
     
    125125        int i;
    126126
    127         spinlock_initialize(&exctbl_lock, "exctbl_lock");
    128 
    129127        for (i=0;i < IVT_ITEMS; i++)
    130128                exc_register(i, "undef", exc_undef);
  • generic/src/main/main.c

    r3fc03fd rdc747e3  
    175175         */
    176176        kconsole_init();
     177
    177178        /* Exception handler initialization, before architecture
    178179         * starts adding it's own handlers
  • generic/src/mm/frame.c

    r3fc03fd rdc747e3  
    4242#include <align.h>
    4343
    44 spinlock_t zone_head_lock;       /**< this lock protects zone_head list */
    45 link_t zone_head;                /**< list of all zones in the system */
     44SPINLOCK_INITIALIZE(zone_head_lock);    /**< this lock protects zone_head list */
     45link_t zone_head;                       /**< list of all zones in the system */
    4646
    4747/** Blacklist containing non-available areas of memory.
     
    243243void zone_init(void)
    244244{
    245         spinlock_initialize(&zone_head_lock, "zone_head_lock");
    246245        list_initialize(&zone_head);
    247246}
  • generic/src/mm/heap.c

    r3fc03fd rdc747e3  
    4444
    4545static chunk_t *chunk0;
    46 static spinlock_t heaplock;
     46SPINLOCK_INITIALIZE(heaplock);
    4747
    4848void early_heap_init(__address heap, size_t size)
    4949{
    50         spinlock_initialize(&heaplock, "heap_lock");
    5150        memsetb(heap, size, 0);
    5251        chunk0 = (chunk_t *) heap;
  • generic/src/mm/tlb.c

    r3fc03fd rdc747e3  
    3838#include <panic.h>
    3939
    40 #ifdef CONFIG_SMP
    41 static spinlock_t tlblock;
    42 #endif
     40SPINLOCK_INITIALIZE(tlblock);
    4341
    4442void tlb_init(void)
    4543{
    46         if (config.cpu_active == 1)
    47                 spinlock_initialize(&tlblock, "tlb_lock");
    48 
    4944        tlb_arch_init();
    5045}
  • generic/src/proc/task.c

    r3fc03fd rdc747e3  
    3737#include <list.h>
    3838
    39 spinlock_t tasks_lock;
     39SPINLOCK_INITIALIZE(tasks_lock);
    4040link_t tasks_head;
    4141
     
    4949{
    5050        TASK = NULL;
    51         spinlock_initialize(&tasks_lock, "tasks_lock");
    5251        list_initialize(&tasks_head);
    5352}
  • generic/src/proc/thread.c

    r3fc03fd rdc747e3  
    5555char *thread_states[] = {"Invalid", "Running", "Sleeping", "Ready", "Entering", "Exiting"}; /**< Thread states */
    5656
    57 spinlock_t threads_lock;        /**< Lock protecting threads_head list. For locking rules, see declaration thereof. */
    58 link_t threads_head;            /**< List of all threads. */
    59 
    60 static spinlock_t tidlock;
     57SPINLOCK_INITIALIZE(threads_lock);      /**< Lock protecting threads_head list. For locking rules, see declaration thereof. */
     58link_t threads_head;                    /**< List of all threads. */
     59
     60SPINLOCK_INITIALIZE(tidlock);
    6161__u32 last_tid = 0;
    6262
     
    9797        THREAD = NULL;
    9898        nrdy = 0;
    99         spinlock_initialize(&threads_lock, "threads_lock");
    10099        list_initialize(&threads_head);
    101100}
  • generic/src/synch/rwlock.c

    r3fc03fd rdc747e3  
    193193                 * after this thread is put asleep.
    194194                 */
     195                #ifdef CONFIG_SMP
    195196                thread_register_call_me(release_spinlock, &rwl->lock);
     197                #else
     198                thread_register_call_me(release_spinlock, NULL);
     199                #endif
    196200                                 
    197201                rc = _mutex_lock_timeout(&rwl->exclusive, usec, trylock);
     
    201205                                 * release_spinlock() wasn't called
    202206                                 */
    203                                 thread_register_call_me(NULL, NULL);                             
     207                                thread_register_call_me(NULL, NULL);
    204208                                spinlock_unlock(&rwl->lock);
    205209                        case ESYNCH_TIMEOUT:
  • test/synch/rwlock4/test.c

    r3fc03fd rdc747e3  
    4040#include <synch/rwlock.h>
    4141#include <synch/synch.h>
     42#include <synch/spinlock.h>
    4243
    4344#define READERS         50
     
    4647static rwlock_t rwlock;
    4748
    48 static spinlock_t lock;
     49SPINLOCK_INITIALIZE(lock);
    4950
    5051static waitq_t can_start;
  • test/synch/semaphore2/test.c

    r3fc03fd rdc747e3  
    3838#include <synch/semaphore.h>
    3939#include <synch/synch.h>
     40#include <synch/spinlock.h>
    4041
    4142static semaphore_t sem;
    4243
    43 static spinlock_t lock;
     44SPINLOCK_INITIALIZE(lock);
    4445
    4546static waitq_t can_start;
  • test/thread/thread1/test.c

    r3fc03fd rdc747e3  
    3838#include <arch.h>
    3939
    40 
    41 
    4240#define THREADS 5
    43 
    4441
    4542static void thread(void *data)
     
    5249}
    5350
    54 
    55 
    5651void test(void)
    5752{
     
    5954        int i;
    6055
    61 
    62 
    63         for (i=0; i<THREADS; i++)
    64         { 
     56        for (i=0; i<THREADS; i++) { 
    6557                if (!(t = thread_create(thread, NULL, TASK, 0)))
    6658                        panic("could not create thread\n");
     
    6860        }
    6961        printf("ok\n");
    70        
    7162}
Note: See TracChangeset for help on using the changeset viewer.