Subversion Repositories HelenOS

Rev

Rev 2482 | Rev 2492 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2482 Rev 2483
1
/*
1
/*
2
 * Copyright (c) 2006 Ondrej Palkovsky
2
 * Copyright (c) 2006 Ondrej Palkovsky
3
 * Copyright (c) 2007 Jakub Jermar
3
 * Copyright (c) 2007 Jakub Jermar
4
 * All rights reserved.
4
 * All rights reserved.
5
 *
5
 *
6
 * Redistribution and use in source and binary forms, with or without
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions
7
 * modification, are permitted provided that the following conditions
8
 * are met:
8
 * are met:
9
 *
9
 *
10
 * - Redistributions of source code must retain the above copyright
10
 * - Redistributions of source code must retain the above copyright
11
 *   notice, this list of conditions and the following disclaimer.
11
 *   notice, this list of conditions and the following disclaimer.
12
 * - Redistributions in binary form must reproduce the above copyright
12
 * - Redistributions in binary form must reproduce the above copyright
13
 *   notice, this list of conditions and the following disclaimer in the
13
 *   notice, this list of conditions and the following disclaimer in the
14
 *   documentation and/or other materials provided with the distribution.
14
 *   documentation and/or other materials provided with the distribution.
15
 * - The name of the author may not be used to endorse or promote products
15
 * - The name of the author may not be used to endorse or promote products
16
 *   derived from this software without specific prior written permission.
16
 *   derived from this software without specific prior written permission.
17
 *
17
 *
18
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
 */
28
 */
29
 
29
 
30
/** @addtogroup libc
30
/** @addtogroup libc
31
 * @{
31
 * @{
32
 */
32
 */
33
/** @file
33
/** @file
34
 */
34
 */
35
 
35
 
36
#include <libadt/list.h>
36
#include <libadt/list.h>
37
#include <fibril.h>
37
#include <fibril.h>
38
#include <malloc.h>
38
#include <malloc.h>
39
#include <unistd.h>
39
#include <unistd.h>
40
#include <thread.h>
40
#include <thread.h>
41
#include <stdio.h>
41
#include <stdio.h>
42
#include <libarch/faddr.h>
42
#include <libarch/faddr.h>
43
#include <futex.h>
43
#include <futex.h>
44
#include <assert.h>
44
#include <assert.h>
45
#include <async.h>
45
#include <async.h>
46
 
46
 
47
#ifndef FIBRIL_INITIAL_STACK_PAGES_NO
47
#ifndef FIBRIL_INITIAL_STACK_PAGES_NO
48
#define FIBRIL_INITIAL_STACK_PAGES_NO   1
48
#define FIBRIL_INITIAL_STACK_PAGES_NO   1
49
#endif
49
#endif
50
 
50
 
-
 
51
/** This futex serializes access to ready_list, serialized_list and manage_list.
-
 
52
 */
-
 
53
static atomic_t fibril_futex = FUTEX_INITIALIZER;
-
 
54
 
51
static LIST_INITIALIZE(ready_list);
55
static LIST_INITIALIZE(ready_list);
52
static LIST_INITIALIZE(serialized_list);
56
static LIST_INITIALIZE(serialized_list);
53
static LIST_INITIALIZE(manager_list);
57
static LIST_INITIALIZE(manager_list);
54
 
58
 
55
static void fibril_main(void);
59
static void fibril_main(void);
56
 
60
 
57
static atomic_t fibril_futex = FUTEX_INITIALIZER;
-
 
58
/** Number of threads that are in async_serialized mode */
61
/** Number of fibrils that are in async_serialized mode */
59
static int serialized_threads;  /* Protected by async_futex */
62
static int serialized_fibrils;  /* Protected by async_futex */
60
/** Thread-local count of serialization. If >0, we must not preempt */
63
/** Thread-local count of serialization. If >0, we must not preempt */
61
static __thread int serialization_count;
64
static __thread int serialization_count;
62
/** Counter for fibrils residing in async_manager */
65
/** Counter for fibrils residing in async_manager */
63
static int fibrils_in_manager;
66
static int fibrils_in_manager;
64
 
