blob: be99a241d30ffdd0c5cef42dbdf83df408f36d58 [file] [log] [blame]
John Park398c74a2018-10-20 21:17:39 -07001#ifndef AOS_INIT_H_
2#define AOS_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
Austin Schuh9fe68f72019-08-10 19:32:03 -070026// Locks everything into memory and sets the limits. This plus InitNRT are
27// everything you need to do before SetCurrentThreadRealtimePriority will make
28// your thread RT. Called as part of ShmEventLoop::Run()
29void InitRT();
30
Brian Silverman8f8debf2018-03-11 19:30:23 -070031// Performs the realtime parts of initialization after InitNRT(true) has been called.
32void GoRT(int relative_priority = 0);
33
Brian Silvermanfe1ef172014-04-12 17:12:45 -070034// Sets up this process to write core dump files.
Brian Silverman6da04272014-05-18 18:47:48 -070035// This is called by Init*, but it's here for other files that want this
36// behavior without calling Init*.
Brian Silvermanfe1ef172014-04-12 17:12:45 -070037void WriteCoreDumps();
38
Brian Silvermanda45b6c2014-12-28 11:36:50 -080039// Sets the current thread's realtime priority.
40void SetCurrentThreadRealtimePriority(int priority);
41
Brian Silvermana70994f2017-03-16 22:32:55 -070042// Sets the current thread back down to non-realtime priority.
43void UnsetCurrentThreadRealtimePriority();
44
Brian Silvermane4d8b282015-12-24 13:44:48 -080045// Pins the current thread to CPU #number.
46void PinCurrentThreadToCPU(int number);
47
Brian Silverman2fe007c2014-12-28 12:20:01 -080048// Sets the name of the current thread.
49// This will displayed by `top -H`, dump_rtprio, and show up in logs.
50// name can have a maximum of 16 characters.
51void SetCurrentThreadName(const ::std::string &name);
52
Austin Schuh3d4d5df2015-10-17 15:51:41 -070053void LockAllMemory();
54
brians343bc112013-02-10 01:53:46 +000055} // namespace aos
56
John Park398c74a2018-10-20 21:17:39 -070057#endif // AOS_INIT_H_