1/* 2 * Copyright 2015, Hamish Morrison, hamishm53@gmail.com. 3 * All rights reserved. Distributed under the terms of the MIT License. 4 */ 5#ifndef _KERNEL_SELECT_OPS_H 6#define _KERNEL_SELECT_OPS_H 7 8 9struct select_ops { 10 status_t (*select)(int32 object, struct select_info* info, bool kernel); 11 status_t (*deselect)(int32 object, struct select_info* info, bool kernel); 12}; 13 14static const select_ops kSelectOps[] = { 15 // B_OBJECT_TYPE_FD 16 { 17 select_fd, 18 deselect_fd 19 }, 20 21 // B_OBJECT_TYPE_SEMAPHORE 22 { 23 select_sem, 24 deselect_sem 25 }, 26 27 // B_OBJECT_TYPE_PORT 28 { 29 select_port, 30 deselect_port 31 }, 32 33 // B_OBJECT_TYPE_THREAD 34 { 35 select_thread, 36 deselect_thread 37 } 38}; 39 40 41static inline status_t 42select_object(uint32 type, int32 object, struct select_info* sync, bool kernel) 43{ 44 if (type >= B_COUNT_OF(kSelectOps)) 45 return B_BAD_VALUE; 46 return kSelectOps[type].select(object, sync, kernel); 47} 48 49 50static inline status_t 51deselect_object(uint32 type, int32 object, struct select_info* sync, bool kernel) 52{ 53 if (type >= B_COUNT_OF(kSelectOps)) 54 return B_BAD_VALUE; 55 return kSelectOps[type].deselect(object, sync, kernel); 56} 57 58 59#endif 60