-
Notifications
You must be signed in to change notification settings - Fork 3
/
vcos_platform.lua
758 lines (618 loc) · 19.2 KB
/
vcos_platform.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
local ffi = require "ffi"
--[[
=============================================================================
VideoCore OS Abstraction Layer - pthreads types
=============================================================================
--]]
-- Do not include this file directly - instead include it via vcos.h
--[[
#include <pthread.h>
#include <semaphore.h>
#include <unistd.h>
#include <sys/types.h>
#include <sched.h>
#include <errno.h>
#include <string.h>
#include <strings.h>
#include <time.h>
#include <signal.h>
#include <stddef.h>
#include <stdlib.h>
--]]
VCOS_HAVE_RTOS = true;
VCOS_HAVE_SEMAPHORE = true;
VCOS_HAVE_EVENT = true;
VCOS_HAVE_QUEUE = false;
VCOS_HAVE_LEGACY_ISR = false;
VCOS_HAVE_TIMER = true;
VCOS_HAVE_CANCELLATION_SAFE_TIMER = true;
VCOS_HAVE_MEMPOOL = false;
VCOS_HAVE_ISR = false;
VCOS_HAVE_ATOMIC_FLAGS = true;
VCOS_HAVE_THREAD_AT_EXIT = true;
VCOS_HAVE_ONCE = true;
VCOS_HAVE_BLOCK_POOL = true;
VCOS_HAVE_FILE = false;
VCOS_HAVE_PROC = false;
VCOS_HAVE_CFG = false;
VCOS_HAVE_ALIEN_THREADS = true;
VCOS_HAVE_CMD = true;
VCOS_HAVE_EVENT_FLAGS = true;
VCOS_WANT_LOG_CMD = false; -- User apps should do their own thing
VCOS_ALWAYS_WANT_LOGGING = false;
VCOS_HAVE_BACKTRACE = true;
VCOS_SO_EXT = ".so";
-- Linux/pthreads seems to have different timer characteristics
VCOS_TIMER_MARGIN_EARLY = 0;
VCOS_TIMER_MARGIN_LATE = 15;
--BUGBUG
VCOS_TICKS_PER_SECOND = 1000;
--local lib = ffi.load("bcm_host");
--VCOS_TICKS_PER_SECOND = lib._vcos_get_ticks_per_second();
ffi.cdef[[
typedef int sem_t;
typedef int pthread_key_t;
typedef int pthread_once_t;
typedef sem_t VCOS_SEMAPHORE_T;
typedef uint32_t VCOS_UNSIGNED;
typedef uint32_t VCOS_OPTION;
typedef pthread_key_t VCOS_TLS_KEY_T;
typedef pthread_once_t VCOS_ONCE_T;
]]
--[===[
ffi.cdef[[
typedef sem_t VCOS_SEMAPHORE_T;
typedef uint32_t VCOS_UNSIGNED;
typedef uint32_t VCOS_OPTION;
typedef pthread_key_t VCOS_TLS_KEY_T;
typedef pthread_once_t VCOS_ONCE_T;
typedef struct VCOS_LLTHREAD_T
{
pthread_t thread; // Must be first field.
} VCOS_LLTHREAD_T;
/* VCOS_CASSERT(offsetof(VCOS_LLTHREAD_T, thread) == 0); */
--]]
if not VCOS_USE_VCOS_FUTEX then
ffi.cdef[[
typedef pthread_mutex_t VCOS_MUTEX_T;
]]
else
-- VCOS_USE_VCOS_FUTEX
require "vcos_futex_mutex"
end
ffi.cdef[[
typedef struct
{
VCOS_MUTEX_T mutex;
sem_t sem;
} VCOS_EVENT_T;
]]
VCOS_ONCE_INIT = PTHREAD_ONCE_INIT
--#if defined(__arm__) && !defined(_HAVE_TIMER_T) && !defined(ANDROID)
ffi.cdef[[
typedef __timer_t timer_t;
]]
--#endif
ffi.cdef[[
typedef struct VCOS_TIMER_T
{
pthread_t thread; /**< id of the timer thread */
pthread_mutex_t lock; /**< lock protecting all other members of the struct */
pthread_cond_t settings_changed; /**< cond. var. for informing the timer thread about changes*/
int quit; /**< non-zero if the timer thread is requested to quit*/
struct timespec expires; /**< absolute time of next expiration, or 0 if disarmed*/
void (*orig_expiration_routine)(void*);/**< the expiration routine provided by the user of the timer*/
void *orig_context; /**< the context for exp. routine provided by the user*/
} VCOS_TIMER_T;
/** Thread attribute structure. Don't use pthread_attr directly, as
* the calls can fail, and inits must match deletes.
*/
typedef struct VCOS_THREAD_ATTR_T
{
void *ta_stackaddr;
VCOS_UNSIGNED ta_stacksz;
VCOS_UNSIGNED ta_priority;
VCOS_UNSIGNED ta_affinity;
VCOS_UNSIGNED ta_timeslice;
VCOS_UNSIGNED legacy;
} VCOS_THREAD_ATTR_T;
/** Called at thread exit.
*/
typedef struct VCOS_THREAD_EXIT_T
{
void (*pfn)(void *);
void *cxt;
} VCOS_THREAD_EXIT_T;
static const int VCOS_MAX_EXIT_HANDLERS = 4;
typedef struct VCOS_THREAD_T
{
pthread_t thread; /**< The thread itself */
VCOS_THREAD_ENTRY_FN_T entry; /**< The thread entry point */
void *arg; /**< The argument to be passed to entry */
VCOS_SEMAPHORE_T suspend; /**< For support event groups and similar - a per thread semaphore */
VCOS_TIMER_T task_timer;
int task_timer_created; /**< non-zero if the task timer has already been created*/
void (*orig_task_timer_expiration_routine)(void*);
void *orig_task_timer_context;
VCOS_UNSIGNED legacy;
char name[16]; /**< Record the name of this thread, for diagnostics */
VCOS_UNSIGNED dummy; /**< Dummy thread created for non-vcos created threads */
/** Callback invoked at thread exit time */
VCOS_THREAD_EXIT_T at_exit[VCOS_MAX_EXIT_HANDLERS];
} VCOS_THREAD_T;
]]
if VCOS_PTHREADS_WANT_HISR_EMULATION then
ffi.cdef[[
typedef struct
{
VCOS_THREAD_T thread;
char stack[1024];
VCOS_SEMAPHORE_T waitsem;
} VCOS_HISR_T;
]]
end
VCOS_SUSPEND = -1;
VCOS_NO_SUSPEND = 0;
VCOS_START = 1;
VCOS_NO_START = 0;
VCOS_THREAD_PRI_MIN = (sched_get_priority_min(SCHED_OTHER))
VCOS_THREAD_PRI_MAX = (sched_get_priority_max(SCHED_OTHER))
VCOS_THREAD_PRI_INCREASE = 1
VCOS_THREAD_PRI_HIGHEST =VCOS_THREAD_PRI_MAX
VCOS_THREAD_PRI_LOWEST =VCOS_THREAD_PRI_MIN
VCOS_THREAD_PRI_NORMAL =((VCOS_THREAD_PRI_MAX+VCOS_THREAD_PRI_MIN)/2)
VCOS_THREAD_PRI_BELOW_NORMAL =(VCOS_THREAD_PRI_NORMAL-VCOS_THREAD_PRI_INCREASE)
VCOS_THREAD_PRI_ABOVE_NORMAL =(VCOS_THREAD_PRI_NORMAL+VCOS_THREAD_PRI_INCREASE)
VCOS_THREAD_PRI_REALTIME =VCOS_THREAD_PRI_MAX
_VCOS_AFFINITY_DEFAULT =0
_VCOS_AFFINITY_CPU0 =0x100
_VCOS_AFFINITY_CPU1 =0x200
_VCOS_AFFINITY_MASK =0x300
VCOS_CAN_SET_STACK_ADDR =0
--]===]
--[[
require "interface/vcos/generic/vcos_generic_event_flags.h"
require "interface/vcos/generic/vcos_generic_blockpool.h"
require "interface/vcos/generic/vcos_mem_from_malloc.h"
--]]
--[==[
ffi.cdef[[
/** Convert errno values into the values recognized by vcos */
VCOSPRE_ VCOS_STATUS_T vcos_pthreads_map_error(int error);
VCOSPRE_ VCOS_STATUS_T VCOSPOST_ vcos_pthreads_map_errno(void);
/** Register a function to be called when the current thread exits.
*/
extern VCOS_STATUS_T vcos_thread_at_exit(void (*pfn)(void*), void *cxt);
extern uint32_t _vcos_get_ticks_per_second(void);
/**
* Set to 1 by default when ANDROID is defined. Allows runtime
* switching for console apps.
*/
extern int vcos_use_android_log;
typedef struct {
VCOS_MUTEX_T mutex;
uint32_t flags;
} VCOS_ATOMIC_FLAGS_T;
]]
#if defined(VCOS_INLINE_BODIES)
#undef VCOS_ASSERT_LOGGING_DISABLE
#define VCOS_ASSERT_LOGGING_DISABLE 1
/*
* Counted Semaphores
*/
VCOS_INLINE_IMPL
VCOS_STATUS_T vcos_semaphore_wait(VCOS_SEMAPHORE_T *sem) {
int ret;
/* gdb causes sem_wait() to EINTR when a breakpoint is hit, retry here */
while ((ret = sem_wait(sem)) == -1 && errno == EINTR)
continue;
vcos_assert(ret==0);
return VCOS_SUCCESS;
}
VCOS_INLINE_IMPL
VCOS_STATUS_T vcos_semaphore_trywait(VCOS_SEMAPHORE_T *sem) {
int ret;
while ((ret = sem_trywait(sem)) == -1 && errno == EINTR)
continue;
if (ret == 0)
return VCOS_SUCCESS;
else if (errno == EAGAIN)
return VCOS_EAGAIN;
else {
vcos_assert(0);
return VCOS_EINVAL;
}
}
/**
* \brief Wait on a semaphore with a timeout.
*
* Note that this function may not be implemented on all
* platforms, and may not be efficient on all platforms
* (see comment in vcos_semaphore_wait)
*
* Try to obtain the semaphore. If it is already taken, return
* VCOS_EAGAIN.
* @param sem Semaphore to wait on
* @param timeout Number of milliseconds to wait before
* returning if the semaphore can't be acquired.
* @return VCOS_SUCCESS - semaphore was taken.
* VCOS_EAGAIN - could not take semaphore (i.e. timeout
* expired)
* VCOS_EINVAL - Some other error (most likely bad
* parameters).
*/
VCOS_INLINE_IMPL
VCOS_STATUS_T vcos_semaphore_wait_timeout(VCOS_SEMAPHORE_T *sem, VCOS_UNSIGNED timeout) {
struct timespec ts;
int ret;
ts.tv_sec = timeout/1000;
ts.tv_nsec = (timeout%1000)*1000*1000;
ret = sem_timedwait( sem, &ts );
if (ret == 0)
return VCOS_SUCCESS;
else if (ret == ETIMEDOUT)
return VCOS_EAGAIN;
else {
vcos_assert(0);
return VCOS_EINVAL;
}
}
VCOS_INLINE_IMPL
VCOS_STATUS_T vcos_semaphore_create(VCOS_SEMAPHORE_T *sem,
const char *name,
VCOS_UNSIGNED initial_count) {
int rc = sem_init(sem, 0, initial_count);
(void)name;
if (rc != -1) return VCOS_SUCCESS;
else return vcos_pthreads_map_errno();
}
VCOS_INLINE_IMPL
void vcos_semaphore_delete(VCOS_SEMAPHORE_T *sem) {
int rc = sem_destroy(sem);
vcos_assert(rc != -1);
(void)rc;
}
VCOS_INLINE_IMPL
VCOS_STATUS_T vcos_semaphore_post(VCOS_SEMAPHORE_T *sem) {
int rc = sem_post(sem);
vcos_assert(rc == 0);
(void)rc;
return VCOS_SUCCESS;
}
/***********************************************************
*
* Threads
*
***********************************************************/
extern VCOS_THREAD_T *vcos_dummy_thread_create(void);
extern pthread_key_t _vcos_thread_current_key;
extern uint64_t vcos_getmicrosecs64_internal(void);
VCOS_INLINE_IMPL
uint32_t vcos_getmicrosecs(void) { return (uint32_t)vcos_getmicrosecs64_internal(); }
VCOS_INLINE_IMPL
uint64_t vcos_getmicrosecs64(void) { return vcos_getmicrosecs64_internal(); }
VCOS_INLINE_IMPL
VCOS_THREAD_T *vcos_thread_current(void) {
void *ret = pthread_getspecific(_vcos_thread_current_key);
if (ret == NULL)
{
ret = vcos_dummy_thread_create();
}
#ifdef __cplusplus
return static_cast<VCOS_THREAD_T*>(ret);
#else
return (VCOS_THREAD_T *)ret;
#endif
}
VCOS_INLINE_IMPL
void vcos_sleep(uint32_t ms) {
struct timespec ts;
ts.tv_sec = ms/1000;
ts.tv_nsec = ms % 1000 * (1000000);
nanosleep(&ts, NULL);
}
VCOS_INLINE_IMPL
void vcos_thread_attr_setstack(VCOS_THREAD_ATTR_T *attr, void *addr, VCOS_UNSIGNED sz) {
attr->ta_stackaddr = addr;
attr->ta_stacksz = sz;
}
VCOS_INLINE_IMPL
void vcos_thread_attr_setstacksize(VCOS_THREAD_ATTR_T *attr, VCOS_UNSIGNED sz) {
attr->ta_stacksz = sz;
}
VCOS_INLINE_IMPL
void vcos_thread_attr_setpriority(VCOS_THREAD_ATTR_T *attr, VCOS_UNSIGNED pri) {
(void)attr;
(void)pri;
}
VCOS_INLINE_IMPL
void vcos_thread_set_priority(VCOS_THREAD_T *thread, VCOS_UNSIGNED p) {
/* not implemented */
(void)thread;
(void)p;
}
VCOS_INLINE_IMPL
VCOS_UNSIGNED vcos_thread_get_priority(VCOS_THREAD_T *thread) {
/* not implemented */
(void)thread;
return 0;
}
VCOS_INLINE_IMPL
void vcos_thread_set_affinity(VCOS_THREAD_T *thread, VCOS_UNSIGNED affinity) {
/* not implemented */
vcos_unused(thread);
vcos_unused(affinity);
}
VCOS_INLINE_IMPL
void vcos_thread_attr_setaffinity(VCOS_THREAD_ATTR_T *attrs, VCOS_UNSIGNED affinity) {
attrs->ta_affinity = affinity;
}
VCOS_INLINE_IMPL
void vcos_thread_attr_settimeslice(VCOS_THREAD_ATTR_T *attrs, VCOS_UNSIGNED ts) {
attrs->ta_timeslice = ts;
}
VCOS_INLINE_IMPL
void _vcos_thread_attr_setlegacyapi(VCOS_THREAD_ATTR_T *attrs, VCOS_UNSIGNED legacy) {
attrs->legacy = legacy;
}
VCOS_INLINE_IMPL
void vcos_thread_attr_setautostart(VCOS_THREAD_ATTR_T *attrs, VCOS_UNSIGNED autostart) {
(void)attrs;
(void)autostart;
}
VCOS_INLINE_IMPL
VCOS_LLTHREAD_T *vcos_llthread_current(void) {
return (VCOS_LLTHREAD_T *)pthread_self();
}
/*
* Mutexes
*/
#ifndef VCOS_USE_VCOS_FUTEX
VCOS_INLINE_IMPL
VCOS_STATUS_T vcos_mutex_create(VCOS_MUTEX_T *latch, const char *name) {
int rc = pthread_mutex_init(latch, NULL);
(void)name;
if (rc == 0) return VCOS_SUCCESS;
else return vcos_pthreads_map_errno();
}
VCOS_INLINE_IMPL
void vcos_mutex_delete(VCOS_MUTEX_T *latch) {
int rc = pthread_mutex_destroy(latch);
(void)rc;
vcos_assert(rc==0);
}
VCOS_INLINE_IMPL
VCOS_STATUS_T vcos_mutex_lock(VCOS_MUTEX_T *latch) {
int rc = pthread_mutex_lock(latch);
vcos_assert(rc==0);
(void)rc;
return VCOS_SUCCESS;
}
VCOS_INLINE_IMPL
void vcos_mutex_unlock(VCOS_MUTEX_T *latch) {
int rc = pthread_mutex_unlock(latch);
(void)rc;
vcos_assert(rc==0);
}
VCOS_INLINE_IMPL
int vcos_mutex_is_locked(VCOS_MUTEX_T *m) {
int rc = pthread_mutex_trylock(m);
if (rc == 0) {
pthread_mutex_unlock(m);
/* it wasn't locked */
return 0;
}
else {
return 1; /* it was locked */
}
}
VCOS_INLINE_IMPL
VCOS_STATUS_T vcos_mutex_trylock(VCOS_MUTEX_T *m) {
int rc = pthread_mutex_trylock(m);
(void)rc;
return (rc == 0) ? VCOS_SUCCESS : VCOS_EAGAIN;
}
#endif /* VCOS_USE_VCOS_FUTEX */
/*
* Events
*/
VCOS_INLINE_IMPL
VCOS_STATUS_T vcos_event_create(VCOS_EVENT_T *event, const char *debug_name)
{
VCOS_STATUS_T status;
int rc = sem_init(&event->sem, 0, 0);
if (rc != 0) return vcos_pthreads_map_errno();
status = vcos_mutex_create(&event->mutex, debug_name);
if (status != VCOS_SUCCESS) {
sem_destroy(&event->sem);
return status;
}
return VCOS_SUCCESS;
}
VCOS_INLINE_IMPL
void vcos_event_signal(VCOS_EVENT_T *event)
{
int ok = 0;
int value;
if (vcos_mutex_lock(&event->mutex) != VCOS_SUCCESS)
goto fail_mtx;
if (sem_getvalue(&event->sem, &value) != 0)
goto fail_sem;
if (value == 0)
if (sem_post(&event->sem) != 0)
goto fail_sem;
ok = 1;
fail_sem:
vcos_mutex_unlock(&event->mutex);
fail_mtx:
vcos_assert(ok);
}
VCOS_INLINE_IMPL
VCOS_STATUS_T vcos_event_wait(VCOS_EVENT_T *event)
{
int ret;
/* gdb causes sem_wait() to EINTR when a breakpoint is hit, retry here */
while ((ret = sem_wait(&event->sem)) == -1 && errno == EINTR)
continue;
vcos_assert(ret==0);
return ret == 0 ? VCOS_SUCCESS : (VCOS_STATUS_T)errno;
}
VCOS_INLINE_IMPL
VCOS_STATUS_T vcos_event_try(VCOS_EVENT_T *event)
{
int ret;
while ((ret = sem_trywait(&event->sem)) == -1 && errno == EINTR)
continue;
if (ret == -1 && errno == EAGAIN)
return VCOS_EAGAIN;
else
return VCOS_SUCCESS;
}
VCOS_INLINE_IMPL
void vcos_event_delete(VCOS_EVENT_T *event)
{
int rc = sem_destroy(&event->sem);
vcos_assert(rc != -1);
(void)rc;
vcos_mutex_delete(&event->mutex);
}
VCOS_INLINE_IMPL
VCOS_UNSIGNED vcos_process_id_current(void) {
return (VCOS_UNSIGNED) getpid();
}
VCOS_INLINE_IMPL
int vcos_strcasecmp(const char *s1, const char *s2) {
return strcasecmp(s1,s2);
}
VCOS_INLINE_IMPL
int vcos_strncasecmp(const char *s1, const char *s2, size_t n) {
return strncasecmp(s1,s2,n);
}
VCOS_INLINE_IMPL
int vcos_in_interrupt(void) {
return 0;
}
/* For support event groups - per thread semaphore */
VCOS_INLINE_IMPL
void _vcos_thread_sem_wait(void) {
VCOS_THREAD_T *t = vcos_thread_current();
vcos_semaphore_wait(&t->suspend);
}
VCOS_INLINE_IMPL
void _vcos_thread_sem_post(VCOS_THREAD_T *target) {
vcos_semaphore_post(&target->suspend);
}
VCOS_INLINE_IMPL
VCOS_STATUS_T vcos_tls_create(VCOS_TLS_KEY_T *key) {
int st = pthread_key_create(key, NULL);
return st == 0 ? VCOS_SUCCESS: VCOS_ENOMEM;
}
VCOS_INLINE_IMPL
void vcos_tls_delete(VCOS_TLS_KEY_T tls) {
pthread_key_delete(tls);
}
VCOS_INLINE_IMPL
VCOS_STATUS_T vcos_tls_set(VCOS_TLS_KEY_T tls, void *v) {
pthread_setspecific(tls, v);
return VCOS_SUCCESS;
}
VCOS_INLINE_IMPL
void *vcos_tls_get(VCOS_TLS_KEY_T tls) {
return pthread_getspecific(tls);
}
#if VCOS_HAVE_ATOMIC_FLAGS
/*
* Atomic flags
*/
/* TODO implement properly... */
VCOS_INLINE_IMPL
VCOS_STATUS_T vcos_atomic_flags_create(VCOS_ATOMIC_FLAGS_T *atomic_flags)
{
atomic_flags->flags = 0;
return vcos_mutex_create(&atomic_flags->mutex, "VCOS_ATOMIC_FLAGS_T");
}
VCOS_INLINE_IMPL
void vcos_atomic_flags_or(VCOS_ATOMIC_FLAGS_T *atomic_flags, uint32_t flags)
{
vcos_mutex_lock(&atomic_flags->mutex);
atomic_flags->flags |= flags;
vcos_mutex_unlock(&atomic_flags->mutex);
}
VCOS_INLINE_IMPL
uint32_t vcos_atomic_flags_get_and_clear(VCOS_ATOMIC_FLAGS_T *atomic_flags)
{
uint32_t flags;
vcos_mutex_lock(&atomic_flags->mutex);
flags = atomic_flags->flags;
atomic_flags->flags = 0;
vcos_mutex_unlock(&atomic_flags->mutex);
return flags;
}
VCOS_INLINE_IMPL
void vcos_atomic_flags_delete(VCOS_ATOMIC_FLAGS_T *atomic_flags)
{
vcos_mutex_delete(&atomic_flags->mutex);
}
#endif
#if defined(linux) || defined(_HAVE_SBRK)
/* not exactly the free memory, but a measure of it */
VCOS_INLINE_IMPL
unsigned long vcos_get_free_mem(void) {
return (unsigned long)sbrk(0);
}
#endif
#ifdef VCOS_PTHREADS_WANT_HISR_EMULATION
VCOS_STATUS_T vcos_legacy_hisr_create(VCOS_HISR_T *hisr, const char *name,
void (*entry)(void),
VCOS_UNSIGNED pri,
void *stack, VCOS_UNSIGNED stack_size);
void vcos_legacy_hisr_activate(VCOS_HISR_T *hisr);
void vcos_legacy_hisr_delete(VCOS_HISR_T *hisr);
#endif
#undef VCOS_ASSERT_LOGGING_DISABLE
#define VCOS_ASSERT_LOGGING_DISABLE 0
#endif /* VCOS_INLINE_BODIES */
#define vcos_log_platform_init() _vcos_log_platform_init()
VCOSPRE_ void VCOSPOST_ _vcos_log_platform_init(void);
VCOS_INLINE_DECL void _vcos_thread_sem_wait(void);
VCOS_INLINE_DECL void _vcos_thread_sem_post(VCOS_THREAD_T *);
#define VCOS_APPLICATION_ARGC vcos_get_argc()
#define VCOS_APPLICATION_ARGV vcos_get_argv()
require "interface/vcos/generic/vcos_generic_reentrant_mtx.h"
require "interface/vcos/generic/vcos_generic_named_sem.h"
require "interface/vcos/generic/vcos_generic_quickslow_mutex.h"
require "interface/vcos/generic/vcos_common.h"
#define _VCOS_LOG_LEVEL() getenv("VC_LOGLEVEL")
VCOS_STATIC_INLINE
char *vcos_strdup(const char *str)
{
return strdup(str);
}
typedef void (*VCOS_ISR_HANDLER_T)(VCOS_UNSIGNED vecnum);
--]==]
--[[
/*
Copyright (c) 2012, Broadcom Europe Ltd
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
--]]