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