67
 
65
/** Setup fibril information into TCB structure */
68
/** Setup fibril information into TCB structure */
66
fibril_t *fibril_setup(void)
69
fibril_t *fibril_setup(void)
67
{
70
{
68
    fibril_t *f;
71
    fibril_t *f;
69
    tcb_t *tcb;
72
    tcb_t *tcb;
70
 
73
 
71
    tcb = __make_tls();
74
    tcb = __make_tls();
72
    if (!tcb)
75
    if (!tcb)
73
        return NULL;
76
        return NULL;
74
 
77
 
75
    f = malloc(sizeof(*f));
78
    f = malloc(sizeof(*f));
76
    if (!f) {
79
    if (!f) {
77
        __free_tls(tcb);
80
        __free_tls(tcb);
78
        return NULL;
81
        return NULL;
79
    }
82
    }
80
 
83
 
81
    tcb->fibril_data = f;
84
    tcb->fibril_data = f;
82
    f->tcb = tcb;
85
    f->tcb = tcb;
83
 
86
 
84
    return f;
87
    return f;
85
}
88
}
86
 
89
 
87
void fibril_teardown(fibril_t *f)
90
void fibril_teardown(fibril_t *f)
88
{
91
{
89
    __free_tls(f->tcb);
92
    __free_tls(f->tcb);
90
    free(f);
93
    free(f);
91
}
94
}
92
 
95
 
93
/** Function that spans the whole life-cycle of a fibril.
96
/** Function that spans the whole life-cycle of a fibril.
94
 *
97
 *
95
 * Each fibril begins execution in this function.  Then the function
98
 * Each fibril begins execution in this function. Then the function implementing
96
 * implementing the fibril logic is called.  After its return, the return value
99
 * the fibril logic is called.  After its return, the return value is saved.
97
 * is saved for a potentional joiner. If the joiner exists, it is woken up. The
-
 
98
 * fibril then switches to another fibril, which cleans up after it.
100
 * The fibril then switches to another fibril, which cleans up after it.
99
 */
101
 */
100
void fibril_main(void)
102
void fibril_main(void)
101
{
103
{
102
    fibril_t *f = __tcb_get()->fibril_data;
104
    fibril_t *f = __tcb_get()->fibril_data;
103
 
105
 
-
 
106
    /* Call the implementing function. */
104
    f->retval = f->func(f->arg);
107
    f->retval = f->func(f->arg);
105
 
108
 
106
    /*
-
 
107
     * If there is a joiner, wake it up and save our return value.
-
 
108
     */
-
 
109
    if (f->joiner) {
-
 
110
        list_append(&f->joiner->link, &ready_list);
-
 
111
        f->joiner->joinee_retval = f->retval;
-
 
112
    }
-
 
113
 
-
 
114
    fibril_schedule_next_adv(FIBRIL_FROM_DEAD);
109
    fibril_schedule_next_adv(FIBRIL_FROM_DEAD);
115
    /* not reached */
110
    /* not reached */
116
}
111
}
117
 
112
 
118
/** Schedule next fibril.
113
/** Schedule next fibril.
119
 *
114
 *
120
 * If calling with FIBRIL_TO_MANAGER parameter, the async_futex should be
115
 * If calling with FIBRIL_TO_MANAGER parameter, the async_futex should be
121
 * held.
116
 * held.
122
 *
117
 *
123
 * @param stype     One of FIBRIL_SLEEP, FIBRIL_PREEMPT, FIBRIL_TO_MANAGER,
118
 * @param stype     Switch type. One of FIBRIL_PREEMPT, FIBRIL_TO_MANAGER,
124
 *          FIBRIL_FROM_MANAGER, FIBRIL_FROM_DEAD. The parameter
119
 *          FIBRIL_FROM_MANAGER, FIBRIL_FROM_DEAD. The parameter
125
 *          describes the circumstances of the switch.
120
 *          describes the circumstances of the switch.
126
 * @return      Return 0 if there is no ready fibril,
121
 * @return      Return 0 if there is no ready fibril,
127
 *          return 1 otherwise.
122
 *          return 1 otherwise.
128
 */
