Lines Matching refs:thread

21 #include "osi/include/thread.h"
52 thread_t* thread;
85 start.thread = ret;
108 void thread_free(thread_t* thread) {
109 if (!thread) return;
111 thread_stop(thread);
112 thread_join(thread);
114 fixed_queue_free(thread->work_queue, osi_free);
115 reactor_free(thread->reactor);
116 osi_free(thread);
119 void thread_join(thread_t* thread) {
120 CHECK(thread != NULL);
122 if (!std::atomic_exchange(&thread->is_joined, true))
123 pthread_join(thread->pthread, NULL);
126 bool thread_post(thread_t* thread, thread_fn func, void* context) {
127 CHECK(thread != NULL);
130 // TODO(sharvil): if the current thread == |thread| and we've run out
139 fixed_queue_enqueue(thread->work_queue, item);
143 void thread_stop(thread_t* thread) {
144 CHECK(thread != NULL);
145 reactor_stop(thread->reactor);
148 bool thread_set_priority(thread_t* thread, int priority) {
149 if (!thread) return false;
151 const int rc = setpriority(PRIO_PROCESS, thread->tid, priority);
154 "%s unable to set thread priority %d for tid %d, error %d",
155 __func__, priority, thread->tid, rc);
162 bool thread_set_rt_priority(thread_t* thread, int priority) {
163 if (!thread) return false;
168 const int rc = sched_setscheduler(thread->tid, SCHED_FIFO, &rt_params);
172 __func__, priority, thread->tid, strerror(errno));
179 bool thread_is_self(const thread_t* thread) {
180 CHECK(thread != NULL);
181 return !!pthread_equal(pthread_self(), thread->pthread);
184 reactor_t* thread_get_reactor(const thread_t* thread) {
185 CHECK(thread != NULL);
186 return thread->reactor;
189 const char* thread_name(const thread_t* thread) {
190 CHECK(thread != NULL);
191 return thread->name;
198 thread_t* thread = start->thread;
200 CHECK(thread != NULL);
202 if (prctl(PR_SET_NAME, (unsigned long)thread->name) == -1) {
203 LOG_ERROR(LOG_TAG, "%s unable to set thread name: %s", __func__,
209 thread->tid = gettid();
211 LOG_INFO(LOG_TAG, "%s: thread id %d, thread name %s started", __func__,
212 thread->tid, thread->name);
216 int fd = fixed_queue_get_dequeue_fd(thread->work_queue);
217 void* context = thread->work_queue;
220 reactor_register(thread->reactor, fd, context, work_queue_read_cb, NULL);
221 reactor_start(thread->reactor);
224 // Make sure we dispatch all queued work items before exiting the thread.
226 // work item and then joining the thread.
229 static_cast<work_item_t*>(fixed_queue_try_dequeue(thread->work_queue));
230 while (item && count <= fixed_queue_capacity(thread->work_queue)) {
234 static_cast<work_item_t*>(fixed_queue_try_dequeue(thread->work_queue));
238 if (count > fixed_queue_capacity(thread->work_queue))
241 LOG_WARN(LOG_TAG, "%s: thread id %d, thread name %s exited", __func__,
242 thread->tid, thread->name);