Browse Source

Build a linked list of registered drivers

Luke Dashjr 12 years ago
parent
commit
e83fc5b70d
2 changed files with 23 additions and 0 deletions
  1. 11 0
      deviceapi.c
  2. 12 0
      deviceapi.h

+ 11 - 0
deviceapi.c

@@ -31,6 +31,17 @@
 #include "miner.h"
 #include "miner.h"
 #include "util.h"
 #include "util.h"
 
 
+void _bfg_register_driver(const struct device_drv * const drv)
+{
+	static struct driver_registration *initlist;
+	struct driver_registration *ndr = malloc(sizeof(*ndr));
+	*ndr = (struct driver_registration){
+		.drv = drv,
+	};
+	LL_PREPEND(initlist, ndr);
+}
+
+
 bool hashes_done(struct thr_info *thr, int64_t hashes, struct timeval *tvp_hashes, uint32_t *max_nonce)
 bool hashes_done(struct thr_info *thr, int64_t hashes, struct timeval *tvp_hashes, uint32_t *max_nonce)
 {
 {
 	struct cgpu_info *cgpu = thr->cgpu;
 	struct cgpu_info *cgpu = thr->cgpu;

+ 12 - 0
deviceapi.h

@@ -7,8 +7,20 @@
 
 
 #include "miner.h"
 #include "miner.h"
 
 
+struct driver_registration;
+struct driver_registration {
+	const struct device_drv *drv;
+	
+	struct driver_registration *next;
+};
+
+extern void _bfg_register_driver(const struct device_drv *);
 #define BFG_REGISTER_DRIVER(drv)                \
 #define BFG_REGISTER_DRIVER(drv)                \
 	struct device_drv drv;                      \
 	struct device_drv drv;                      \
+	__attribute__((constructor))                \
+	static void __bfg_register_drv_ ## drv() {  \
+		_bfg_register_driver(&drv);             \
+	}                                           \
 // END BFG_REGISTER_DRIVER
 // END BFG_REGISTER_DRIVER
 
 
 extern void request_work(struct thr_info *);
 extern void request_work(struct thr_info *);