123
 */
129
int fibril_schedule_next_adv(fibril_switch_type_t stype)
124
int fibril_schedule_next_adv(fibril_switch_type_t stype)
130
{
125
{
131
    fibril_t *srcf, *dstf;
126
    fibril_t *srcf, *dstf;
132
    int retval = 0;
127
    int retval = 0;
133
   
128
   
134
    futex_down(&fibril_futex);
129
    futex_down(&fibril_futex);
135
 
130
 
136
    if (stype == FIBRIL_PREEMPT && list_empty(&ready_list))
131
    if (stype == FIBRIL_PREEMPT && list_empty(&ready_list))
137
        goto ret_0;
132
        goto ret_0;
138
    if (stype == FIBRIL_SLEEP) {
-
 
139
        if (list_empty(&ready_list) && list_empty(&serialized_list))
-
 
140
            goto ret_0;
-
 
141
    }
-
 
142
 
133
 
143
    if (stype == FIBRIL_FROM_MANAGER) {
134
    if (stype == FIBRIL_FROM_MANAGER) {
144
        if (list_empty(&ready_list) && list_empty(&serialized_list))
135
        if (list_empty(&ready_list) && list_empty(&serialized_list))
145
            goto ret_0;
136
            goto ret_0;
146
        /*
137
        /*
147
         * Do not preempt if there is not sufficient count of thread
138
         * Do not preempt if there is not sufficient count of fibril
148
         * managers.
139
         * managers.
149
         */
140
         */
150
        if (list_empty(&serialized_list) && fibrils_in_manager <=
141
        if (list_empty(&serialized_list) && fibrils_in_manager <=
151
            serialized_threads) {
142
            serialized_fibrils) {
152
            goto ret_0;
143
            goto ret_0;
153
        }
144
        }
154
    }
145
    }
155
    /* If we are going to manager and none exists, create it */
146
    /* If we are going to manager and none exists, create it */
156
    if (stype == FIBRIL_TO_MANAGER || stype == FIBRIL_FROM_DEAD) {
147
    if (stype == FIBRIL_TO_MANAGER || stype == FIBRIL_FROM_DEAD) {
157
        while (list_empty(&manager_list)) {
148
        while (list_empty(&manager_list)) {
158
            futex_up(&fibril_futex);
149
            futex_up(&fibril_futex);
159
            async_create_manager();
150
            async_create_manager();
160
            futex_down(&fibril_futex);
151
            futex_down(&fibril_futex);
161
        }
152
        }
162
    }
153
    }
163
   
154
   
164
    srcf = __tcb_get()->fibril_data;
155
    srcf = __tcb_get()->fibril_data;
165
    if (stype != FIBRIL_FROM_DEAD) {
156
    if (stype != FIBRIL_FROM_DEAD) {
166
        /* Save current state */
157
        /* Save current state */
167
        if (!context_save(&srcf->ctx)) {
158
        if (!context_save(&srcf->ctx)) {
168
            if (serialization_count)
159
            if (serialization_count)
169
                srcf->flags &= ~FIBRIL_SERIALIZED;
160
                srcf->flags &= ~FIBRIL_SERIALIZED;
170
            if (srcf->clean_after_me) {
161
            if (srcf->clean_after_me) {
171
                /*
162
                /*
172
                 * Cleanup after the dead fibril from which we
163
                 * Cleanup after the dead fibril from which we
173
                 * restored context here.
164
                 * restored context here.
174
                 */
165
                 */
175
                free(srcf->clean_after_me->stack);
166
                free(srcf->clean_after_me->stack);
176
                fibril_teardown(srcf->clean_after_me);
167
                fibril_teardown(srcf->clean_after_me);
177
                srcf->clean_after_me = NULL;
168
                srcf->clean_after_me = NULL;
178
            }
169
            }
179
            return 1;   /* futex_up already done here */
170
            return 1;   /* futex_up already done here */
180
        }
171
        }
181
 
172
 
182
        /* Save myself to the correct run list */
173
        /* Save myself to the correct run list */
183
        if (stype == FIBRIL_PREEMPT)
174
        if (stype == FIBRIL_PREEMPT)
184
            list_append(&srcf->link, &ready_list);
175
            list_append(&srcf->link, &ready_list);
185
        else if (stype == FIBRIL_FROM_MANAGER) {
176
        else if (stype == FIBRIL_FROM_MANAGER) {
186
            list_append(&srcf->link, &manager_list);
177
            list_append(&srcf->link, &manager_list);
187
            fibrils_in_manager--;
178
            fibrils_in_manager--;
188
        } else {   
179
        } else {   
189
            /*
180
            /*
190
             * If stype == FIBRIL_TO_MANAGER, don't put ourselves to
181
             * If stype == FIBRIL_TO_MANAGER, don't put ourselves to
191
             * any list, we should already be somewhere, or we will
182
             * any list, we should already be somewhere, or we will
192
             * be lost.
183
             * be lost.
193
             *
-
 
194
             * The stype == FIBRIL_SLEEP case is similar. The fibril
-
 
195
             * has an external refernce which can be used to wake it
-
 
196
             * up once that time has come.
-
 
197
             */
184
             */
198
        }
185
        }
199
    }
186
    }
200
 
187
 
201
    /* Choose a new fibril to run */
188
    /* Choose a new fibril to run */
202
    if (stype == FIBRIL_TO_MANAGER || stype == FIBRIL_FROM_DEAD) {
189
    if (stype == FIBRIL_TO_MANAGER || stype == FIBRIL_FROM_DEAD) {
203
        dstf = list_get_instance(manager_list.next, fibril_t, link);
190
        dstf = list_get_instance(manager_list.next, fibril_t, link);
204
        if (serialization_count && stype == FIBRIL_TO_MANAGER) {
191
        if (serialization_count && stype == FIBRIL_TO_MANAGER) {
205
            serialized_threads++;
192
            serialized_fibrils++;
206
            srcf->flags |= FIBRIL_SERIALIZED;
193
            srcf->flags |= FIBRIL_SERIALIZED;
207
        }
194
        }
208
        fibrils_in_manager++;
195
        fibrils_in_manager++;
209
 
196
 
210
        if (stype == FIBRIL_FROM_DEAD)
197
        if (stype == FIBRIL_FROM_DEAD)
211
            dstf->clean_after_me = srcf;
198
            dstf->clean_after_me = srcf;
212
    } else {
199
    } else {
213
        if (!list_empty(&serialized_list)) {
200
        if (!list_empty(&serialized_list)) {
214
            dstf = list_get_instance(serialized_list.next, fibril_t,
201
            dstf = list_get_instance(serialized_list.next, fibril_t,
215
                link);
202
                link);
216
            serialized_threads--;
203
            serialized_fibrils--;
217
        } else {
204
        } else {
218
            dstf = list_get_instance(ready_list.next, fibril_t,
205
            dstf = list_get_instance(ready_list.next, fibril_t,
219
                link);
206
                link);
220
        }
207
        }
221
    }
208
    }
222
    list_remove(&dstf->link);
209
    list_remove(&dstf->link);
223
 
210
 
224
    futex_up(&fibril_futex);
211
    futex_up(&fibril_futex);
225
    context_restore(&dstf->ctx);
212
    context_restore(&dstf->ctx);
226
    /* not reached */
213
    /* not reached */
227
 
214
 
228
ret_0:
215
ret_0:
229
    futex_up(&fibril_futex);
216
    futex_up(&fibril_futex);
230
    return retval;
217
    return retval;
231
}
218
}
232
 
