Brian Silverman | 14fd0fb | 2014-01-14 21:42:01 -0800 | [diff] [blame] | 1 | #ifndef AOS_LINUX_CODE_INIT_H_ |
| 2 | #define AOS_LINUX_CODE_INIT_H_ |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 3 | |
Brian Silverman | 2fe007c | 2014-12-28 12:20:01 -0800 | [diff] [blame] | 4 | #include <string> |
| 5 | |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 6 | namespace aos { |
| 7 | |
Brian Silverman | 6da0427 | 2014-05-18 18:47:48 -0700 | [diff] [blame] | 8 | // 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 | |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 12 | // Does the non-realtime parts of the initialization process. |
| 13 | void InitNRT(); |
| 14 | // Initializes everything, including the realtime stuff. |
Brian Silverman | f3cfbd7 | 2013-10-28 16:26:09 -0700 | [diff] [blame] | 15 | // relative_priority adjusts the priority of this process relative to all of the |
| 16 | // other ones (positive for higher priority). |
| 17 | void Init(int relative_priority = 0); |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 18 | // Same as InitNRT, except will remove an existing shared memory file and create |
| 19 | // a new one. |
| 20 | void InitCreate(); |
| 21 | // Cleans up (probably not going to get called very often because few things can |
| 22 | // exit gracefully). |
| 23 | void Cleanup(); |
| 24 | |
Brian Silverman | fe1ef17 | 2014-04-12 17:12:45 -0700 | [diff] [blame] | 25 | // Sets up this process to write core dump files. |
Brian Silverman | 6da0427 | 2014-05-18 18:47:48 -0700 | [diff] [blame] | 26 | // This is called by Init*, but it's here for other files that want this |
| 27 | // behavior without calling Init*. |
Brian Silverman | fe1ef17 | 2014-04-12 17:12:45 -0700 | [diff] [blame] | 28 | void WriteCoreDumps(); |
| 29 | |
Brian Silverman | da45b6c | 2014-12-28 11:36:50 -0800 | [diff] [blame] | 30 | // Sets the current thread's realtime priority. |
| 31 | void SetCurrentThreadRealtimePriority(int priority); |
| 32 | |
Brian Silverman | a70994f | 2017-03-16 22:32:55 -0700 | [diff] [blame] | 33 | // Sets the current thread back down to non-realtime priority. |
| 34 | void UnsetCurrentThreadRealtimePriority(); |
| 35 | |
Brian Silverman | e4d8b28 | 2015-12-24 13:44:48 -0800 | [diff] [blame] | 36 | // Pins the current thread to CPU #number. |
| 37 | void PinCurrentThreadToCPU(int number); |
| 38 | |
Brian Silverman | 2fe007c | 2014-12-28 12:20:01 -0800 | [diff] [blame] | 39 | // Sets the name of the current thread. |
| 40 | // This will displayed by `top -H`, dump_rtprio, and show up in logs. |
| 41 | // name can have a maximum of 16 characters. |
| 42 | void SetCurrentThreadName(const ::std::string &name); |
| 43 | |
Austin Schuh | 3d4d5df | 2015-10-17 15:51:41 -0700 | [diff] [blame] | 44 | void LockAllMemory(); |
| 45 | |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 46 | } // namespace aos |
| 47 | |
Brian Silverman | 14fd0fb | 2014-01-14 21:42:01 -0800 | [diff] [blame] | 48 | #endif // AOS_LINUX_CODE_INIT_H_ |