blob: 91b8c19f81a015b632235716790e67491261088f [file] [log] [blame]
Brian Silverman14fd0fb2014-01-14 21:42:01 -08001#ifndef AOS_LINUX_CODE_INIT_H_
2#define AOS_LINUX_CODE_INIT_H_
brians343bc112013-02-10 01:53:46 +00003
Brian Silverman2fe007c2014-12-28 12:20:01 -08004#include <string>
5
brians343bc112013-02-10 01:53:46 +00006namespace aos {
7
Brian Silverman6da04272014-05-18 18:47:48 -07008// In order to use shared memory, one of the Init* functions must be called in
9// exactly 1 thread per process. It is OK to keep going without calling one of
10// them again after fork(2)ing.
11
brians343bc112013-02-10 01:53:46 +000012// Does the non-realtime parts of the initialization process.
Brian Silverman8f8debf2018-03-11 19:30:23 -070013// If for_realtime is true, this sets up to call GoRT later.
14void InitNRT(bool for_realtime = false);
brians343bc112013-02-10 01:53:46 +000015// Initializes everything, including the realtime stuff.
Brian Silvermanf3cfbd72013-10-28 16:26:09 -070016// relative_priority adjusts the priority of this process relative to all of the
17// other ones (positive for higher priority).
18void Init(int relative_priority = 0);
brians343bc112013-02-10 01:53:46 +000019// Same as InitNRT, except will remove an existing shared memory file and create
20// a new one.
21void InitCreate();
22// Cleans up (probably not going to get called very often because few things can
23// exit gracefully).
24void Cleanup();
25
Brian Silverman8f8debf2018-03-11 19:30:23 -070026// Performs the realtime parts of initialization after InitNRT(true) has been called.
27void GoRT(int relative_priority = 0);
28
Brian Silvermanfe1ef172014-04-12 17:12:45 -070029// Sets up this process to write core dump files.
Brian Silverman6da04272014-05-18 18:47:48 -070030// This is called by Init*, but it's here for other files that want this
31// behavior without calling Init*.
Brian Silvermanfe1ef172014-04-12 17:12:45 -070032void WriteCoreDumps();
33
Brian Silvermanda45b6c2014-12-28 11:36:50 -080034// Sets the current thread's realtime priority.
35void SetCurrentThreadRealtimePriority(int priority);
36
Brian Silvermana70994f2017-03-16 22:32:55 -070037// Sets the current thread back down to non-realtime priority.
38void UnsetCurrentThreadRealtimePriority();
39
Brian Silvermane4d8b282015-12-24 13:44:48 -080040// Pins the current thread to CPU #number.
41void PinCurrentThreadToCPU(int number);
42
Brian Silverman2fe007c2014-12-28 12:20:01 -080043// Sets the name of the current thread.
44// This will displayed by `top -H`, dump_rtprio, and show up in logs.
45// name can have a maximum of 16 characters.
46void SetCurrentThreadName(const ::std::string &name);
47
Austin Schuh3d4d5df2015-10-17 15:51:41 -070048void LockAllMemory();
49
brians343bc112013-02-10 01:53:46 +000050} // namespace aos
51
Brian Silverman14fd0fb2014-01-14 21:42:01 -080052#endif // AOS_LINUX_CODE_INIT_H_