1/*
2 * Copyright 2009, Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
5#ifndef SCHEDULER_H
6#define SCHEDULER_H
7
8
9#include <OS.h>
10
11
12/*!
13	To get a good thread priority, call suggest_thread_priority() with the
14	following information:
15		\a what is a bit mask describing what you're doing in the thread.
16		\a period is how many times a second your thread needs to run
17			(-1 if you're running continuously.)
18		\a jitter is an estimate (in us) of how much that period can vary,
19			as long as it stays centered on the average.
20		\a length is how long (in us) you expect to run for each invocation.
21			"Invocation" means, typically, receiving a message, dispatching
22			it, and then returning to reading a message.
23		MANIPULATION means both filtering and compression/decompression.
24		PLAYBACK and RECORDING means threads feeding/reading ACTUAL
25		HARDWARE ONLY.
26		0 means don't care
27*/
28
29/* bitmasks for suggest_thread_priority() */
30enum be_task_flags {
31	B_DEFAULT_MEDIA_PRIORITY	= 0x000,
32	B_OFFLINE_PROCESSING		= 0x001,
33	B_STATUS_RENDERING			= 0x002,	/* can also use this for */
34											/* "preview" type things */
35	B_USER_INPUT_HANDLING		= 0x004,
36	B_LIVE_VIDEO_MANIPULATION	= 0x008,	/* non-live processing is */
37											/* OFFLINE_PROCESSING */
38
39	B_VIDEO_PLAYBACK			= 0x010,	/* feeding hardware */
40	B_VIDEO_RECORDING			= 0x020,	/* grabbing from hardware */
41	B_LIVE_AUDIO_MANIPULATION	= 0x040,	/* non-live processing is */
42											/* OFFLINE_PROCESSING */
43
44	B_AUDIO_PLAYBACK			= 0x080,	/* feeding hardware */
45	B_AUDIO_RECORDING			= 0x100,	/* grabbing from hardware */
46	B_LIVE_3D_RENDERING			= 0x200,	/* non-live rendering is */
47											/* OFFLINE_PROCESSING */
48	B_NUMBER_CRUNCHING			= 0x400,
49	B_MIDI_PROCESSING			= 0x800
50};
51
52enum scheduler_mode {
53	SCHEDULER_MODE_LOW_LATENCY,
54	SCHEDULER_MODE_POWER_SAVING,
55};
56
57#if defined(__cplusplus)
58extern "C" {
59
60int32 suggest_thread_priority(uint32 task_flags = B_DEFAULT_MEDIA_PRIORITY,
61	int32 period = 0, bigtime_t jitter = 0, bigtime_t length = 0);
62
63bigtime_t estimate_max_scheduling_latency(thread_id th = -1);
64	/* default is current thread */
65
66status_t set_scheduler_mode(int32 mode);
67int32 get_scheduler_mode(void);
68
69}
70#else
71
72int32 suggest_thread_priority(uint32 what, int32 period, bigtime_t jitter,
73	bigtime_t length);
74
75bigtime_t estimate_max_scheduling_latency(thread_id th);
76	/* default is current thread */
77
78status_t set_scheduler_mode(int32 mode);
79int32 get_scheduler_mode(void);
80
81#endif
82
83#endif // SCHEDULER_H
84
85