source: proiecte/swift/trunk/src/swift_context.c @ 176

Last change on this file since 176 was 176, checked in by (none), 14 years ago
  • imported repo from "guagal"
File size: 1.7 KB
Line 
1/*
2 * swift_context.c
3 *
4 * (c) 2009 Ionut Rosoiu <ionut.rosoiu@gmail.com>
5 *
6 */
7
8#include "swift_context.h"
9#include <stdlib.h>
10#include <string.h>
11
12void swift_context_init(swift_context_t *context, swift_size_t nprocs) {
13        //TODO: check
14        swift_thread_t *thread;
15        int i;
16#ifdef SWIFT_USE_CUSTOM_ALLOCATOR
17        int j;
18#endif
19
20        context->thread_num = nprocs;
21        context->parallel_finished = 0;
22
23        context->threads = (swift_thread_t*) swift_malloc_system(nprocs * sizeof(swift_thread_t));
24
25        //TODO: check
26        for (i=0; i<nprocs; i++) {
27                thread = &context->threads[i];
28
29#ifdef SWIFT_USE_CUSTOM_ALLOCATOR
30                thread->heap = swift_malloc_system(SWIFT_HEAP_SIZE);
31                thread->buckets = (swift_allocator_list_t**) swift_malloc_system(SWIFT_BUCKET_COUNT * sizeof(void*));
32                swift_assert(thread->heap && thread->buckets);
33
34                thread->heap_top = thread->heap;
35                thread->heap_limit = ((char*)thread->heap + SWIFT_HEAP_SIZE);
36
37                for (j=0; j<SWIFT_BUCKET_COUNT; j++) {
38                        thread->buckets[j] = NULL;
39                }
40#endif
41
42                swift_deque_init(thread,
43                                                 &thread->workque,
44                                                 SWIFT_DEQUE_SIZE);
45
46                //TODO: check
47                thread->context = context;
48                thread->id = i;
49                thread->stats = 0;
50                thread->stop = 0;
51                thread->round_robin_id = i;
52                thread->last_sleep_time = i * 10 + 1;
53                thread->frame_no = 0;
54        }
55}
56
57void swift_context_destroy(swift_context_t *context) {
58        int i;
59#ifdef SWIFT_USE_CUSTOM_ALLOCATOR
60        int j;
61#endif
62
63        for (i=0; i<context->thread_num; i++) {
64                swift_deque_destroy(&context->threads[i], &context->threads[i].workque);
65
66#ifdef SWIFT_USE_CUSTOM_ALLOCATOR
67                for (j=0; j<SWIFT_BUCKET_COUNT; j++) {
68                        context->threads[i].buckets[j] = NULL;
69                }
70                swift_free_system(context->threads[i].buckets);
71#endif
72
73        }
74
75        swift_free_system(context->threads);
76}
77
Note: See TracBrowser for help on using the repository browser.