• Home
  • Raw
  • Download

Lines Matching refs:h

101 static inline void close_cmd_fd(int h);
103 static inline void add_poll(int h, int fd, int type, int flags, uint32_t user_id);
150 static void free_thread_slot(int h) in free_thread_slot() argument
152 if(0 <= h && h < MAX_THREAD) in free_thread_slot()
154 close_cmd_fd(h); in free_thread_slot()
155 ts[h].used = 0; in free_thread_slot()
157 else APPL_TRACE_ERROR("invalid thread handle:%d", h); in free_thread_slot()
166 int h; in btsock_thread_init() local
167 for(h = 0; h < MAX_THREAD; h++) in btsock_thread_init()
169 ts[h].cmd_fdr = ts[h].cmd_fdw = -1; in btsock_thread_init()
170 ts[h].used = 0; in btsock_thread_init()
171 ts[h].thread_id = -1; in btsock_thread_init()
172 ts[h].poll_count = 0; in btsock_thread_init()
173 ts[h].callback = NULL; in btsock_thread_init()
174 ts[h].cmd_callback = NULL; in btsock_thread_init()
183 int h = alloc_thread_slot(); in btsock_thread_create() local
185 APPL_TRACE_DEBUG("alloc_thread_slot ret:%d", h); in btsock_thread_create()
186 if(h >= 0) in btsock_thread_create()
188 init_poll(h); in btsock_thread_create()
190 int status = create_thread(sock_poll_thread, (void*)(uintptr_t)h, &thread); in btsock_thread_create()
194 free_thread_slot(h); in btsock_thread_create()
198 ts[h].thread_id = thread; in btsock_thread_create()
199 APPL_TRACE_DEBUG("h:%d, thread id:%d", h, ts[h].thread_id); in btsock_thread_create()
200 ts[h].callback = callback; in btsock_thread_create()
201 ts[h].cmd_callback = cmd_callback; in btsock_thread_create()
203 return h; in btsock_thread_create()
207 static inline void init_cmd_fd(int h) in init_cmd_fd() argument
209 asrt(ts[h].cmd_fdr == -1 && ts[h].cmd_fdw == -1); in init_cmd_fd()
210 if(socketpair(AF_UNIX, SOCK_STREAM, 0, &ts[h].cmd_fdr) < 0) in init_cmd_fd()
215 APPL_TRACE_DEBUG("h:%d, cmd_fdr:%d, cmd_fdw:%d", h, ts[h].cmd_fdr, ts[h].cmd_fdw); in init_cmd_fd()
217 add_poll(h, ts[h].cmd_fdr, 0, SOCK_THREAD_FD_RD, 0); in init_cmd_fd()
219 static inline void close_cmd_fd(int h) in close_cmd_fd() argument
221 if(ts[h].cmd_fdr != -1) in close_cmd_fd()
223 close(ts[h].cmd_fdr); in close_cmd_fd()
224 ts[h].cmd_fdr = -1; in close_cmd_fd()
226 if(ts[h].cmd_fdw != -1) in close_cmd_fd()
228 close(ts[h].cmd_fdw); in close_cmd_fd()
229 ts[h].cmd_fdw = -1; in close_cmd_fd()
240 int btsock_thread_add_fd(int h, int fd, int type, int flags, uint32_t user_id) in btsock_thread_add_fd() argument
242 if(h < 0 || h >= MAX_THREAD) in btsock_thread_add_fd()
244 APPL_TRACE_ERROR("invalid bt thread handle:%d", h); in btsock_thread_add_fd()
247 if(ts[h].cmd_fdw == -1) in btsock_thread_add_fd()
255 if(ts[h].thread_id == pthread_self()) in btsock_thread_add_fd()
259 add_poll(h, fd, type, flags, user_id); in btsock_thread_add_fd()
268 OSI_NO_INTR(ret = send(ts[h].cmd_fdw, &cmd, sizeof(cmd), 0)); in btsock_thread_add_fd()
294 int btsock_thread_post_cmd(int h, int type, const unsigned char* data, int size, uint32_t user_id) in btsock_thread_post_cmd() argument
296 if(h < 0 || h >= MAX_THREAD) in btsock_thread_post_cmd()
298 APPL_TRACE_ERROR("invalid bt thread handle:%d", h); in btsock_thread_post_cmd()
301 if(ts[h].cmd_fdw == -1) in btsock_thread_post_cmd()
307 APPL_TRACE_DEBUG("post cmd type:%d, size:%d, h:%d, ", type, size, h); in btsock_thread_post_cmd()
321 APPL_TRACE_ERROR("alloca failed at h:%d, cmd type:%d, size:%d", h, type, size_send); in btsock_thread_post_cmd()
327 OSI_NO_INTR(ret = send(ts[h].cmd_fdw, cmd_send, size_send, 0)); in btsock_thread_post_cmd()
331 int btsock_thread_wakeup(int h) in btsock_thread_wakeup() argument
333 if(h < 0 || h >= MAX_THREAD) in btsock_thread_wakeup()
335 APPL_TRACE_ERROR("invalid bt thread handle:%d", h); in btsock_thread_wakeup()
338 if(ts[h].cmd_fdw == -1) in btsock_thread_wakeup()
340 APPL_TRACE_ERROR("thread handle:%d, cmd socket is not created", h); in btsock_thread_wakeup()
346 OSI_NO_INTR(ret = send(ts[h].cmd_fdw, &cmd, sizeof(cmd), 0)); in btsock_thread_wakeup()
350 int btsock_thread_exit(int h) in btsock_thread_exit() argument
352 if(h < 0 || h >= MAX_THREAD) in btsock_thread_exit()
354 APPL_TRACE_ERROR("invalid bt thread handle:%d", h); in btsock_thread_exit()
357 if(ts[h].cmd_fdw == -1) in btsock_thread_exit()
365 OSI_NO_INTR(ret = send(ts[h].cmd_fdw, &cmd, sizeof(cmd), 0)); in btsock_thread_exit()
368 pthread_join(ts[h].thread_id, 0); in btsock_thread_exit()
370 free_thread_slot(h); in btsock_thread_exit()
376 static void init_poll(int h) in init_poll() argument
379 ts[h].poll_count = 0; in init_poll()
380 ts[h].thread_id = -1; in init_poll()
381 ts[h].callback = NULL; in init_poll()
382 ts[h].cmd_callback = NULL; in init_poll()
385 ts[h].ps[i].pfd.fd = -1; in init_poll()
386 ts[h].psi[i] = -1; in init_poll()
388 init_cmd_fd(h); in init_poll()
412 static inline void add_poll(int h, int fd, int type, int flags, uint32_t user_id) in add_poll() argument
417 poll_slot_t* ps = ts[h].ps; in add_poll()
423 asrt(ts[h].poll_count < MAX_POLL); in add_poll()
433 asrt(ts[h].poll_count < MAX_POLL); in add_poll()
435 ++ts[h].poll_count; in add_poll()
440 static inline void remove_poll(int h, poll_slot_t* ps, int flags) in remove_poll() argument
445 --ts[h].poll_count; in remove_poll()
457 static int process_cmd_sock(int h) in process_cmd_sock() argument
460 int fd = ts[h].cmd_fdr; in process_cmd_sock()
474 add_poll(h, cmd.fd, cmd.type, cmd.flags, cmd.user_id); in process_cmd_sock()
479 poll_slot_t *poll_slot = &ts[h].ps[i]; in process_cmd_sock()
482 remove_poll(h, poll_slot, poll_slot->flags); in process_cmd_sock()
491 asrt(ts[h].cmd_callback); in process_cmd_sock()
492 if(ts[h].cmd_callback) in process_cmd_sock()
493 ts[h].cmd_callback(fd, cmd.type, cmd.flags, cmd.user_id); in process_cmd_sock()
503 static void process_data_sock(int h, struct pollfd *pfds, int count) in process_data_sock() argument
505 asrt(count <= ts[h].poll_count); in process_data_sock()
507 for( i= 1; i < ts[h].poll_count; i++) in process_data_sock()
511 int ps_i = ts[h].psi[i]; in process_data_sock()
512 asrt(pfds[i].fd == ts[h].ps[ps_i].pfd.fd); in process_data_sock()
513 uint32_t user_id = ts[h].ps[ps_i].user_id; in process_data_sock()
514 int type = ts[h].ps[ps_i].type; in process_data_sock()
529 remove_poll(h, &ts[h].ps[ps_i], ts[h].ps[ps_i].flags); in process_data_sock()
532 … remove_poll(h, &ts[h].ps[ps_i], flags); //remove the monitor flags that already processed in process_data_sock()
534 ts[h].callback(pfds[i].fd, type, flags, user_id); in process_data_sock()
539 static void prepare_poll_fds(int h, struct pollfd* pfds) in prepare_poll_fds() argument
544 asrt(ts[h].poll_count <= MAX_POLL); in prepare_poll_fds()
545 memset(pfds, 0, sizeof(pfds[0])*ts[h].poll_count); in prepare_poll_fds()
546 while(count < ts[h].poll_count) in prepare_poll_fds()
551 ps_i, MAX_POLL, count, ts[h].poll_count); in prepare_poll_fds()
554 if(ts[h].ps[ps_i].pfd.fd >= 0) in prepare_poll_fds()
556 pfds[pfd_i] = ts[h].ps[ps_i].pfd; in prepare_poll_fds()
557 ts[h].psi[pfd_i] = ps_i; in prepare_poll_fds()
568 int h = (intptr_t)arg; in sock_poll_thread() local
571 prepare_poll_fds(h, pfds); in sock_poll_thread()
573 OSI_NO_INTR(ret = poll(pfds, ts[h].poll_count, -1)); in sock_poll_thread()
584 asrt(pfds[0].fd == ts[h].cmd_fdr); in sock_poll_thread()
585 if(!process_cmd_sock(h)) in sock_poll_thread()
587 APPL_TRACE_DEBUG("h:%d, process_cmd_sock return false, exit...", h); in sock_poll_thread()
595 process_data_sock(h, pfds, ret); in sock_poll_thread()
599 ts[h].thread_id = -1; in sock_poll_thread()
600 APPL_TRACE_DEBUG("socket poll thread exiting, h:%d", h); in sock_poll_thread()