219
 
233
/** Wait for fibril to finish.
-
 
234
 *
-
 
235
 * Each fibril can be only joined by one other fibril. Moreover, the joiner must
-
 
236
 * be from the same thread as the joinee.
-
 
237
 *
-
 
238
 * @param fid       Fibril to join.
-
 
239
 *
-
 
240
 * @return      Value returned by the completed fibril.
-
 
241
 */
-
 
242
int fibril_join(fid_t fid)
-
 
243
{
-
 
244
    fibril_t *f;
-
 
245
    fibril_t *cur;
-
 
246
 
-
 
247
    /* Handle fid = Kernel address -> it is wait for call */
-
 
248
    f = (fibril_t *) fid;
-
 
249
 
-
 
250
    /*
-
 
251
     * The joiner is running so the joinee isn't.
-
 
252
     */
-
 
253
    cur = __tcb_get()->fibril_data;
-
 
254
    f->joiner = cur;
-
 
255
    fibril_schedule_next_adv(FIBRIL_SLEEP);
-
 
256
 
-
 
257
    /*
-
 
258
     * The joinee fills in the return value.
-
 
259
     */
-
 
260
    return cur->joinee_retval;
-
 
261
}
-
 
262
 
-
 
263
/** Create a new fibril.
220
/** Create a new fibril.
264
 *
221
 *
265
 * @param func      Implementing function of the new fibril.
222
 * @param func      Implementing function of the new fibril.
266
 * @param arg       Argument to pass to func.
223
 * @param arg       Argument to pass to func.
267
 *
224
 *
268
 * @return      Return 0 on failure or TLS of the new fibril.
225
 * @return      Return 0 on failure or TLS of the new fibril.
269
 */
