fiber.hh (13435:18fc735cae14) | fiber.hh (14042:7c548eb5c4c1) |
---|---|
1/* 2 * Copyright 2018 Google, Inc. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: redistributions of source code must retain the above copyright 7 * notice, this list of conditions and the following disclaimer; 8 * redistributions in binary form must reproduce the above copyright --- 68 unchanged lines hidden (view full) --- 77 /// Start executing the fiber represented by this object. This function 78 /// will "return" when the current fiber is switched back to later on. 79 void run(); 80 81 /// Returns whether the "main" function of this fiber has finished. 82 /// 83 bool finished() const { return _finished; }; 84 | 1/* 2 * Copyright 2018 Google, Inc. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: redistributions of source code must retain the above copyright 7 * notice, this list of conditions and the following disclaimer; 8 * redistributions in binary form must reproduce the above copyright --- 68 unchanged lines hidden (view full) --- 77 /// Start executing the fiber represented by this object. This function 78 /// will "return" when the current fiber is switched back to later on. 79 void run(); 80 81 /// Returns whether the "main" function of this fiber has finished. 82 /// 83 bool finished() const { return _finished; }; 84 |
85 /// Returns whether the "main" function of this fiber has started. 86 /// 87 bool started() const { return _started; }; 88 |
|
85 /// Get a pointer to the current running Fiber. 86 /// 87 static Fiber *currentFiber(); 88 /// Get a pointer to the primary Fiber. 89 /// This Fiber represents the thread of execution started by the OS, and 90 /// which has a Fiber attached to it after the fact. 91 static Fiber *primaryFiber(); 92 93 protected: 94 /// This method is called when this fiber is first run. Override it to 95 /// give your fiber something to do. When main returns, the fiber will 96 /// mark itself as finished and switch to its link fiber. 97 virtual void main() = 0; 98 | 89 /// Get a pointer to the current running Fiber. 90 /// 91 static Fiber *currentFiber(); 92 /// Get a pointer to the primary Fiber. 93 /// This Fiber represents the thread of execution started by the OS, and 94 /// which has a Fiber attached to it after the fact. 95 static Fiber *primaryFiber(); 96 97 protected: 98 /// This method is called when this fiber is first run. Override it to 99 /// give your fiber something to do. When main returns, the fiber will 100 /// mark itself as finished and switch to its link fiber. 101 virtual void main() = 0; 102 |
99 void setStarted() { started = true; } | 103 void setStarted() { _started = true; } |
100 101 private: 102 static void entryTrampoline(); 103 void start(); 104 105 ucontext_t ctx; 106 Fiber *link; 107 108 // The stack for this context, or a nullptr if allocated elsewhere. 109 void *stack; 110 size_t stackSize; 111 void *guardPage; 112 size_t guardPageSize; 113#if HAVE_VALGRIND 114 unsigned valgrindStackId; 115#endif 116 | 104 105 private: 106 static void entryTrampoline(); 107 void start(); 108 109 ucontext_t ctx; 110 Fiber *link; 111 112 // The stack for this context, or a nullptr if allocated elsewhere. 113 void *stack; 114 size_t stackSize; 115 void *guardPage; 116 size_t guardPageSize; 117#if HAVE_VALGRIND 118 unsigned valgrindStackId; 119#endif 120 |
117 bool started; | 121 bool _started; |
118 bool _finished; 119 void createContext(); 120}; 121 122#endif // __BASE_FIBER_HH__ | 122 bool _finished; 123 void createContext(); 124}; 125 126#endif // __BASE_FIBER_HH__ |