226
 */
270
fid_t fibril_create(int (*func)(void *), void *arg)
227
fid_t fibril_create(int (*func)(void *), void *arg)
271
{
228
{
272
    fibril_t *f;
229
    fibril_t *f;
273
 
230
 
274
    f = fibril_setup();
231
    f = fibril_setup();
275
    if (!f)
232
    if (!f)
276
        return 0;
233
        return 0;
277
    f->stack = (char *) malloc(FIBRIL_INITIAL_STACK_PAGES_NO *
234
    f->stack = (char *) malloc(FIBRIL_INITIAL_STACK_PAGES_NO *
278
        getpagesize());
235
        getpagesize());
279
 
236
 
280
    if (!f->stack) {
237
    if (!f->stack) {
281
        fibril_teardown(f);
238
        fibril_teardown(f);
282
        return 0;
239
        return 0;
283
    }
240
    }
284
 
241
 
285
    f->arg = arg;
242
    f->arg = arg;
286
    f->func = func;
243
    f->func = func;
287
    f->clean_after_me = NULL;
244
    f->clean_after_me = NULL;
288
    f->joiner = NULL;
-
 
289
    f->joinee_retval = 0;
-
 
290
    f->retval = 0;
245
    f->retval = 0;
291
    f->flags = 0;
246
    f->flags = 0;
292
 
247
 
293
    context_save(&f->ctx);
248
    context_save(&f->ctx);
294
    context_set(&f->ctx, FADDR(fibril_main), f->stack,
249
    context_set(&f->ctx, FADDR(fibril_main), f->stack,
295
        FIBRIL_INITIAL_STACK_PAGES_NO * getpagesize(), f->tcb);
250
        FIBRIL_INITIAL_STACK_PAGES_NO * getpagesize(), f->tcb);
296
 
251
 
297
    return (fid_t) f;
252
    return (fid_t) f;
298
}
253
}
299
 
254
 
300
/** Add a fibril to the ready list.
255
/** Add a fibril to the ready list.
301
 *
256
 *
302
 * @param fid       Pinter to the fibril structure of the fibril to be added.
257
 * @param fid       Pinter to the fibril structure of the fibril to be added.
303
 */
258
 */
304
void fibril_add_ready(fid_t fid)
259
void fibril_add_ready(fid_t fid)
305
{
260
{
306
    fibril_t *f;
261
    fibril_t *f;
307
 
262
 
308
    f = (fibril_t *) fid;
263
    f = (fibril_t *) fid;
309
    futex_down(&fibril_futex);
264
    futex_down(&fibril_futex);
310
    if ((f->flags & FIBRIL_SERIALIZED))
265
    if ((f->flags & FIBRIL_SERIALIZED))
311
        list_append(&f->link, &serialized_list);
266
        list_append(&f->link, &serialized_list);
312
    else
267
    else
313
        list_append(&f->link, &ready_list);
268
        list_append(&f->link, &ready_list);
314
    futex_up(&fibril_futex);
269
    futex_up(&fibril_futex);
315
}
270
}
316
 
271
 
317
/** Add a fibril to the manager list.
272
/** Add a fibril to the manager list.
318
 *
273
 *
319
 * @param fid       Pinter to the fibril structure of the fibril to be added.
274
 * @param fid       Pinter to the fibril structure of the fibril to be added.
320
 */
275
 */
321
void fibril_add_manager(fid_t fid)
276
void fibril_add_manager(fid_t fid)
322
{
277
{
323
    fibril_t *f;
278
    fibril_t *f;
324
 
279
 
325
    f = (fibril_t *) fid;
280
    f = (fibril_t *) fid;
326
 
281
 
327
    futex_down(&fibril_futex);
282
    futex_down(&fibril_futex);
328
    list_append(&f->link, &manager_list);
283
    list_append(&f->link, &manager_list);
329
    futex_up(&fibril_futex);
284
    futex_up(&fibril_futex);
330
}
285
}
331
 
286
 
332
/** Remove one manager from the manager list. */
287
/** Remove one manager from the manager list. */
333
void fibril_remove_manager(void)
288
void fibril_remove_manager(void)
334
{
289
{
335
    futex_down(&fibril_futex);
290
    futex_down(&fibril_futex);
336
    if (list_empty(&manager_list)) {
291
    if (list_empty(&manager_list)) {
337
        futex_up(&fibril_futex);
292
        futex_up(&fibril_futex);
338
        return;
293
        return;
339
    }
294
    }
340
    list_remove(manager_list.next);
295
    list_remove(manager_list.next);
341
    futex_up(&fibril_futex);
296
    futex_up(&fibril_futex);
342
}
297
}
343
 
298
 
344
/** Return fibril id of the currently running fibril.
299
/** Return fibril id of the currently running fibril.
345
 *
300
 *
346
 * @return      Fibril ID of the currently running pseudo thread.
301
 * @return      Fibril ID of the currently running pseudo thread.
347
 */
302
 */
348
fid_t fibril_get_id(void)
303
fid_t fibril_get_id(void)
349
{
304
{
350
    return (fid_t) __tcb_get()->fibril_data;
305
    return (fid_t) __tcb_get()->fibril_data;
351
}
306
}
352
 
307
 
353
/** Disable preemption
308
/** Disable preemption
354
 *
309
 *
355
 * If the fibril wants to send several message in a row and does not want to be
310
 * If the fibril wants to send several message in a row and does not want to be
356
 * preempted, it should start async_serialize_start() in the beginning of
311
 * preempted, it should start async_serialize_start() in the beginning of
357
 * communication and async_serialize_end() in the end. If it is a true
312
 * communication and async_serialize_end() in the end. If it is a true
358
 * multithreaded application, it should protect the communication channel by a
313
 * multithreaded application, it should protect the communication channel by a
359
 * futex as well. Interrupt messages can still be preempted.
314
 * futex as well. Interrupt messages can still be preempted.
360
 */
315
 */
361
void fibril_inc_sercount(void)
316
void fibril_inc_sercount(void)
362
{
317
{
363
    serialization_count++;
318
    serialization_count++;
364
}
319
}
365
 
320
 
366
/** Restore the preemption counter to the previous state. */
321
/** Restore the preemption counter to the previous state. */
367
void fibril_dec_sercount(void)
322
void fibril_dec_sercount(void)
368
{
323
{
369
    serialization_count--;
324
    serialization_count--;
370
}
325
}
371
 
326
 
372
/** @}
327
/** @}
373
 */
328
 */
374
 
329
 
375
 
330